Initialize Event Emitter as part of UIManagerModule

Reviewed By: achen1

Differential Revision: D8216184

fbshipit-source-id: 3b188804e2dad2b112f566da49a939eb4338713d
This commit is contained in:
David Vacca 2018-05-30 21:49:26 -07:00 committed by Facebook Github Bot
parent 0f10e03dd8
commit 6e359c4589
22 changed files with 43 additions and 50 deletions

View File

@ -1078,8 +1078,6 @@ public class ReactInstanceManager {
ReactMarker.logMarker(CREATE_REACT_CONTEXT_START, jsExecutor.getName());
final ReactApplicationContext reactContext = new ReactApplicationContext(mApplicationContext);
reactContext.setEventDispatcher(new EventDispatcher(reactContext));
NativeModuleCallExceptionHandler exceptionHandler = mNativeModuleCallExceptionHandler != null
? mNativeModuleCallExceptionHandler
: mDevSupportManager;

View File

@ -194,7 +194,7 @@ public class ReactRootView extends SizeMonitoringFrameLayout
return;
}
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
EventDispatcher eventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
mJSTouchDispatcher.onChildStartedNativeGesture(androidEvent, eventDispatcher);
}
@ -280,7 +280,7 @@ public class ReactRootView extends SizeMonitoringFrameLayout
return;
}
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
EventDispatcher eventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher);
}

View File

@ -39,7 +39,6 @@ public class ReactContext extends ContextWrapper {
private LifecycleState mLifecycleState = LifecycleState.BEFORE_CREATE;
private @Nullable EventDispatcher mEventDispatcher;
private @Nullable CatalystInstance mCatalystInstance;
private @Nullable LayoutInflater mInflater;
private @Nullable MessageQueueThread mUiMessageQueueThread;
@ -351,11 +350,4 @@ public class ReactContext extends ContextWrapper {
return mCatalystInstance.getJavaScriptContextHolder();
}
public <T extends EventDispatcher> T getEventDispatcher() {
return (T) mEventDispatcher;
}
public void setEventDispatcher(EventDispatcher eventDispatcher) {
mEventDispatcher = eventDispatcher;
}
}

View File

@ -31,6 +31,7 @@ import com.facebook.react.uimanager.PointerEvents;
import com.facebook.react.uimanager.ReactClippingViewGroup;
import com.facebook.react.uimanager.ReactCompoundViewGroup;
import com.facebook.react.uimanager.ReactPointerEventsView;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.views.image.ImageLoadEvent;
import java.lang.ref.WeakReference;
@ -126,7 +127,7 @@ import javax.annotation.Nullable;
}
ReactContext reactContext = ((ReactContext) view.getContext());
reactContext.<EventDispatcher>getEventDispatcher().dispatchEvent(
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
new ImageLoadEvent(reactTag, imageLoadEvent));
}
}

View File

@ -7,7 +7,6 @@
package com.facebook.react.uimanager;
import com.facebook.react.bridge.EventDispatcher;
import javax.annotation.Nullable;
import android.app.Activity;
@ -17,8 +16,6 @@ import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.LifecycleEventListener;
//
/**
* Wraps {@link ReactContext} with the base {@link Context} passed into the constructor.
* It provides also a way to start activities using the viewContext to which RN native views belong.
@ -56,9 +53,4 @@ public class ThemedReactContext extends ReactContext {
public @Nullable Activity getCurrentActivity() {
return mReactApplicationContext.getCurrentActivity();
}
@Override
public <T extends EventDispatcher> T getEventDispatcher() {
return mReactApplicationContext.getEventDispatcher();
}
}

View File

@ -130,7 +130,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
int minTimeLeftInFrameForNonBatchedOperationMs) {
super(reactContext);
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
mEventDispatcher = reactContext.getEventDispatcher();
mEventDispatcher = new EventDispatcher(reactContext);
mModuleConstants = createConstants(viewManagerResolver);
mCustomDirectEvents = UIManagerModuleConstants.getDirectEventTypeConstants();
mUIImplementation =
@ -150,7 +150,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
int minTimeLeftInFrameForNonBatchedOperationMs) {
super(reactContext);
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
mEventDispatcher = reactContext.getEventDispatcher();
mEventDispatcher = new EventDispatcher(reactContext);
mCustomDirectEvents = MapBuilder.newHashMap();
mModuleConstants = createConstants(viewManagersList, null, mCustomDirectEvents);
mUIImplementation =
@ -704,10 +704,6 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
mUIImplementation.setViewHierarchyUpdateDebugListener(listener);
}
/**
* This method is deprecated, use {@link ReactContext#getEventDispatcher()}.
*/
@Deprecated
public EventDispatcher getEventDispatcher() {
return mEventDispatcher;
}

