mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Animated: Reduce Duplication in Animated{Props,Style} (#46384)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46384 Minor refactor to reduce duplicated logic when traversing props and styles in `AnimatedProps` and `AnimatedStyle`, respectively. This refactor also makes a future optimization (in which we want to skip processing certain props) more straightforward to implement. Changelog [Internal] Reviewed By: javache Differential Revision: D62351078 fbshipit-source-id: 63c06462c99ef83f3b511456a3281b940b7a3ac0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
734c1505f4
commit
5dbd9fc159
@@ -30,29 +30,20 @@ function createAnimatedProps(inputProps: {
|
||||
const key = keys[ii];
|
||||
const value = inputProps[key];
|
||||
|
||||
let node;
|
||||
if (key === 'style') {
|
||||
const node = AnimatedStyle.from(value);
|
||||
if (node == null) {
|
||||
props[key] = value;
|
||||
} else {
|
||||
nodeKeys.push(key);
|
||||
nodes.push(node);
|
||||
props[key] = node;
|
||||
}
|
||||
node = AnimatedStyle.from(value);
|
||||
} else if (value instanceof AnimatedNode) {
|
||||
const node = value;
|
||||
node = value;
|
||||
} else {
|
||||
node = AnimatedObject.from(value);
|
||||
}
|
||||
if (node == null) {
|
||||
props[key] = value;
|
||||
} else {
|
||||
nodeKeys.push(key);
|
||||
nodes.push(node);
|
||||
props[key] = node;
|
||||
} else {
|
||||
const node = AnimatedObject.from(value);
|
||||
if (node == null) {
|
||||
props[key] = value;
|
||||
} else {
|
||||
nodeKeys.push(key);
|
||||
nodes.push(node);
|
||||
props[key] = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-23
@@ -32,36 +32,25 @@ function createAnimatedStyle(
|
||||
const key = keys[ii];
|
||||
const value = inputStyle[key];
|
||||
|
||||
let node;
|
||||
if (value != null && key === 'transform') {
|
||||
const node = ReactNativeFeatureFlags.shouldUseAnimatedObjectForTransform()
|
||||
node = ReactNativeFeatureFlags.shouldUseAnimatedObjectForTransform()
|
||||
? AnimatedObject.from(value)
|
||||
: // $FlowFixMe[incompatible-call] - `value` is mixed.
|
||||
AnimatedTransform.from(value);
|
||||
if (node == null) {
|
||||
if (keepUnanimatedValues) {
|
||||
style[key] = value;
|
||||
}
|
||||
} else {
|
||||
nodeKeys.push(key);
|
||||
nodes.push(node);
|
||||
style[key] = node;
|
||||
}
|
||||
} else if (value instanceof AnimatedNode) {
|
||||
const node = value;
|
||||
node = value;
|
||||
} else {
|
||||
node = AnimatedObject.from(value);
|
||||
}
|
||||
if (node == null) {
|
||||
if (keepUnanimatedValues) {
|
||||
style[key] = value;
|
||||
}
|
||||
} else {
|
||||
nodeKeys.push(key);
|
||||
nodes.push(node);
|
||||
style[key] = value;
|
||||
} else {
|
||||
const node = AnimatedObject.from(value);
|
||||
if (node == null) {
|
||||
if (keepUnanimatedValues) {
|
||||
style[key] = value;
|
||||
}
|
||||
} else {
|
||||
nodeKeys.push(key);
|
||||
nodes.push(node);
|
||||
style[key] = node;
|
||||
}
|
||||
style[key] = node;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user