mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-16 12:12:20 +08:00
Native Animated - Restore default values when removing props on Android
Summary: Same as #11819 but for Android. I didn't notice the bug initially in my app because I was using different animations on Android which did not trigger this issue. **Test plan** Created a simple repro example and tested that this fixes it. https://gist.github.com/janicduplessis/0f3eb362dae63fedf99a0d3ee041796a Closes https://github.com/facebook/react-native/pull/12842 Differential Revision: D5556439 Pulled By: hramos fbshipit-source-id: d13f4ad258d03cca46c793751ebc49d942b99152
This commit is contained in:
committed by
Facebook Github Bot
parent
b4f91be647
commit
ac43548063
@@ -992,4 +992,51 @@ public class NativeAnimatedNodeTraversalTest {
|
||||
verify(mUIImplementationMock).synchronouslyUpdateViewOnUIThread(eq(viewTag), stylesCaptor.capture());
|
||||
assertThat(stylesCaptor.getValue().getDouble("opacity", Double.NaN)).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestoreDefaultProps() {
|
||||
int viewTag = 1000;
|
||||
int propsNodeTag = 3;
|
||||
mNativeAnimatedNodesManager.createAnimatedNode(
|
||||
1,
|
||||
JavaOnlyMap.of("type", "value", "value", 1d, "offset", 0d));
|
||||
mNativeAnimatedNodesManager.createAnimatedNode(
|
||||
2,
|
||||
JavaOnlyMap.of("type", "style", "style", JavaOnlyMap.of("opacity", 1)));
|
||||
mNativeAnimatedNodesManager.createAnimatedNode(
|
||||
propsNodeTag,
|
||||
JavaOnlyMap.of("type", "props", "props", JavaOnlyMap.of("style", 2)));
|
||||
mNativeAnimatedNodesManager.connectAnimatedNodes(1, 2);
|
||||
mNativeAnimatedNodesManager.connectAnimatedNodes(2, propsNodeTag);
|
||||
mNativeAnimatedNodesManager.connectAnimatedNodeToView(propsNodeTag, viewTag);
|
||||
|
||||
JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.5d, 1d);
|
||||
Callback animationCallback = mock(Callback.class);
|
||||
mNativeAnimatedNodesManager.startAnimatingNode(
|
||||
1,
|
||||
1,
|
||||
JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 0d),
|
||||
animationCallback);
|
||||
|
||||
ArgumentCaptor<ReactStylesDiffMap> stylesCaptor =
|
||||
ArgumentCaptor.forClass(ReactStylesDiffMap.class);
|
||||
|
||||
reset(mUIImplementationMock);
|
||||
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
|
||||
verify(mUIImplementationMock).synchronouslyUpdateViewOnUIThread(eq(viewTag), stylesCaptor.capture());
|
||||
assertThat(stylesCaptor.getValue().getDouble("opacity", Double.NaN)).isEqualTo(1);
|
||||
|
||||
for (int i = 0; i < frames.size(); i++) {
|
||||
reset(mUIImplementationMock);
|
||||
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
|
||||
}
|
||||
|
||||
verify(mUIImplementationMock).synchronouslyUpdateViewOnUIThread(eq(viewTag), stylesCaptor.capture());
|
||||
assertThat(stylesCaptor.getValue().getDouble("opacity", Double.NaN)).isEqualTo(0);
|
||||
|
||||
reset(mUIImplementationMock);
|
||||
mNativeAnimatedNodesManager.restoreDefaultValues(propsNodeTag, viewTag);
|
||||
verify(mUIImplementationMock).synchronouslyUpdateViewOnUIThread(eq(viewTag), stylesCaptor.capture());
|
||||
assertThat(stylesCaptor.getValue().isNull("opacity"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user