Skip to content

Commit 7550599

Browse files
kmagierakelset
authored andcommitted
Fix native animated style and transform node to call __makeNative once all the children are converted to native nodes (#20658)
Summary: This PR fixes an issue I have found while playing with native animated driver nodes. I discovered the bug when using animated views that have both animated props and styles. See this snack to see an example: https://snack.expo.io/B17SFXy8Q In that example we set `opacity` and `style` props which both contain animated props. This is not an usual way to do that, as normally you would place `opacity` inside the `styles` in which case the bug won't surface. But this is only done for demo purposes and in practice the problem will occur if you have a custom native view that exposes props that are not styles and can be animated. In the above example you get this error: > Invariant Violation: Attempt to get native tag from node not marked as "native" When `opacity` is moved into `styles` container the problem no longer occurs. The problem turned out to be related to the initialization code responsible for creating native animated nodes. In all subclasses of `AnimatedWithChildren` (like `AimatedAddition`) we only call `super.__makeNative` after we call `__makeNative` method on the child nodes. This order was reversed in `AnimatedStyle` and `AnimatedTransform`. As a result when `super.__makeNative` is called in `AnimatedStyle`, we try to call `__getNativeTag` on children nodes not yet marked as native which results in the error described above ("Attempt to get native tag..."). We should instead follow the order of calling `super.__makeNative` that is used in the remaining subclasses of `AnimatedWithChildren`. Such that all the children nodes are first converted to native prior to calling superclass method. This is what this PR is changing. Pull Request resolved: #20658 Differential Revision: D9297191 Pulled By: hramos fbshipit-source-id: f5e394fb259ff514c7c1433edcb5fc89203f55e2
1 parent 692493b commit 7550599

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Libraries/Animated/src/nodes/AnimatedStyle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ class AnimatedStyle extends AnimatedWithChildren {
9595
}
9696

9797
__makeNative() {
98-
super.__makeNative();
9998
for (const key in this._style) {
10099
const value = this._style[key];
101100
if (value instanceof AnimatedNode) {
102101
value.__makeNative();
103102
}
104103
}
104+
super.__makeNative();
105105
}
106106

107107
__getNativeConfig(): Object {

Libraries/Animated/src/nodes/AnimatedTransform.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class AnimatedTransform extends AnimatedWithChildren {
2222
}
2323

2424
__makeNative() {
25-
super.__makeNative();
2625
this._transforms.forEach(transform => {
2726
for (const key in transform) {
2827
const value = transform[key];
@@ -31,6 +30,7 @@ class AnimatedTransform extends AnimatedWithChildren {
3130
}
3231
}
3332
});
33+
super.__makeNative();
3434
}
3535

3636
__getValue(): $ReadOnlyArray<Object> {

0 commit comments

Comments
 (0)