Skip to content

Commit 1f5d092

Browse files
committed
[fix] Animated works with compiled styles
Animated should now work with compiled and extracted styles. The original styles are passed to components, rather than being flattened into a new object that cannot be used by the style runtime to either lookup the results of StyleSheet.create calls or consume extracted styles. Inline styles that use AnimatedValue are moved into a seperate object that is appended to the original styles. Fix #2387
1 parent e68c327 commit 1f5d092

File tree

1 file changed

+26
-10
lines changed
  • packages/react-native-web/src/vendor/react-native/Animated/nodes

1 file changed

+26
-10
lines changed

packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedStyle.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,32 @@ import StyleSheet from '../../../../exports/StyleSheet';
1919

2020
const flattenStyle = StyleSheet.flatten;
2121

22+
function createAnimatedStyle(inputStyle: any): Object {
23+
const style = flattenStyle(inputStyle);
24+
const animatedStyles = {}
25+
for (const key in style) {
26+
const value = style[key];
27+
if (key === 'transform') {
28+
animatedStyles[key] = new AnimatedTransform(value);
29+
}
30+
else if (value instanceof AnimatedNode) {
31+
animatedStyles[key] = value;
32+
}
33+
else if (value && !Array.isArray(value) && typeof value === 'object') {
34+
animatedStyles[key] = createAnimatedStyle(value);
35+
}
36+
}
37+
return animatedStyles;
38+
}
39+
2240
class AnimatedStyle extends AnimatedWithChildren {
41+
_inputStyle: any;
2342
_style: Object;
2443

2544
constructor(style: any) {
2645
super();
27-
style = flattenStyle(style) || {};
28-
if (style.transform) {
29-
style = {
30-
...style,
31-
transform: new AnimatedTransform(style.transform),
32-
};
33-
}
34-
this._style = style;
46+
this._inputStyle = style;
47+
this._style = createAnimatedStyle(style);
3548
}
3649

3750
// Recursively get values for nested styles (like iOS's shadowOffset)
@@ -55,8 +68,11 @@ class AnimatedStyle extends AnimatedWithChildren {
5568
return updatedStyle;
5669
}
5770

58-
__getValue(): Object {
59-
return this._walkStyleAndGetValues(this._style);
71+
__getValue(): Array<Object> {
72+
return [
73+
this._inputStyle,
74+
this._walkStyleAndGetValues(this._style)
75+
];
6076
}
6177

6278
// Recursively get animated values for nested styles (like iOS's shadowOffset)

0 commit comments

Comments
 (0)