mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-11 11:29:03 +08:00
native decay animation
Summary: Add support for `useNativeDriver: true` to `Animated.decay`. Add example in Native Animated Example UIExplorer app. Reviewed By: ritzau Differential Revision: D3690127 fbshipit-source-id: eaa5e61293ed174191cec72255ea2677dbaa1757
This commit is contained in:
committed by
Facebook Github Bot 5
parent
37ab1c8844
commit
2a7f4be8f8
@@ -17,7 +17,6 @@ import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.uimanager.ReactStylesDiffMap;
|
||||
import com.facebook.react.uimanager.UIImplementation;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -259,6 +258,63 @@ public class NativeAnimatedNodeTraversalTest {
|
||||
verifyNoMoreInteractions(mUIImplementationMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecayAnimation() {
|
||||
createSimpleAnimatedViewWithOpacity(1000, 0d);
|
||||
|
||||
Callback animationCallback = mock(Callback.class);
|
||||
mNativeAnimatedNodesManager.startAnimatingNode(
|
||||
1,
|
||||
1,
|
||||
JavaOnlyMap.of(
|
||||
"type",
|
||||
"decay",
|
||||
"velocity",
|
||||
0.5d,
|
||||
"deceleration",
|
||||
0.998d),
|
||||
animationCallback);
|
||||
|
||||
ArgumentCaptor<ReactStylesDiffMap> stylesCaptor =
|
||||
ArgumentCaptor.forClass(ReactStylesDiffMap.class);
|
||||
|
||||
reset(mUIImplementationMock);
|
||||
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
|
||||
verify(mUIImplementationMock, atMost(1))
|
||||
.synchronouslyUpdateViewOnUIThread(eq(1000), stylesCaptor.capture());
|
||||
double previousValue = stylesCaptor.getValue().getDouble("opacity", Double.NaN);
|
||||
double previousDiff = Double.POSITIVE_INFINITY;
|
||||
/* run 3 secs of animation */
|
||||
for (int i = 0; i < 3 * 60; i++) {
|
||||
reset(mUIImplementationMock);
|
||||
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
|
||||
verify(mUIImplementationMock, atMost(1))
|
||||
.synchronouslyUpdateViewOnUIThread(eq(1000), stylesCaptor.capture());
|
||||
double currentValue = stylesCaptor.getValue().getDouble("opacity", Double.NaN);
|
||||
double currentDiff = currentValue - previousValue;
|
||||
// verify monotonicity
|
||||
// greater *or equal* because the animation stops during these 3 seconds
|
||||
assertThat(currentValue).as("on frame " + i).isGreaterThanOrEqualTo(previousValue);
|
||||
// verify decay
|
||||
if (i > 3) {
|
||||
// i > 3 because that's how long it takes to settle previousDiff
|
||||
if (i % 3 != 0) {
|
||||
// i % 3 != 0 because every 3 frames we go a tiny
|
||||
// bit faster, because frame length is 16.(6)ms
|
||||
assertThat(currentDiff).as("on frame " + i).isLessThanOrEqualTo(previousDiff);
|
||||
} else {
|
||||
assertThat(currentDiff).as("on frame " + i).isGreaterThanOrEqualTo(previousDiff);
|
||||
}
|
||||
}
|
||||
previousValue = currentValue;
|
||||
previousDiff = currentDiff;
|
||||
}
|
||||
// should be done in 3s
|
||||
reset(mUIImplementationMock);
|
||||
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
|
||||
verifyNoMoreInteractions(mUIImplementationMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnimationCallbackFinish() {
|
||||
createSimpleAnimatedViewWithOpacity(1000, 0d);
|
||||
|
||||
Reference in New Issue
Block a user