pass EventDispatcher to UIImplementation constructor

Summary: This way `UIImplementation` can hold on to it and use it outside of calls from the `UIManagerModule`.

Reviewed By: lexs

Differential Revision: D3899774

fbshipit-source-id: 01e4956c4540bcdf30774a3f40a625e934714ee9
This commit is contained in:
Felix Oghina 2016-10-04 12:21:03 -07:00 committed by Facebook Github Bot
parent 5eb28dc4f0
commit f7cbd56d8e
15 changed files with 82 additions and 65 deletions

View File

@ -16,24 +16,24 @@ import java.util.Set;
import com.facebook.react.bridge.BaseJavaModule; import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.bridge.CatalystInstance; import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.InvalidIteratorException; import com.facebook.react.bridge.InvalidIteratorException;
import com.facebook.react.bridge.JavaScriptModule; import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NoSuchKeyException; import com.facebook.react.bridge.NoSuchKeyException;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.bridge.ReadableNativeMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator; import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.UnexpectedNativeTypeException; import com.facebook.react.bridge.ReadableNativeMap;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.bridge.UiThreadUtil; import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.UnexpectedNativeTypeException;
import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.modules.systeminfo.AndroidInfoModule; import com.facebook.react.modules.systeminfo.AndroidInfoModule;
import com.facebook.react.testing.FakeWebSocketModule; import com.facebook.react.testing.FakeWebSocketModule;
import com.facebook.react.testing.ReactIntegrationTestCase; import com.facebook.react.testing.ReactIntegrationTestCase;
import com.facebook.react.testing.ReactTestHelper; import com.facebook.react.testing.ReactTestHelper;
import com.facebook.react.uimanager.UIImplementation; import com.facebook.react.uimanager.UIImplementationProvider;
import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.views.view.ReactViewManager; import com.facebook.react.views.view.ReactViewManager;
@ -79,7 +79,7 @@ public class CatalystNativeJSToJavaParametersTestCase extends ReactIntegrationTe
final UIManagerModule mUIManager = new UIManagerModule( final UIManagerModule mUIManager = new UIManagerModule(
getContext(), getContext(),
viewManagers, viewManagers,
new UIImplementation(getContext(), viewManagers)); new UIImplementationProvider());
UiThreadUtil.runOnUiThread( UiThreadUtil.runOnUiThread(
new Runnable() { new Runnable() {
@Override @Override

View File

@ -14,16 +14,16 @@ import java.util.List;
import com.facebook.react.bridge.CatalystInstance; import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.JavaScriptModule; import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.ObjectAlreadyConsumedException; import com.facebook.react.bridge.ObjectAlreadyConsumedException;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeArray; import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.testing.AssertModule; import com.facebook.react.testing.AssertModule;
import com.facebook.react.testing.FakeWebSocketModule; import com.facebook.react.testing.FakeWebSocketModule;
import com.facebook.react.testing.ReactIntegrationTestCase; import com.facebook.react.testing.ReactIntegrationTestCase;
import com.facebook.react.testing.ReactTestHelper; import com.facebook.react.testing.ReactTestHelper;
import com.facebook.react.uimanager.UIImplementation; import com.facebook.react.uimanager.UIImplementationProvider;
import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.views.view.ReactViewManager; import com.facebook.react.views.view.ReactViewManager;
@ -62,7 +62,7 @@ public class CatalystNativeJavaToJSArgumentsTestCase extends ReactIntegrationTes
final UIManagerModule mUIManager = new UIManagerModule( final UIManagerModule mUIManager = new UIManagerModule(
getContext(), getContext(),
viewManagers, viewManagers,
new UIImplementation(getContext(), viewManagers)); new UIImplementationProvider());
UiThreadUtil.runOnUiThread( UiThreadUtil.runOnUiThread(
new Runnable() { new Runnable() {
@Override @Override

View File

@ -24,6 +24,7 @@ import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.modules.systeminfo.AndroidInfoModule; import com.facebook.react.modules.systeminfo.AndroidInfoModule;
import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.UIImplementation; import com.facebook.react.uimanager.UIImplementation;
import com.facebook.react.uimanager.UIImplementationProvider;
import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.views.text.ReactRawTextManager; import com.facebook.react.views.text.ReactRawTextManager;
@ -81,7 +82,7 @@ public class CatalystUIManagerTestCase extends ReactIntegrationTestCase {
uiManager = new UIManagerModule( uiManager = new UIManagerModule(
getContext(), getContext(),
viewManagers, viewManagers,
new UIImplementation(getContext(), viewManagers)); new UIImplementationProvider());
UiThreadUtil.runOnUiThread(new Runnable() { UiThreadUtil.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -18,7 +18,7 @@ import com.facebook.react.testing.StringRecordingModule;
import com.facebook.react.bridge.CatalystInstance; import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.JavaScriptModule; import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.UiThreadUtil; import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.uimanager.UIImplementation; import com.facebook.react.uimanager.UIImplementationProvider;
import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.views.view.ReactViewManager; import com.facebook.react.views.view.ReactViewManager;
@ -46,7 +46,7 @@ public class JSLocaleTest extends ReactIntegrationTestCase {
final UIManagerModule mUIManager = new UIManagerModule( final UIManagerModule mUIManager = new UIManagerModule(
getContext(), getContext(),
viewManagers, viewManagers,
new UIImplementation(getContext(), viewManagers)); new UIImplementationProvider());
UiThreadUtil.runOnUiThread( UiThreadUtil.runOnUiThread(
new Runnable() { new Runnable() {
@Override @Override

View File

@ -26,6 +26,7 @@ import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.UiThreadUtil; import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.modules.systeminfo.AndroidInfoModule; import com.facebook.react.modules.systeminfo.AndroidInfoModule;
import com.facebook.react.uimanager.UIImplementation; import com.facebook.react.uimanager.UIImplementation;
import com.facebook.react.uimanager.UIImplementationProvider;
import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.views.progressbar.ReactProgressBarViewManager; import com.facebook.react.views.progressbar.ReactProgressBarViewManager;
@ -71,7 +72,7 @@ public class ProgressBarTestCase extends ReactIntegrationTestCase {
mUIManager = new UIManagerModule( mUIManager = new UIManagerModule(
getContext(), getContext(),
viewManagers, viewManagers,
new UIImplementation(getContext(), viewManagers)); new UIImplementationProvider());
UiThreadUtil.runOnUiThread( UiThreadUtil.runOnUiThread(
new Runnable() { new Runnable() {
@Override @Override

View File

@ -22,6 +22,7 @@ import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.modules.systeminfo.AndroidInfoModule; import com.facebook.react.modules.systeminfo.AndroidInfoModule;
import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.UIImplementation; import com.facebook.react.uimanager.UIImplementation;
import com.facebook.react.uimanager.UIImplementationProvider;
import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.views.view.ReactViewGroup; import com.facebook.react.views.view.ReactViewGroup;
@ -52,7 +53,7 @@ public class ViewRenderingTestCase extends ReactIntegrationTestCase {
final UIManagerModule uiManager = new UIManagerModule( final UIManagerModule uiManager = new UIManagerModule(
getContext(), getContext(),
viewManagers, viewManagers,
new UIImplementation(getContext(), viewManagers)); new UIImplementationProvider());
UiThreadUtil.runOnUiThread( UiThreadUtil.runOnUiThread(
new Runnable() { new Runnable() {
@Override @Override

View File

@ -202,9 +202,7 @@ import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_M
return new UIManagerModule( return new UIManagerModule(
reactContext, reactContext,
viewManagersList, viewManagersList,
mUIImplementationProvider.createUIImplementation( mUIImplementationProvider);
reactContext,
viewManagersList));
} finally { } finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END); ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END);

View File

@ -45,31 +45,41 @@ public class UIImplementation {
private final NativeViewHierarchyOptimizer mNativeViewHierarchyOptimizer; private final NativeViewHierarchyOptimizer mNativeViewHierarchyOptimizer;
private final int[] mMeasureBuffer = new int[4]; private final int[] mMeasureBuffer = new int[4];
private final ReactApplicationContext mReactContext; private final ReactApplicationContext mReactContext;
protected final EventDispatcher mEventDispatcher;
private double mLayoutCount = 0.0; private double mLayoutCount = 0.0;
private double mLayoutTimer = 0.0; private double mLayoutTimer = 0.0;
public UIImplementation(ReactApplicationContext reactContext, List<ViewManager> viewManagers) { public UIImplementation(
this(reactContext, new ViewManagerRegistry(viewManagers)); ReactApplicationContext reactContext,
List<ViewManager> viewManagers,
EventDispatcher eventDispatcher) {
this(reactContext, new ViewManagerRegistry(viewManagers), eventDispatcher);
} }
private UIImplementation(ReactApplicationContext reactContext, ViewManagerRegistry viewManagers) { private UIImplementation(
ReactApplicationContext reactContext,
ViewManagerRegistry viewManagers,
EventDispatcher eventDispatcher) {
this( this(
reactContext, reactContext,
viewManagers, viewManagers,
new UIViewOperationQueue(reactContext, new NativeViewHierarchyManager(viewManagers))); new UIViewOperationQueue(reactContext, new NativeViewHierarchyManager(viewManagers)),
eventDispatcher);
} }
protected UIImplementation( protected UIImplementation(
ReactApplicationContext reactContext, ReactApplicationContext reactContext,
ViewManagerRegistry viewManagers, ViewManagerRegistry viewManagers,
UIViewOperationQueue operationsQueue) { UIViewOperationQueue operationsQueue,
EventDispatcher eventDispatcher) {
mReactContext = reactContext; mReactContext = reactContext;
mViewManagers = viewManagers; mViewManagers = viewManagers;
mOperationsQueue = operationsQueue; mOperationsQueue = operationsQueue;
mNativeViewHierarchyOptimizer = new NativeViewHierarchyOptimizer( mNativeViewHierarchyOptimizer = new NativeViewHierarchyOptimizer(
mOperationsQueue, mOperationsQueue,
mShadowNodeRegistry); mShadowNodeRegistry);
mEventDispatcher = eventDispatcher;
} }
protected ReactShadowNode createRootShadowNode() { protected ReactShadowNode createRootShadowNode() {
@ -136,8 +146,7 @@ public class UIImplementation {
public void updateNodeSize( public void updateNodeSize(
int nodeViewTag, int nodeViewTag,
int newWidth, int newWidth,
int newHeight, int newHeight) {
EventDispatcher eventDispatcher) {
ReactShadowNode cssNode = mShadowNodeRegistry.getNode(nodeViewTag); ReactShadowNode cssNode = mShadowNodeRegistry.getNode(nodeViewTag);
cssNode.setStyleWidth(newWidth); cssNode.setStyleWidth(newWidth);
cssNode.setStyleHeight(newHeight); cssNode.setStyleHeight(newHeight);
@ -146,7 +155,7 @@ public class UIImplementation {
// the batch. As all batches are executed as a single runnable on the event queue this should // the batch. As all batches are executed as a single runnable on the event queue this should
// always be empty, but that calling architecture is an implementation detail. // always be empty, but that calling architecture is an implementation detail.
if (mOperationsQueue.isEmpty()) { if (mOperationsQueue.isEmpty()) {
dispatchViewUpdates(eventDispatcher, -1); // -1 = no associated batch id dispatchViewUpdates(-1); // -1 = no associated batch id
} }
} }
@ -515,20 +524,20 @@ public class UIImplementation {
/** /**
* Invoked at the end of the transaction to commit any updates to the node hierarchy. * Invoked at the end of the transaction to commit any updates to the node hierarchy.
*/ */
public void dispatchViewUpdates(EventDispatcher eventDispatcher, int batchId) { public void dispatchViewUpdates(int batchId) {
updateViewHierarchy(eventDispatcher); updateViewHierarchy();
mNativeViewHierarchyOptimizer.onBatchComplete(); mNativeViewHierarchyOptimizer.onBatchComplete();
mOperationsQueue.dispatchViewUpdates(batchId); mOperationsQueue.dispatchViewUpdates(batchId);
} }
protected void updateViewHierarchy(EventDispatcher eventDispatcher) { protected void updateViewHierarchy() {
for (int i = 0; i < mShadowNodeRegistry.getRootNodeCount(); i++) { for (int i = 0; i < mShadowNodeRegistry.getRootNodeCount(); i++) {
int tag = mShadowNodeRegistry.getRootTag(i); int tag = mShadowNodeRegistry.getRootTag(i);
ReactShadowNode cssRoot = mShadowNodeRegistry.getNode(tag); ReactShadowNode cssRoot = mShadowNodeRegistry.getNode(tag);
notifyOnBeforeLayoutRecursive(cssRoot); notifyOnBeforeLayoutRecursive(cssRoot);
calculateRootLayout(cssRoot); calculateRootLayout(cssRoot);
applyUpdatesRecursive(cssRoot, 0f, 0f, eventDispatcher); applyUpdatesRecursive(cssRoot, 0f, 0f);
} }
} }
@ -764,8 +773,7 @@ public class UIImplementation {
protected void applyUpdatesRecursive( protected void applyUpdatesRecursive(
ReactShadowNode cssNode, ReactShadowNode cssNode,
float absoluteX, float absoluteX,
float absoluteY, float absoluteY) {
EventDispatcher eventDispatcher) {
if (!cssNode.hasUpdates()) { if (!cssNode.hasUpdates()) {
return; return;
} }
@ -775,8 +783,7 @@ public class UIImplementation {
applyUpdatesRecursive( applyUpdatesRecursive(
cssNode.getChildAt(i), cssNode.getChildAt(i),
absoluteX + cssNode.getLayoutX(), absoluteX + cssNode.getLayoutX(),
absoluteY + cssNode.getLayoutY(), absoluteY + cssNode.getLayoutY());
eventDispatcher);
} }
} }
@ -790,7 +797,7 @@ public class UIImplementation {
// notify JS about layout event if requested // notify JS about layout event if requested
if (cssNode.shouldNotifyOnLayout()) { if (cssNode.shouldNotifyOnLayout()) {
eventDispatcher.dispatchEvent( mEventDispatcher.dispatchEvent(
OnLayoutEvent.obtain( OnLayoutEvent.obtain(
tag, tag,
cssNode.getScreenX(), cssNode.getScreenX(),

View File

@ -11,6 +11,7 @@ package com.facebook.react.uimanager;
import java.util.List; import java.util.List;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.events.EventDispatcher;
/** /**
* Provides UIImplementation to use in {@link UIManagerModule}. * Provides UIImplementation to use in {@link UIManagerModule}.
@ -18,7 +19,8 @@ import com.facebook.react.bridge.ReactApplicationContext;
public class UIImplementationProvider { public class UIImplementationProvider {
public UIImplementation createUIImplementation( public UIImplementation createUIImplementation(
ReactApplicationContext reactContext, ReactApplicationContext reactContext,
List<ViewManager> viewManagers) { List<ViewManager> viewManagers,
return new UIImplementation(reactContext, viewManagers); EventDispatcher eventDispatcher) {
return new UIImplementation(reactContext, viewManagers, eventDispatcher);
} }
} }

View File

@ -85,12 +85,13 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
public UIManagerModule( public UIManagerModule(
ReactApplicationContext reactContext, ReactApplicationContext reactContext,
List<ViewManager> viewManagerList, List<ViewManager> viewManagerList,
UIImplementation uiImplementation) { UIImplementationProvider uiImplementationProvider) {
super(reactContext); super(reactContext);
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext); DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
mEventDispatcher = new EventDispatcher(reactContext); mEventDispatcher = new EventDispatcher(reactContext);
mModuleConstants = createConstants(viewManagerList); mModuleConstants = createConstants(viewManagerList);
mUIImplementation = uiImplementation; mUIImplementation = uiImplementationProvider
.createUIImplementation(reactContext, viewManagerList, mEventDispatcher);
reactContext.addLifecycleEventListener(this); reactContext.addLifecycleEventListener(this);
} }
@ -209,7 +210,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
public void updateNodeSize(int nodeViewTag, int newWidth, int newHeight) { public void updateNodeSize(int nodeViewTag, int newWidth, int newHeight) {
getReactApplicationContext().assertOnNativeModulesQueueThread(); getReactApplicationContext().assertOnNativeModulesQueueThread();
mUIImplementation.updateNodeSize(nodeViewTag, newWidth, newHeight, mEventDispatcher); mUIImplementation.updateNodeSize(nodeViewTag, newWidth, newHeight);
} }
@ReactMethod @ReactMethod
@ -496,7 +497,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
.arg("BatchId", batchId) .arg("BatchId", batchId)
.flush(); .flush();
try { try {
mUIImplementation.dispatchViewUpdates(mEventDispatcher, batchId); mUIImplementation.dispatchViewUpdates(batchId);
} finally { } finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
} }

View File

@ -25,10 +25,10 @@ import com.facebook.react.uimanager.annotations.ReactPropGroup;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.rule.PowerMockRule; import org.powermock.modules.junit4.rule.PowerMockRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import static org.fest.assertions.api.Assertions.assertThat; import static org.fest.assertions.api.Assertions.assertThat;
import static org.fest.assertions.api.Assertions.fail; import static org.fest.assertions.api.Assertions.fail;
@ -148,7 +148,7 @@ public class ReactPropConstantsTest {
UIManagerModule uiManagerModule = new UIManagerModule( UIManagerModule uiManagerModule = new UIManagerModule(
reactContext, reactContext,
viewManagers, viewManagers,
new UIImplementation(reactContext, viewManagers)); new UIImplementationProvider());
Map<String, String> constants = Map<String, String> constants =
(Map) valueAtPath(uiManagerModule.getConstants(), "SomeView", "NativeProps"); (Map) valueAtPath(uiManagerModule.getConstants(), "SomeView", "NativeProps");
assertThat(constants).isEqualTo( assertThat(constants).isEqualTo(

View File

@ -15,6 +15,7 @@ import java.util.Map;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.common.MapBuilder; import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.events.EventDispatcher;
import org.fest.assertions.data.MapEntry; import org.fest.assertions.data.MapEntry;
import org.junit.Before; import org.junit.Before;
@ -27,6 +28,7 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import static org.fest.assertions.api.Assertions.assertThat; import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -50,12 +52,17 @@ public class UIManagerModuleConstantsTest {
private static final Map TWIRL_DIRECT_EVENT_MAP = MapBuilder.of("registrationName", "onTwirl"); private static final Map TWIRL_DIRECT_EVENT_MAP = MapBuilder.of("registrationName", "onTwirl");
private ReactApplicationContext mReactContext; private ReactApplicationContext mReactContext;
private UIImplementation mUIImplementation; private UIImplementationProvider mUIImplementationProvider;
@Before @Before
public void setUp() { public void setUp() {
mReactContext = new ReactApplicationContext(RuntimeEnvironment.application); mReactContext = new ReactApplicationContext(RuntimeEnvironment.application);
mUIImplementation = mock(UIImplementation.class); mUIImplementationProvider = mock(UIImplementationProvider.class);
when(mUIImplementationProvider.createUIImplementation(
any(ReactApplicationContext.class),
any(List.class),
any(EventDispatcher.class)))
.thenReturn(mock(UIImplementation.class));
} }
@Test @Test
@ -64,7 +71,7 @@ public class UIManagerModuleConstantsTest {
UIManagerModule uiManagerModule = new UIManagerModule( UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext, mReactContext,
viewManagers, viewManagers,
mUIImplementation); mUIImplementationProvider);
Map<String, Object> constants = uiManagerModule.getConstants(); Map<String, Object> constants = uiManagerModule.getConstants();
assertThat(constants) assertThat(constants)
.containsKey(CUSTOM_BUBBLING_EVENT_TYPES) .containsKey(CUSTOM_BUBBLING_EVENT_TYPES)
@ -81,7 +88,7 @@ public class UIManagerModuleConstantsTest {
UIManagerModule uiManagerModule = new UIManagerModule( UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext, mReactContext,
viewManagers, viewManagers,
mUIImplementation); mUIImplementationProvider);
Map<String, Object> constants = uiManagerModule.getConstants(); Map<String, Object> constants = uiManagerModule.getConstants();
assertThat((Map) constants.get(CUSTOM_BUBBLING_EVENT_TYPES)) assertThat((Map) constants.get(CUSTOM_BUBBLING_EVENT_TYPES))
.contains(MapEntry.entry("onTwirl", TWIRL_BUBBLING_EVENT_MAP)) .contains(MapEntry.entry("onTwirl", TWIRL_BUBBLING_EVENT_MAP))
@ -97,7 +104,7 @@ public class UIManagerModuleConstantsTest {
UIManagerModule uiManagerModule = new UIManagerModule( UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext, mReactContext,
viewManagers, viewManagers,
mUIImplementation); mUIImplementationProvider);
Map<String, Object> constants = uiManagerModule.getConstants(); Map<String, Object> constants = uiManagerModule.getConstants();
assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES)) assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES))
.contains(MapEntry.entry("onTwirl", TWIRL_DIRECT_EVENT_MAP)) .contains(MapEntry.entry("onTwirl", TWIRL_DIRECT_EVENT_MAP))
@ -114,7 +121,7 @@ public class UIManagerModuleConstantsTest {
UIManagerModule uiManagerModule = new UIManagerModule( UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext, mReactContext,
viewManagers, viewManagers,
mUIImplementation); mUIImplementationProvider);
Map<String, Object> constants = uiManagerModule.getConstants(); Map<String, Object> constants = uiManagerModule.getConstants();
assertThat(constants).containsKey("RedPandaPhotoOfTheDayView"); assertThat(constants).containsKey("RedPandaPhotoOfTheDayView");
assertThat((Map) constants.get("RedPandaPhotoOfTheDayView")).containsKey("Constants"); assertThat((Map) constants.get("RedPandaPhotoOfTheDayView")).containsKey("Constants");
@ -132,7 +139,7 @@ public class UIManagerModuleConstantsTest {
UIManagerModule uiManagerModule = new UIManagerModule( UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext, mReactContext,
viewManagers, viewManagers,
mUIImplementation); mUIImplementationProvider);
Map<String, Object> constants = uiManagerModule.getConstants(); Map<String, Object> constants = uiManagerModule.getConstants();
assertThat((String) valueAtPath(constants, "SomeView", "NativeProps", "fooProp")) assertThat((String) valueAtPath(constants, "SomeView", "NativeProps", "fooProp"))
.isEqualTo("number"); .isEqualTo("number");
@ -166,7 +173,7 @@ public class UIManagerModuleConstantsTest {
UIManagerModule uiManagerModule = new UIManagerModule( UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext, mReactContext,
viewManagers, viewManagers,
mUIImplementation); mUIImplementationProvider);
Map<String, Object> constants = uiManagerModule.getConstants(); Map<String, Object> constants = uiManagerModule.getConstants();
assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES)).containsKey("onTwirl"); assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES)).containsKey("onTwirl");

View File

@ -22,28 +22,28 @@ import android.widget.TextView;
import com.facebook.react.ReactRootView; import com.facebook.react.ReactRootView;
import com.facebook.react.animation.Animation; import com.facebook.react.animation.Animation;
import com.facebook.react.animation.AnimationPropertyUpdater; import com.facebook.react.animation.AnimationPropertyUpdater;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.CatalystInstance; import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.JavaOnlyArray; import com.facebook.react.bridge.JavaOnlyArray;
import com.facebook.react.bridge.JavaOnlyMap; import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactTestHelper;
import com.facebook.react.views.text.ReactRawTextManager; import com.facebook.react.views.text.ReactRawTextManager;
import com.facebook.react.views.text.ReactTextShadowNode; import com.facebook.react.views.text.ReactTextShadowNode;
import com.facebook.react.views.text.ReactTextViewManager; import com.facebook.react.views.text.ReactTextViewManager;
import com.facebook.react.views.view.ReactViewGroup; import com.facebook.react.views.view.ReactViewGroup;
import com.facebook.react.views.view.ReactViewManager; import com.facebook.react.views.view.ReactViewManager;
import com.facebook.react.bridge.ReactTestHelper;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.runner.RunWith;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito; import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule; import org.powermock.modules.junit4.rule.PowerMockRule;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
@ -110,7 +110,6 @@ public class UIManagerModuleTest {
UIManagerModule uiManagerModuleMock = mock(UIManagerModule.class); UIManagerModule uiManagerModuleMock = mock(UIManagerModule.class);
when(mCatalystInstanceMock.getNativeModule(UIManagerModule.class)) when(mCatalystInstanceMock.getNativeModule(UIManagerModule.class))
.thenReturn(uiManagerModuleMock); .thenReturn(uiManagerModuleMock);
} }
@Test @Test
@ -644,7 +643,7 @@ public class UIManagerModuleTest {
executePendingChoreographerCallbacks(); executePendingChoreographerCallbacks();
assertThat(rootView.getChildCount()).isEqualTo(2); assertThat(rootView.getChildCount()).isEqualTo(2);
assertThat(((ViewGroup)rootView.getChildAt(0)).getChildCount()).isEqualTo(2); assertThat(((ViewGroup) rootView.getChildAt(0)).getChildCount()).isEqualTo(2);
uiManager.removeSubviewsFromContainerWithID(containerTag); uiManager.removeSubviewsFromContainerWithID(containerTag);
@ -652,7 +651,7 @@ public class UIManagerModuleTest {
executePendingChoreographerCallbacks(); executePendingChoreographerCallbacks();
assertThat(rootView.getChildCount()).isEqualTo(2); assertThat(rootView.getChildCount()).isEqualTo(2);
assertThat(((ViewGroup)rootView.getChildAt(0)).getChildCount()).isEqualTo(0); assertThat(((ViewGroup) rootView.getChildAt(0)).getChildCount()).isEqualTo(0);
} }
/** /**
@ -821,7 +820,7 @@ public class UIManagerModuleTest {
UIManagerModule uiManagerModule = new UIManagerModule( UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext, mReactContext,
viewManagers, viewManagers,
new UIImplementation(mReactContext, viewManagers)); new UIImplementationProvider());
uiManagerModule.onHostResume(); uiManagerModule.onHostResume();
return uiManagerModule; return uiManagerModule;
} }

View File

@ -16,7 +16,6 @@ import java.util.List;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.text.Spanned; import android.text.Spanned;
@ -34,7 +33,7 @@ import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactTestHelper; import com.facebook.react.bridge.ReactTestHelper;
import com.facebook.react.uimanager.ReactChoreographer; import com.facebook.react.uimanager.ReactChoreographer;
import com.facebook.react.uimanager.UIImplementation; import com.facebook.react.uimanager.UIImplementationProvider;
import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.ViewProps;
@ -121,7 +120,7 @@ public class ReactTextTest {
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text")); JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
CustomStyleSpan customStyleSpan = CustomStyleSpan customStyleSpan =
getSingleSpan((TextView)rootView.getChildAt(0), CustomStyleSpan.class); getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
assertThat(customStyleSpan.getWeight() & Typeface.BOLD).isNotZero(); assertThat(customStyleSpan.getWeight() & Typeface.BOLD).isNotZero();
assertThat(customStyleSpan.getStyle() & Typeface.ITALIC).isZero(); assertThat(customStyleSpan.getStyle() & Typeface.ITALIC).isZero();
} }
@ -435,7 +434,7 @@ public class ReactTextTest {
UIManagerModule uiManagerModule = new UIManagerModule( UIManagerModule uiManagerModule = new UIManagerModule(
reactContext, reactContext,
viewManagers, viewManagers,
new UIImplementation(reactContext, viewManagers)); new UIImplementationProvider());
uiManagerModule.onHostResume(); uiManagerModule.onHostResume();
return uiManagerModule; return uiManagerModule;
} }

View File

@ -24,6 +24,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactTestHelper; import com.facebook.react.bridge.ReactTestHelper;
import com.facebook.react.uimanager.ReactChoreographer; import com.facebook.react.uimanager.ReactChoreographer;
import com.facebook.react.uimanager.UIImplementation; import com.facebook.react.uimanager.UIImplementation;
import com.facebook.react.uimanager.UIImplementationProvider;
import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.ViewProps;
@ -185,7 +186,7 @@ public class TextInputTest {
UIManagerModule uiManagerModule = new UIManagerModule( UIManagerModule uiManagerModule = new UIManagerModule(
reactContext, reactContext,
viewManagers, viewManagers,
new UIImplementation(reactContext, viewManagers)); new UIImplementationProvider());
uiManagerModule.onHostResume(); uiManagerModule.onHostResume();
return uiManagerModule; return uiManagerModule;
} }