Skip to content

Commit

Permalink
Set collapse property before starting an animation that uses the nati…
Browse files Browse the repository at this point in the history
…ve 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.
  • Loading branch information
cabelitos committed Jun 22, 2019
1 parent 3915c0f commit da903c1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Libraries/Animated/src/nodes/AnimatedProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class AnimatedProps extends AnimatedNode {
_props: Object;
_animatedView: any;
_callback: () => void;
_alreadySetCollapsable: boolean;

constructor(props: Object, callback: () => void) {
super();
Expand All @@ -32,6 +33,7 @@ class AnimatedProps extends AnimatedNode {
}
this._props = props;
this._callback = callback;
this._alreadySetCollapsable = false;
this.__attach();
}

Expand Down Expand Up @@ -125,6 +127,17 @@ class AnimatedProps extends AnimatedNode {
nativeViewTag != null,
'Unable to locate attached view in the native tree',
);
/*
Set the collapsable to false making NativeViewHierarchyManager to not optimize away the
animated view.
*/
if (
!this._alreadySetCollapsable &&
typeof this._animatedView.setNativeProps === 'function'
) {
this._alreadySetCollapsable = true;
this._animatedView.setNativeProps({collapsable: false});
}
NativeAnimatedHelper.API.connectAnimatedNodeToView(
this.__getNativeTag(),
nativeViewTag,
Expand Down

0 comments on commit da903c1

Please sign in to comment.