View File

@ -56,8 +56,7 @@ import javax.annotation.Nullable;
* EVENT_TYPE_ID_MASK = 0x0000ffff00000000
* COALESCING_KEY_MASK = 0xffff000000000000
*/
public class EventDispatcher implements LifecycleEventListener,
com.facebook.react.bridge.EventDispatcher {
public class EventDispatcher implements LifecycleEventListener {
private static final Comparator<Event> EVENT_COMPARATOR = new Comparator<Event>() {
@Override

View File

@ -10,6 +10,7 @@ import android.widget.CompoundButton;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.events.EventDispatcher;
@ -25,7 +26,7 @@ public class ReactCheckBoxManager extends SimpleViewManager<ReactCheckBox> {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
ReactContext reactContext = (ReactContext) buttonView.getContext();
reactContext
.<EventDispatcher>getEventDispatcher()
.getNativeModule(UIManagerModule.class).getEventDispatcher()
.dispatchEvent(new ReactCheckBoxEvent(buttonView.getId(), isChecked));
}
};

View File

@ -19,6 +19,7 @@ import com.facebook.react.common.ReactConstants;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.events.EventDispatcher;
@ -51,7 +52,7 @@ public class ReactDrawerLayoutManager extends ViewGroupManager<ReactDrawerLayout
view.setDrawerListener(
new DrawerEventEmitter(
view,
reactContext.<EventDispatcher>getEventDispatcher()));
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()));
}
@Override

View File

