/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.animated;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.JavaOnlyArray;
import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.ReactStylesDiffMap;
import com.facebook.react.uimanager.UIImplementation;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import java.util.Map;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;
import org.robolectric.RobolectricTestRunner;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atMost;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
/**
* Tests the animated nodes graph traversal algorithm from {@link NativeAnimatedNodesManager}.
*/
@PrepareForTest({Arguments.class})
@RunWith(RobolectricTestRunner.class)
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*"})
public class NativeAnimatedNodeTraversalTest {
private static long FRAME_LEN_NANOS = 1000000000L / 60L;
private static long INITIAL_FRAME_TIME_NANOS = 14599233201256L; /* random */
@Rule
public PowerMockRule rule = new PowerMockRule();
private long mFrameTimeNanos;
private UIManagerModule mUIManagerMock;
private UIImplementation mUIImplementationMock;
private EventDispatcher mEventDispatcherMock;
private NativeAnimatedNodesManager mNativeAnimatedNodesManager;
private long nextFrameTime() {
return mFrameTimeNanos += FRAME_LEN_NANOS;
}
@Before
public void setUp() {
PowerMockito.mockStatic(Arguments.class);
PowerMockito.when(Arguments.createArray()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return new JavaOnlyArray();
}
});
PowerMockito.when(Arguments.createMap()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return new JavaOnlyMap();
}
});
mFrameTimeNanos = INITIAL_FRAME_TIME_NANOS;
mUIManagerMock = mock(UIManagerModule.class);
mUIImplementationMock = mock(UIImplementation.class);
mEventDispatcherMock = mock(EventDispatcher.class);
PowerMockito.when(mUIManagerMock.getUIImplementation()).thenAnswer(new Answer<UIImplementation>() {
@Override
public UIImplementation answer(InvocationOnMock invocation) throws Throwable {
return mUIImplementationMock;
}
});
PowerMockito.when(mUIManagerMock.getEventDispatcher()).thenAnswer(new Answer<EventDispatcher>() {
@Override
public EventDispatcher answer(InvocationOnMock invocation) throws Throwable {
return mEventDispatcherMock;
}
});
PowerMockito.when(mUIManagerMock.getConstants()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return MapBuilder.of("customDirectEventTypes", MapBuilder.newHashMap());
}
});
PowerMockito
.when(mUIManagerMock.getDirectEventNamesResolver())
.thenAnswer(new Answer<UIManagerModule.CustomEventNamesResolver>() {
@Override
public UIManagerModule.CustomEventNamesResolver answer(InvocationOnMock invocation) throws Throwable {
return new UIManagerModule.CustomEventNamesResolver() {
@Override
public String resolveCustomEventName(String eventName) {
Map<String, Map> directEventTypes =
(Map<String, Map>) mUIManagerMock.getConstants().get("customDirectEventTypes");
if (directEventTypes != null) {
Map<String, String> customEventType = (Map<String, String>) directEventTypes.get(eventName);
if (customEventType != null) {
return customEventType.get("registrationName");
}
}
return eventName;
}
};
}
});
mNativeAnimatedNodesManager = new NativeAnimatedNodesManager(mUIManagerMock);
}
/**
* Generates a simple animated nodes graph and attaches the props node to a given {@param viewTag}
* Parameter {@param opacity} is used as a initial value for the "opacity" attribute.
*
* Nodes are connected as follows (nodes IDs in parens):
* ValueNode(1) -> StyleNode(2) -> PropNode(3)
*/
private void createSimpleAnimatedViewWithOpacity(int viewTag, double opacity) {
mNativeAnimatedNodesManager.createAnimatedNode(
1,
JavaOnlyMap.of("type", "value", "value", opacity, "offset", 0d));
mNativeAnimatedNodesManager.createAnimatedNode(
2,
JavaOnlyMap.of("type", "style", "style", JavaOnlyMap.of("opacity", 1)));
mNativeAnimatedNodesManager.createAnimatedNode(
3,
JavaOnlyMap.of("type", "props", "props", JavaOnlyMap.of("style", 2)));
mNativeAnimatedNodesManager.connectAnimatedNodes(1, 2);
mNativeAnimatedNodesManager.connectAnimatedNodes(2, 3);
mNativeAnimatedNodesManager.connectAnimatedNodeToView(3, viewTag);
}
@Test
public void testFramesAnimation() {
createSimpleAnimatedViewWithOpacity(1000, 0d);
JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.2d, 0.4d, 0.6d, 0.8d, 1d);
Callback animationCallback = mock(Callback.class);
mNativeAnimatedNodesManager.startAnimatingNode(
1,
1,
JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1d),
animationCallback);
ArgumentCaptor<ReactStylesDiffMap> stylesCaptor =
ArgumentCaptor.forClass(ReactStylesDiffMap.class);
for (int i = 0; i < frames.size(); i++) {
reset(mUIImplementationMock);
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
verify(mUIImplementationMock)
.synchronouslyUpdateViewOnUIThread(eq(1000), stylesCaptor.capture());
assertThat(stylesCaptor.getValue().getDouble("opacity", Double.NaN))
.isEqualTo(frames.getDouble(i));
}
reset(mUIImplementationMock);
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
verifyNoMoreInteractions(mUIImplementationMock);
}
@Test
public void testFramesAnimationLoopsFiveTimes() {
createSimpleAnimatedViewWithOpacity(1000, 0d);
JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.2d, 0.4d, 0.6d, 0.8d, 1d);
Callback animationCallback = mock(Callback.class);
mNativeAnimatedNodesManager.startAnimatingNode(
1,
1,
JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1d, "iterations", 5),
animationCallback);
ArgumentCaptor<ReactStylesDiffMap> stylesCaptor =
ArgumentCaptor.forClass(ReactStylesDiffMap.class);
for (int iteration = 0; iteration < 5; iteration++) {
for (int i = 0; i < frames.size(); i++) {
reset(mUIImplementationMock);
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
verify(mUIImp
没有合适的资源?快使用搜索试试~ 我知道了~
react-native-0.55.0-rc.2.zip
共2000个文件
java:695个
js:515个
h:432个
需积分: 0 0 下载量 191 浏览量
2024-08-29
16:01:08
上传
评论
收藏 9.13MB ZIP 举报
温馨提示
一个使用 React 构建 app 应用程序的框架 A framework for building native applications using React
资源推荐
资源详情
资源评论
收起资源包目录
react-native-0.55.0-rc.2.zip (2000个子文件)
fishhook.c 8KB
Yoga.cpp 152KB
YGJNI.cpp 29KB
JSCExecutor.cpp 27KB
YGNode.cpp 20KB
Exceptions.cpp 11KB
Value.cpp 11KB
JSCTracing.cpp 10KB
JSCPerfLogging.cpp 9KB
CatalystInstanceImpl.cpp 9KB
LocalString.cpp 9KB
JSCHelpers.cpp 9KB
jscexecutor.cpp 9KB
fbjni.cpp 8KB
NativeToJsBridge.cpp 8KB
ReadableNativeMap.cpp 8KB
YGNodePrint.cpp 7KB
MethodInvoker.cpp 7KB
MicroProfiler.cpp 7KB
JavaModuleWrapper.cpp 6KB
OnLoad.cpp 6KB
CxxNativeModule.cpp 6KB
Instance.cpp 6KB
jni_helpers.cpp 6KB
systemJSCWrapper.cpp 6KB
methodcall.cpp 5KB
Environment.cpp 5KB
ModuleRegistry.cpp 5KB
YGEnums.cpp 5KB
ReadableNativeArray.cpp 5KB
ProxyExecutor.cpp 4KB
jsarg_helpers.cpp 4KB
SampleCxxModule.cpp 4KB
YGStyle.cpp 3KB
JSIndexedRAMBundle.cpp 3KB
JSCPerfStats.cpp 3KB
AndroidJSCFactory.cpp 3KB
OnLoad.cpp 3KB
JInspector.cpp 3KB
value.cpp 3KB
lyra.cpp 3KB
glog_init.cpp 3KB
Unicode.cpp 3KB
InspectorInterfaces.cpp 3KB
JniJSModulesUnbundle.cpp 3KB
WritableNativeMap.cpp 3KB
JMessageQueueThread.cpp 3KB
YGLayout.cpp 2KB
ByteBuffer.cpp 2KB
MethodCall.cpp 2KB
log.cpp 2KB
CpuCapabilities.cpp 2KB
JSCNativeModules.cpp 2KB
DebugStringConvertible.cpp 2KB
WritableNativeArray.cpp 2KB
Countable.cpp 2KB
RAMBundleRegistry.cpp 2KB
ReactMarker.cpp 2KB
ModuleRegistryBuilder.cpp 2KB
JSCLegacyTracing.cpp 2KB
JSLoader.cpp 2KB
NativeCommon.cpp 2KB
SamplingProfilerJniMethod.cpp 2KB
FabricUIManager.cpp 2KB
CxxModuleWrapper.cpp 2KB
Utils.cpp 1KB
jsbigstring.cpp 1KB
JSCMemory.cpp 1KB
RecoverableErrorTest.cpp 1KB
WeakReference.cpp 1KB
jsclogging.cpp 1KB
assert.cpp 1KB
JSLogging.cpp 1008B
DebugStringConvertibleItem.cpp 981B
NativeArray.cpp 970B
JSCWrapper.cpp 927B
JSBundleType.cpp 856B
JSPackagerClientResponder.cpp 809B
References.cpp 802B
JSCSamplingProfiler.cpp 780B
ReferenceChecking.cpp 712B
JSBigString.cpp 700B
NativeMap.cpp 692B
onload.cpp 625B
Hybrid.cpp 619B
Platform.cpp 574B
Sealable.cpp 553B
ShadowNode.cpp 492B
OnLoad.cpp 477B
JSCUtils.cpp 387B
OnLoad.cpp 362B
PrivateDataBase.cpp 172B
style.css 1KB
jni.h 51KB
CoreClasses.h 22KB
References.h 20KB
CoreClasses-inl.h 19KB
Meta-inl.h 17KB
References-inl.h 14KB
Yoga.h 14KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
a3737337
- 粉丝: 0
- 资源: 2869
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- bdwptqmxgj11.zip
- onnxruntime-win-x86
- onnxruntime-win-x64-gpu-1.20.1.zip
- vs2019 c++20 语法规范 头文件 <ratio> 的源码阅读与注释,处理分数的存储,加减乘除,以及大小比较等运算
- 首次尝试使用 Win,DirectX C++ 中的形状渲染套件.zip
- 预乘混合模式是一种用途广泛的三合一混合模式 它已经存在很长时间了,但似乎每隔几年就会被重新发现 该项目包括使用预乘 alpha 的描述,示例和工具 .zip
- 项目描述 DirectX 引擎支持版本 9、10、11 库 Microsoft SDK 功能相机视图、照明、加载网格、动画、蒙皮、层次结构界面、动画控制器、网格容器、碰撞系统 .zip
- 项目 wiki 文档中使用的代码教程的源代码库.zip
- 面向对象的通用GUI框架.zip
- 基于Java语言的PlayerBase游戏角色设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功