mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-17 23:04:40 +08:00
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:
committed by
Facebook Github Bot
parent
5eb28dc4f0
commit
f7cbd56d8e
@@ -25,10 +25,10 @@ import com.facebook.react.uimanager.annotations.ReactPropGroup;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
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.fail;
|
||||
@@ -148,7 +148,7 @@ public class ReactPropConstantsTest {
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(
|
||||
reactContext,
|
||||
viewManagers,
|
||||
new UIImplementation(reactContext, viewManagers));
|
||||
new UIImplementationProvider());
|
||||
Map<String, String> constants =
|
||||
(Map) valueAtPath(uiManagerModule.getConstants(), "SomeView", "NativeProps");
|
||||
assertThat(constants).isEqualTo(
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.Map;
|
||||
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
|
||||
import org.fest.assertions.data.MapEntry;
|
||||
import org.junit.Before;
|
||||
@@ -27,6 +28,7 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
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.when;
|
||||
|
||||
@@ -50,12 +52,17 @@ public class UIManagerModuleConstantsTest {
|
||||
private static final Map TWIRL_DIRECT_EVENT_MAP = MapBuilder.of("registrationName", "onTwirl");
|
||||
|
||||
private ReactApplicationContext mReactContext;
|
||||
private UIImplementation mUIImplementation;
|
||||
private UIImplementationProvider mUIImplementationProvider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
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
|
||||
@@ -64,7 +71,7 @@ public class UIManagerModuleConstantsTest {
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(
|
||||
mReactContext,
|
||||
viewManagers,
|
||||
mUIImplementation);
|
||||
mUIImplementationProvider);
|
||||
Map<String, Object> constants = uiManagerModule.getConstants();
|
||||
assertThat(constants)
|
||||
.containsKey(CUSTOM_BUBBLING_EVENT_TYPES)
|
||||
@@ -81,7 +88,7 @@ public class UIManagerModuleConstantsTest {
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(
|
||||
mReactContext,
|
||||
viewManagers,
|
||||
mUIImplementation);
|
||||
mUIImplementationProvider);
|
||||
Map<String, Object> constants = uiManagerModule.getConstants();
|
||||
assertThat((Map) constants.get(CUSTOM_BUBBLING_EVENT_TYPES))
|
||||
.contains(MapEntry.entry("onTwirl", TWIRL_BUBBLING_EVENT_MAP))
|
||||
@@ -97,7 +104,7 @@ public class UIManagerModuleConstantsTest {
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(
|
||||
mReactContext,
|
||||
viewManagers,
|
||||
mUIImplementation);
|
||||
mUIImplementationProvider);
|
||||
Map<String, Object> constants = uiManagerModule.getConstants();
|
||||
assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES))
|
||||
.contains(MapEntry.entry("onTwirl", TWIRL_DIRECT_EVENT_MAP))
|
||||
@@ -114,7 +121,7 @@ public class UIManagerModuleConstantsTest {
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(
|
||||
mReactContext,
|
||||
viewManagers,
|
||||
mUIImplementation);
|
||||
mUIImplementationProvider);
|
||||
Map<String, Object> constants = uiManagerModule.getConstants();
|
||||
assertThat(constants).containsKey("RedPandaPhotoOfTheDayView");
|
||||
assertThat((Map) constants.get("RedPandaPhotoOfTheDayView")).containsKey("Constants");
|
||||
@@ -132,7 +139,7 @@ public class UIManagerModuleConstantsTest {
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(
|
||||
mReactContext,
|
||||
viewManagers,
|
||||
mUIImplementation);
|
||||
mUIImplementationProvider);
|
||||
Map<String, Object> constants = uiManagerModule.getConstants();
|
||||
assertThat((String) valueAtPath(constants, "SomeView", "NativeProps", "fooProp"))
|
||||
.isEqualTo("number");
|
||||
@@ -166,7 +173,7 @@ public class UIManagerModuleConstantsTest {
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(
|
||||
mReactContext,
|
||||
viewManagers,
|
||||
mUIImplementation);
|
||||
mUIImplementationProvider);
|
||||
Map<String, Object> constants = uiManagerModule.getConstants();
|
||||
assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES)).containsKey("onTwirl");
|
||||
|
||||
|
||||
@@ -22,28 +22,28 @@ import android.widget.TextView;
|
||||
import com.facebook.react.ReactRootView;
|
||||
import com.facebook.react.animation.Animation;
|
||||
import com.facebook.react.animation.AnimationPropertyUpdater;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
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.JavaOnlyArray;
|
||||
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.ReactTextShadowNode;
|
||||
import com.facebook.react.views.text.ReactTextViewManager;
|
||||
import com.facebook.react.views.view.ReactViewGroup;
|
||||
import com.facebook.react.views.view.ReactViewManager;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
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.PrepareForTest;
|
||||
import org.powermock.modules.junit4.rule.PowerMockRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
@@ -110,7 +110,6 @@ public class UIManagerModuleTest {
|
||||
UIManagerModule uiManagerModuleMock = mock(UIManagerModule.class);
|
||||
when(mCatalystInstanceMock.getNativeModule(UIManagerModule.class))
|
||||
.thenReturn(uiManagerModuleMock);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -644,7 +643,7 @@ public class UIManagerModuleTest {
|
||||
executePendingChoreographerCallbacks();
|
||||
|
||||
assertThat(rootView.getChildCount()).isEqualTo(2);
|
||||
assertThat(((ViewGroup)rootView.getChildAt(0)).getChildCount()).isEqualTo(2);
|
||||
assertThat(((ViewGroup) rootView.getChildAt(0)).getChildCount()).isEqualTo(2);
|
||||
|
||||
uiManager.removeSubviewsFromContainerWithID(containerTag);
|
||||
|
||||
@@ -652,7 +651,7 @@ public class UIManagerModuleTest {
|
||||
executePendingChoreographerCallbacks();
|
||||
|
||||
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(
|
||||
mReactContext,
|
||||
viewManagers,
|
||||
new UIImplementation(mReactContext, viewManagers));
|
||||
new UIImplementationProvider());
|
||||
uiManagerModule.onHostResume();
|
||||
return uiManagerModule;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.util.List;
|
||||
import android.annotation.TargetApi;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
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.ReactTestHelper;
|
||||
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.ViewManager;
|
||||
import com.facebook.react.uimanager.ViewProps;
|
||||
@@ -121,7 +120,7 @@ public class ReactTextTest {
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView)rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
assertThat(customStyleSpan.getWeight() & Typeface.BOLD).isNotZero();
|
||||
assertThat(customStyleSpan.getStyle() & Typeface.ITALIC).isZero();
|
||||
}
|
||||
@@ -435,7 +434,7 @@ public class ReactTextTest {
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(
|
||||
reactContext,
|
||||
viewManagers,
|
||||
new UIImplementation(reactContext, viewManagers));
|
||||
new UIImplementationProvider());
|
||||
uiManagerModule.onHostResume();
|
||||
return uiManagerModule;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
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.ViewManager;
|
||||
import com.facebook.react.uimanager.ViewProps;
|
||||
@@ -185,7 +186,7 @@ public class TextInputTest {
|
||||
UIManagerModule uiManagerModule = new UIManagerModule(
|
||||
reactContext,
|
||||
viewManagers,
|
||||
new UIImplementation(reactContext, viewManagers));
|
||||
new UIImplementationProvider());
|
||||
uiManagerModule.onHostResume();
|
||||
return uiManagerModule;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user