Skip to content

Commit

Permalink
Initialize Event Emitter as part of UIManagerModule
Browse files Browse the repository at this point in the history
Reviewed By: achen1

Differential Revision: D8216184

fbshipit-source-id: 3b188804e2dad2b112f566da49a939eb4338713d
  • Loading branch information
mdvacca authored and facebook-github-bot committed May 31, 2018
1 parent 0f10e03 commit 6e359c4
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1078,8 +1078,6 @@ private ReactApplicationContext createReactContext(
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void onChildStartedNativeGesture(MotionEvent androidEvent) {
return;
}
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
EventDispatcher eventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
mJSTouchDispatcher.onChildStartedNativeGesture(androidEvent, eventDispatcher);
}

Expand Down Expand Up @@ -280,7 +280,7 @@ private void dispatchJSTouchEvent(MotionEvent event) {
return;
}
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
EventDispatcher eventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -351,11 +350,4 @@ public JavaScriptContextHolder getJavaScriptContextHolder() {
return mCatalystInstance.getJavaScriptContextHolder();
}

public <T extends EventDispatcher> T getEventDispatcher() {
return (T) mEventDispatcher;
}

public void setEventDispatcher(EventDispatcher eventDispatcher) {
mEventDispatcher = eventDispatcher;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -126,7 +127,7 @@ public void dispatchImageLoadEvent(int reactTag, int imageLoadEvent) {
}

ReactContext reactContext = ((ReactContext) view.getContext());
reactContext.<EventDispatcher>getEventDispatcher().dispatchEvent(
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
new ImageLoadEvent(reactTag, imageLoadEvent));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package com.facebook.react.uimanager;

import com.facebook.react.bridge.EventDispatcher;
import javax.annotation.Nullable;

import android.app.Activity;
Expand All @@ -17,8 +16,6 @@
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.
Expand Down Expand Up @@ -56,9 +53,4 @@ public boolean hasCurrentActivity() {
public @Nullable Activity getCurrentActivity() {
return mReactApplicationContext.getCurrentActivity();
}

@Override
public <T extends EventDispatcher> T getEventDispatcher() {
return mReactApplicationContext.getEventDispatcher();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public UIManagerModule(
int minTimeLeftInFrameForNonBatchedOperationMs) {
super(reactContext);
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
mEventDispatcher = reactContext.getEventDispatcher();
mEventDispatcher = new EventDispatcher(reactContext);
mModuleConstants = createConstants(viewManagerResolver);
mCustomDirectEvents = UIManagerModuleConstants.getDirectEventTypeConstants();
mUIImplementation =
Expand All @@ -150,7 +150,7 @@ public UIManagerModule(
int minTimeLeftInFrameForNonBatchedOperationMs) {
super(reactContext);
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
mEventDispatcher = reactContext.getEventDispatcher();
mEventDispatcher = new EventDispatcher(reactContext);
mCustomDirectEvents = MapBuilder.newHashMap();
mModuleConstants = createConstants(viewManagersList, null, mCustomDirectEvents);
mUIImplementation =
Expand Down Expand Up @@ -704,10 +704,6 @@ public void setViewHierarchyUpdateDebugListener(
mUIImplementation.setViewHierarchyUpdateDebugListener(listener);
}

/**
* This method is deprecated, use {@link ReactContext#getEventDispatcher()}.
*/
@Deprecated
public EventDispatcher getEventDispatcher() {
return mEventDispatcher;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand All @@ -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));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -51,7 +52,7 @@ protected void addEventEmitters(ThemedReactContext reactContext, ReactDrawerLayo
view.setDrawerListener(
new DrawerEventEmitter(
view,
reactContext.<EventDispatcher>getEventDispatcher()));
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
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;
Expand Down Expand Up @@ -231,7 +232,7 @@ public void setShouldNotifyLoadEvents(boolean shouldNotify) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand Down Expand Up @@ -71,7 +72,7 @@ protected void addEventEmitters(
ThemedReactContext reactContext,
final ReactModalHostView view) {
final EventDispatcher dispatcher =
reactContext.<EventDispatcher>getEventDispatcher();
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
view.setOnRequestCloseListener(
new ReactModalHostView.OnRequestCloseListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {

private EventDispatcher getEventDispatcher() {
ReactContext reactContext = getReactContext();
return reactContext.<EventDispatcher>getEventDispatcher();
return reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -86,7 +87,7 @@ protected void addEventEmitters(
picker.setOnSelectListener(
new PickerEventEmitter(
picker,
reactContext.<EventDispatcher>getEventDispatcher()));
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()));
}

private static class ReactPickerAdapter extends ArrayAdapter<ReadableMap> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;

/**
Expand Down Expand Up @@ -68,7 +69,7 @@ private static void emitScrollEvent(
}

ReactContext reactContext = (ReactContext) scrollView.getContext();
reactContext.<EventDispatcher>getEventDispatcher().dispatchEvent(
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
ScrollEvent.obtain(
scrollView.getId(),
scrollEventType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -107,7 +108,7 @@ public long measure(
@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),
Expand All @@ -121,7 +122,7 @@ public void onStartTrackingTouch(SeekBar seekbar) {
@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())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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;
Expand Down Expand Up @@ -88,7 +89,7 @@ protected void addEventEmitters(
new OnRefreshListener() {
@Override
public void onRefresh() {
reactContext.<EventDispatcher>getEventDispatcher()
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()
.dispatchEvent(new RefreshEvent(view.getId()));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
Expand Down Expand Up @@ -104,7 +105,7 @@ public long measure(
@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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;

Expand Down Expand Up @@ -64,7 +65,7 @@ public ReactEditTextInputConnectionWrapper(
final ReactEditText editText
) {
super(target, false);
mEventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
mEditText = editText;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
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;
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;
Expand Down Expand Up @@ -693,7 +695,7 @@ private class ReactTextInputTextWatcher implements TextWatcher {
public ReactTextInputTextWatcher(
final ReactContext reactContext,
final ReactEditText editText) {
mEventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
mEditText = editText;
mPreviousText = null;
}
Expand Down Expand Up @@ -751,7 +753,7 @@ protected void addEventEmitters(
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(
Expand Down Expand Up @@ -788,7 +790,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent keyEvent) {
// Additionally we always generate a `submit` event.

EventDispatcher eventDispatcher =
reactContext.<EventDispatcher>getEventDispatcher();
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();

eventDispatcher.dispatchEvent(
new ReactTextInputSubmitEditingEvent(
Expand Down Expand Up @@ -817,7 +819,7 @@ private class ReactContentSizeWatcher implements ContentSizeWatcher {
public ReactContentSizeWatcher(ReactEditText editText) {
mEditText = editText;
ReactContext reactContext = (ReactContext) editText.getContext();
mEventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
}

@Override
Expand Down Expand Up @@ -856,7 +858,7 @@ private class ReactSelectionWatcher implements SelectionWatcher {
public ReactSelectionWatcher(ReactEditText editText) {
mReactEditText = editText;
ReactContext reactContext = (ReactContext) editText.getContext();
mEventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
}

@Override
Expand Down Expand Up @@ -888,7 +890,7 @@ private class ReactScrollWatcher implements ScrollWatcher {
public ReactScrollWatcher(ReactEditText editText) {
mReactEditText = editText;
ReactContext reactContext = (ReactContext) editText.getContext();
mEventDispatcher = reactContext.<EventDispatcher>getEventDispatcher();
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
}

@Override
Expand Down
Loading

0 comments on commit 6e359c4

Please sign in to comment.