Skip to content

Commit da903c1

Browse files
committed
Set collapse property before starting an animation that uses the native driver
Depending on the style props of an Animated.View it may be optimised away by the NativeViewHierarchyOptimizer, which will make the animation to fail, because the native view is virtual (it does not exists in the native view hierarchy). Although the createAnimatedComponent already sets the collapsable property based on the this._propsAnimated.__isNative flag, it won't work on all cases, since the __isNative flag is only set when one starts the animation. Which won't cause a re-render to occuor, thus not setting the collapsable property to false. In order to prevent this issue the AnimatedProps object will directly set the collapsable property to false before starting an animation.
1 parent 3915c0f commit da903c1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Libraries/Animated/src/nodes/AnimatedProps.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class AnimatedProps extends AnimatedNode {
2121
_props: Object;
2222
_animatedView: any;
2323
_callback: () => void;
24+
_alreadySetCollapsable: boolean;
2425

2526
constructor(props: Object, callback: () => void) {
2627
super();
@@ -32,6 +33,7 @@ class AnimatedProps extends AnimatedNode {
3233
}
3334
this._props = props;
3435
this._callback = callback;
36+
this._alreadySetCollapsable = false;
3537
this.__attach();
3638
}
3739

@@ -125,6 +127,17 @@ class AnimatedProps extends AnimatedNode {
125127
nativeViewTag != null,
126128
'Unable to locate attached view in the native tree',
127129
);
130+
/*
131+
Set the collapsable to false making NativeViewHierarchyManager to not optimize away the
132+
animated view.
133+
*/
134+
if (
135+
!this._alreadySetCollapsable &&
136+
typeof this._animatedView.setNativeProps === 'function'
137+
) {
138+
this._alreadySetCollapsable = true;
139+
this._animatedView.setNativeProps({collapsable: false});
140+
}
128141
NativeAnimatedHelper.API.connectAnimatedNodeToView(
129142
this.__getNativeTag(),
130143
nativeViewTag,

0 commit comments

Comments
 (0)