@ -50,6 +50,7 @@ import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.modules.fresco.ReactNetworkImageRequest;
import com.facebook.react.uimanager.FloatUtil;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.views.imagehelper.ImageSource;
import com.facebook.react.views.imagehelper.MultiSourceHelper;
@ -231,7 +232,7 @@ public class ReactImageView extends GenericDraweeView {
if (!shouldNotify) {
mControllerListener = null;
} else {
final EventDispatcher mEventDispatcher = ((ReactContext) getContext()).<EventDispatcher>getEventDispatcher();
final EventDispatcher mEventDispatcher = ((ReactContext) getContext()).getNativeModule(UIManagerModule.class).getEventDispatcher();
mControllerListener = new BaseControllerListener<ImageInfo>() {
@Override

View File

@ -12,6 +12,7 @@ import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.events.EventDispatcher;
@ -71,7 +72,7 @@ public class ReactModalHostManager extends ViewGroupManager<ReactModalHostView>
ThemedReactContext reactContext,
final ReactModalHostView view) {
final EventDispatcher dispatcher =
reactContext.<EventDispatcher>getEventDispatcher();
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
view.setOnRequestCloseListener(
new ReactModalHostView.OnRequestCloseListener() {
@Override

View File

@ -370,7 +370,7 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe
private EventDispatcher getEventDispatcher() {
ReactContext reactContext = getReactContext();
return reactContext.<EventDispatcher>getEventDispatcher();
return reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
}
}
}

View File

@ -19,6 +19,7 @@ import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.events.EventDispatcher;
@ -86,7 +87,7 @@ public abstract class ReactPickerManager extends SimpleViewManager<ReactPicker>
picker.setOnSelectListener(
new PickerEventEmitter(
picker,
reactContext.<EventDispatcher>getEventDispatcher()));
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()));
}
private static class ReactPickerAdapter extends ArrayAdapter<ReadableMap> {

View File

@ -11,6 +11,7 @@ import android.view.View;
import android.view.ViewGroup;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.events.EventDispatcher;
/**
@ -68,7 +69,7 @@ public class ReactScrollViewHelper {
}
ReactContext reactContext = (ReactContext) scrollView.getContext();
reactContext.<EventDispatcher>getEventDispatcher().dispatchEvent(
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
ScrollEvent.obtain(
scrollView.getId(),
scrollEventType,

View File

@ -19,6 +19,7 @@ import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.ReactShadowNodeImpl;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.events.EventDispatcher;
@ -107,7 +108,7 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider> {
@Override
public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) {
ReactContext reactContext = (ReactContext) seekbar.getContext();
reactContext.<EventDispatcher>getEventDispatcher().dispatchEvent(
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
new ReactSliderEvent(
seekbar.getId(),
((ReactSlider) seekbar).toRealProgress(progress),
@ -121,7 +122,7 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider> {
@Override
public void onStopTrackingTouch(SeekBar seekbar) {
ReactContext reactContext = (ReactContext) seekbar.getContext();
reactContext.<EventDispatcher>getEventDispatcher().dispatchEvent(
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
new ReactSlidingCompleteEvent(
seekbar.getId(),
((ReactSlider) seekbar).toRealProgress(seekbar.getProgress())));

View File

@ -16,6 +16,7 @@ import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.annotations.ReactProp;
@ -88,7 +89,7 @@ public class SwipeRefreshLayoutManager extends ViewGroupManager<ReactSwipeRefres
new OnRefreshListener() {
@Override
public void onRefresh() {
reactContext.<EventDispatcher>getEventDispatcher()
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()
.dispatchEvent(new RefreshEvent(view.getId()));
}
});

View File

@ -17,6 +17,7 @@ import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.ReactShadowNodeImpl;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.events.EventDispatcher;
@ -104,7 +105,7 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
ReactContext reactContext = (ReactContext) buttonView.getContext();
reactContext.<EventDispatcher>getEventDispatcher().dispatchEvent(
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
new ReactSwitchEvent(
buttonView.getId(),
isChecked));

View File

@ -12,6 +12,7 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputConnectionWrapper;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.events.EventDispatcher;
import javax.annotation.Nullable;
@ -64,7 +65,7 @@ class ReactEditTextInputConnectionWrapper extends InputConnectionWrapper {
final ReactEditText editText
) {
super(target, false);
mEventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
mEditText = editText;
}

View File

@ -27,6 +27,7 @@ import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.BaseViewManager;
@ -34,6 +35,7 @@ import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.Spacing;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewDefaults;
import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.annotations.ReactProp;
@ -693,7 +695,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
public ReactTextInputTextWatcher(
final ReactContext reactContext,
final ReactEditText editText) {
mEventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
mEditText = editText;
mPreviousText = null;
}
@ -751,7 +753,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
EventDispatcher eventDispatcher =
reactContext.<EventDispatcher>getEventDispatcher();
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
if (hasFocus) {
eventDispatcher.dispatchEvent(
new ReactTextInputFocusEvent(
@ -788,7 +790,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
// Additionally we always generate a `submit` event.
EventDispatcher eventDispatcher =
reactContext.<EventDispatcher>getEventDispatcher();
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
eventDispatcher.dispatchEvent(
new ReactTextInputSubmitEditingEvent(
@ -817,7 +819,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
public ReactContentSizeWatcher(ReactEditText editText) {
mEditText = editText;
ReactContext reactContext = (ReactContext) editText.getContext();
mEventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
}
@Override
@ -856,7 +858,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
public ReactSelectionWatcher(ReactEditText editText) {
mReactEditText = editText;
ReactContext reactContext = (ReactContext) editText.getContext();
mEventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
}
@Override
@ -888,7 +890,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
public ReactScrollWatcher(ReactEditText editText) {
mReactEditText = editText;
ReactContext reactContext = (ReactContext) editText.getContext();
mEventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
}
@Override

View File

@ -19,6 +19,7 @@ import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.events.EventDispatcher;
@ -117,7 +118,7 @@ public class ReactToolbarManager extends ViewGroupManager<ReactToolbar> {
@Override
protected void addEventEmitters(final ThemedReactContext reactContext, final ReactToolbar view) {
final EventDispatcher mEventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
final EventDispatcher mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
view.setNavigationOnClickListener(
new View.OnClickListener() {
@Override

View File

@ -15,6 +15,7 @@ import android.view.View;
import android.view.ViewGroup;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.uimanager.events.NativeGestureUtil;
import java.util.ArrayList;
@ -158,7 +159,7 @@ public class ReactViewPager extends ViewPager {
public ReactViewPager(ReactContext reactContext) {
super(reactContext);
mEventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
mIsCurrentItemFromJs = false;
setOnPageChangeListener(new PageChangeListener());
setAdapter(new Adapter());

View File

@ -9,6 +9,7 @@ package com.facebook.react.views.webview;
import android.annotation.TargetApi;
import android.content.Context;
import com.facebook.react.uimanager.UIManagerModule;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
@ -686,7 +687,7 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
protected static void dispatchEvent(WebView webView, Event event) {
ReactContext reactContext = (ReactContext) webView.getContext();
EventDispatcher eventDispatcher =
reactContext.<EventDispatcher>getEventDispatcher();
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
eventDispatcher.dispatchEvent(event);
}
}