com.facebook.react.uimanager.events.EventDispatcher Java Examples

The following examples show how to use com.facebook.react.uimanager.events.EventDispatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactRootView.java    From react-native-GPay with MIT License 6 votes vote down vote up
private void dispatchJSTouchEvent(MotionEvent event) {
  if (mReactInstanceManager == null || !mIsAttachedToInstance ||
    mReactInstanceManager.getCurrentReactContext() == null) {
    FLog.w(
      ReactConstants.TAG,
      "Unable to dispatch touch to JS as the catalyst instance has not been attached");
    return;
  }
  if (mJSTouchDispatcher == null) {
    FLog.w(
      ReactConstants.TAG,
      "Unable to dispatch touch to JS before the dispatcher is available");
    return;
  }
  ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
  EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
  mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher);
}
 
Example #2
Source File: UIManagerModule.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Deprecated
public UIManagerModule(
    ReactApplicationContext reactContext,
    List<ViewManager> viewManagersList,
    UIImplementationProvider uiImplementationProvider,
    int minTimeLeftInFrameForNonBatchedOperationMs) {
  super(reactContext);
  DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
  mEventDispatcher = new EventDispatcher(reactContext);
  mCustomDirectEvents = MapBuilder.newHashMap();
  mModuleConstants = createConstants(viewManagersList, null, mCustomDirectEvents);
  mUIImplementation =
      uiImplementationProvider.createUIImplementation(
          reactContext,
          viewManagersList,
          mEventDispatcher,
          minTimeLeftInFrameForNonBatchedOperationMs);

  reactContext.addLifecycleEventListener(this);
}
 
Example #3
Source File: ReactAztecText.java    From react-native-aztec with GNU General Public License v2.0 6 votes vote down vote up
private boolean onBackspace() {
    int cursorPositionStart = getSelectionStart();
    int cursorPositionEnd = getSelectionEnd();
    // Make sure to report backspace at the beginning only, with no selection.
    if (cursorPositionStart != 0 || cursorPositionEnd != 0) {
        return false;
    }

    disableTextChangedListener();
    String content = toHtml(false);
    enableTextChangedListener();
    ReactContext reactContext = (ReactContext) getContext();
    EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
    // TODO: isRTL? Should be passed here?
    eventDispatcher.dispatchEvent(
            new ReactAztecBackspaceEvent(getId(), content, cursorPositionStart, cursorPositionEnd)
    );
    return true;
}
 
Example #4
Source File: UIManagerModule.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Deprecated
public UIManagerModule(
    ReactApplicationContext reactContext,
    ViewManagerResolver viewManagerResolver,
    UIImplementationProvider uiImplementationProvider,
    int minTimeLeftInFrameForNonBatchedOperationMs) {
  super(reactContext);
  DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
  mEventDispatcher = new EventDispatcher(reactContext);
  mModuleConstants = createConstants(viewManagerResolver);
  mCustomDirectEvents = UIManagerModuleConstants.getDirectEventTypeConstants();
  mUIImplementation =
      uiImplementationProvider.createUIImplementation(
          reactContext,
          viewManagerResolver,
          mEventDispatcher,
          minTimeLeftInFrameForNonBatchedOperationMs);

  reactContext.addLifecycleEventListener(this);
}
 
Example #5
Source File: JSTouchDispatcher.java    From react-native-GPay with MIT License 6 votes vote down vote up
private void dispatchCancelEvent(MotionEvent androidEvent, EventDispatcher eventDispatcher) {
  // This means the gesture has already ended, via some other CANCEL or UP event. This is not
  // expected to happen very often as it would mean some child View has decided to intercept the
  // touch stream and start a native gesture only upon receiving the UP/CANCEL event.
  if (mTargetTag == -1) {
    FLog.w(
      ReactConstants.TAG,
      "Can't cancel already finished gesture. Is a child View trying to start a gesture from " +
        "an UP/CANCEL event?");
    return;
  }

  Assertions.assertCondition(
    !mChildIsHandlingNativeGesture,
    "Expected to not have already sent a cancel for this gesture");
  Assertions.assertNotNull(eventDispatcher).dispatchEvent(
    TouchEvent.obtain(
      mTargetTag,
      TouchEventType.CANCEL,
      androidEvent,
      mGestureStartTime,
      mTargetCoordinates[0],
      mTargetCoordinates[1],
      mTouchEventCoalescingKeyHelper));
}
 
Example #6
Source File: ReactRootView.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public void onChildStartedNativeGesture(MotionEvent androidEvent) {
  if (mReactInstanceManager == null || !mIsAttachedToInstance ||
    mReactInstanceManager.getCurrentReactContext() == null) {
    FLog.w(
      ReactConstants.TAG,
      "Unable to dispatch touch to JS as the catalyst instance has not been attached");
    return;
  }
  if (mJSTouchDispatcher == null) {
    FLog.w(
      ReactConstants.TAG,
      "Unable to dispatch touch to JS before the dispatcher is available");
    return;
  }
  ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
  EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
  mJSTouchDispatcher.onChildStartedNativeGesture(androidEvent, eventDispatcher);
}
 
Example #7
Source File: FabricUIManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
public FabricUIManager(
    ReactApplicationContext reactContext,
    ViewManagerRegistry viewManagerRegistry,
    JavaScriptContextHolder jsContext,
    EventDispatcher eventDispatcher) {
  DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
  mReactApplicationContext = reactContext;
  mViewManagerRegistry = viewManagerRegistry;
  mNativeViewHierarchyManager = new NativeViewHierarchyManager(viewManagerRegistry);
  mUIViewOperationQueue =
      new UIViewOperationQueue(
          reactContext, mNativeViewHierarchyManager, 0);
  mFabricReconciler = new FabricReconciler(mUIViewOperationQueue);
  mFabricEventEmitter =
    new FabricEventEmitter(mReactApplicationContext, this);
  mEventDispatcher = eventDispatcher;
  mJSContext = jsContext;
}
 
Example #8
Source File: ReactToolbarManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
protected void addEventEmitters(final ThemedReactContext reactContext, final ReactToolbar view) {
  final EventDispatcher mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
  view.setNavigationOnClickListener(
      new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          mEventDispatcher.dispatchEvent(
              new ToolbarClickEvent(view.getId(), -1));
        }
      });

  view.setOnMenuItemClickListener(
      new ReactToolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
          mEventDispatcher.dispatchEvent(
              new ToolbarClickEvent(
                  view.getId(),
                  menuItem.getOrder()));
          return true;
        }
      });
}
 
Example #9
Source File: UIImplementation.java    From react-native-GPay with MIT License 5 votes vote down vote up
protected UIImplementation(
    ReactApplicationContext reactContext,
    ViewManagerRegistry viewManagers,
    UIViewOperationQueue operationsQueue,
    EventDispatcher eventDispatcher) {
  mReactContext = reactContext;
  mViewManagers = viewManagers;
  mOperationsQueue = operationsQueue;
  mNativeViewHierarchyOptimizer = new NativeViewHierarchyOptimizer(
      mOperationsQueue,
      mShadowNodeRegistry);
  mEventDispatcher = eventDispatcher;
}
 
Example #10
Source File: UIImplementationProvider.java    From react-native-GPay with MIT License 5 votes vote down vote up
public UIImplementation createUIImplementation(
    ReactApplicationContext reactContext,
    List<ViewManager> viewManagerList,
    EventDispatcher eventDispatcher,
    int minTimeLeftInFrameForNonBatchedOperationMs) {
  return new UIImplementation(
      reactContext,
      viewManagerList,
      eventDispatcher,
      minTimeLeftInFrameForNonBatchedOperationMs);
}
 
Example #11
Source File: UIImplementation.java    From react-native-GPay with MIT License 5 votes vote down vote up
public UIImplementation(
    ReactApplicationContext reactContext,
    UIManagerModule.ViewManagerResolver viewManagerResolver,
    EventDispatcher eventDispatcher,
    int minTimeLeftInFrameForNonBatchedOperationMs) {
  this(
      reactContext,
      new ViewManagerRegistry(viewManagerResolver),
      eventDispatcher,
      minTimeLeftInFrameForNonBatchedOperationMs);
}
 
Example #12
Source File: UIImplementation.java    From react-native-GPay with MIT License 5 votes vote down vote up
public UIImplementation(
    ReactApplicationContext reactContext,
    List<ViewManager> viewManagers,
    EventDispatcher eventDispatcher,
    int minTimeLeftInFrameForNonBatchedOperationMs) {
  this(
      reactContext,
      new ViewManagerRegistry(viewManagers),
      eventDispatcher,
      minTimeLeftInFrameForNonBatchedOperationMs);
}
 
Example #13
Source File: UIImplementation.java    From react-native-GPay with MIT License 5 votes vote down vote up
private UIImplementation(
    ReactApplicationContext reactContext,
    ViewManagerRegistry viewManagers,
    EventDispatcher eventDispatcher,
    int minTimeLeftInFrameForNonBatchedOperationMs) {
  this(
      reactContext,
      viewManagers,
      new UIViewOperationQueue(
          reactContext,
          new NativeViewHierarchyManager(viewManagers),
          minTimeLeftInFrameForNonBatchedOperationMs),
      eventDispatcher);
}
 
Example #14
Source File: ReactAztecText.java    From react-native-aztec with GNU General Public License v2.0 5 votes vote down vote up
private void updateToolbarButtons(ArrayList<ITextFormat> appliedStyles) {
    // Read the applied styles and get the String list of formatting options
    LinkedList<String> formattingOptions = new LinkedList<>();
    for (ITextFormat currentStyle : appliedStyles) {
        if ((currentStyle == AztecTextFormat.FORMAT_STRONG || currentStyle == AztecTextFormat.FORMAT_BOLD)
                && !formattingOptions.contains("bold")) {
            formattingOptions.add("bold");
        }
        if ((currentStyle == AztecTextFormat.FORMAT_ITALIC || currentStyle == AztecTextFormat.FORMAT_CITE)
                && !formattingOptions.contains("italic")) {
            formattingOptions.add("italic");
        }
        if (currentStyle == AztecTextFormat.FORMAT_STRIKETHROUGH) {
            formattingOptions.add("strikethrough");
        }
    }

    // Check if the same formatting event was already sent
    String newOptionsAsString = "";
    for (String currentFormatting: formattingOptions) {
        newOptionsAsString += currentFormatting;
    }
    if (newOptionsAsString.equals(lastSentFormattingOptionsEventString)) {
        // no need to send any event now
        return;
    }
    lastSentFormattingOptionsEventString = newOptionsAsString;

    if (shouldHandleActiveFormatsChange) {
        ReactContext reactContext = (ReactContext) getContext();
        EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
        eventDispatcher.dispatchEvent(
                new ReactAztecFormattingChangeEvent(
                        getId(),
                        formattingOptions.toArray(new String[formattingOptions.size()])
                )
        );
    }
}
 
Example #15
Source File: JSTouchDispatcher.java    From react-native-GPay with MIT License 5 votes vote down vote up
public void onChildStartedNativeGesture(MotionEvent androidEvent, EventDispatcher eventDispatcher) {
  if (mChildIsHandlingNativeGesture) {
    // This means we previously had another child start handling this native gesture and now a
    // different native parent of that child has decided to intercept the touch stream and handle
    // the gesture itself. Example where this can happen: HorizontalScrollView in a ScrollView.
    return;
  }

  dispatchCancelEvent(androidEvent, eventDispatcher);
  mChildIsHandlingNativeGesture = true;
  mTargetTag = -1;
}
 
Example #16
Source File: FabricUIManagerTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  mNextReactTag = 2;
  ReactApplicationContext reactContext = new ReactApplicationContext(RuntimeEnvironment.application);
  reactContext.initializeWithInstance(ReactTestHelper.createMockCatalystInstance());
  mThemedReactContext = new ThemedReactContext(reactContext, reactContext);

  List<ViewManager> viewManagers =
      Arrays.<ViewManager>asList(
          new ReactViewManager(), new ReactTextViewManager(), new ReactRawTextManager());
  ViewManagerRegistry viewManagerRegistry = new ViewManagerRegistry(viewManagers);
  JavaScriptContextHolder jsContext = mock(JavaScriptContextHolder.class);
  EventDispatcher eventDispatcher = mock(EventDispatcher.class);
  mFabricUIManager = new FabricUIManager(reactContext, viewManagerRegistry, jsContext, eventDispatcher);
}
 
Example #17
Source File: FabricReconcilerTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Before
public void setUp() {
  CatalystInstance catalystInstance = ReactTestHelper.createMockCatalystInstance();
  ReactApplicationContext reactContext =
      new ReactApplicationContext(RuntimeEnvironment.application);
  reactContext.initializeWithInstance(catalystInstance);
  List<ViewManager> viewManagers = new ArrayList<>();
  ViewManagerRegistry viewManagerRegistry = new ViewManagerRegistry(viewManagers);
  JavaScriptContextHolder jsContext = mock(JavaScriptContextHolder.class);
  EventDispatcher eventDispatcher = mock(EventDispatcher.class);
  mFabricUIManager = new FabricUIManager(reactContext, viewManagerRegistry, jsContext, eventDispatcher);
  mMockUIViewOperationQueue = new MockUIViewOperationQueue(reactContext);
  mFabricReconciler = new FabricReconciler(mMockUIViewOperationQueue);
}
 
Example #18
Source File: ReactImageView.java    From react-native-GPay with MIT License 5 votes vote down vote up
public void setShouldNotifyLoadEvents(boolean shouldNotify) {
  if (!shouldNotify) {
    mControllerListener = null;
  } else {
    final EventDispatcher mEventDispatcher = ((ReactContext) getContext()).getNativeModule(UIManagerModule.class).getEventDispatcher();

    mControllerListener = new BaseControllerListener<ImageInfo>() {
      @Override
      public void onSubmit(String id, Object callerContext) {
        mEventDispatcher.dispatchEvent(
          new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_START));
      }

      @Override
      public void onFinalImageSet(
        String id,
        @Nullable final ImageInfo imageInfo,
        @Nullable Animatable animatable) {
        if (imageInfo != null) {
          mEventDispatcher.dispatchEvent(
            new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD,
              mImageSource.getSource(), imageInfo.getWidth(), imageInfo.getHeight()));
          mEventDispatcher.dispatchEvent(
            new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END));
        }
      }

      @Override
      public void onFailure(String id, Throwable throwable) {
        mEventDispatcher.dispatchEvent(
          new ImageLoadEvent(getId(), ImageLoadEvent.ON_ERROR));
        mEventDispatcher.dispatchEvent(
          new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END));
      }
    };
  }

  mIsDirty = true;
}
 
Example #19
Source File: ReactAztecManager.java    From react-native-aztec with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void addEventEmitters(final ThemedReactContext reactContext, final ReactAztecText aztecText) {
    aztecText.addTextChangedListener(new AztecTextWatcher(reactContext, aztecText));
    aztecText.setOnFocusChangeListener(
            new View.OnFocusChangeListener() {
                public void onFocusChange(View v, boolean hasFocus) {
                    EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
                    final ReactAztecText editText = (ReactAztecText)v;
                    if (hasFocus) {
                        eventDispatcher.dispatchEvent(
                                new ReactAztecFocusEvent(
                                        editText.getId()));
                    } else {
                        eventDispatcher.dispatchEvent(
                                new ReactAztecBlurEvent(
                                        editText.getId()));

                        eventDispatcher.dispatchEvent(
                                new ReactAztecEndEditingEvent(
                                        editText.getId(),
                                        editText.toHtml(false)));
                    }
                }
            });

    // Don't think we need to add setOnEditorActionListener here (intercept Enter for example), but
    // in case check ReactTextInputManager
}
 
Example #20
Source File: ReactAztecText.java    From react-native-aztec with GNU General Public License v2.0 5 votes vote down vote up
private void propagateSelectionChanges(int selStart, int selEnd) {
    if (!shouldHandleOnSelectionChange) {
        return;
    }
    String content = toHtml(false);
    ReactContext reactContext = (ReactContext) getContext();
    EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
    eventDispatcher.dispatchEvent(
            new ReactAztecSelectionChangeEvent(getId(), content, selStart, selEnd)
    );
}
 
Example #21
Source File: ReactAztecText.java    From react-native-aztec with GNU General Public License v2.0 5 votes vote down vote up
private boolean onEnter() {
    disableTextChangedListener();
    String content = toHtml(false);
    int cursorPositionStart = getSelectionStart();
    int cursorPositionEnd = getSelectionEnd();
    enableTextChangedListener();
    ReactContext reactContext = (ReactContext) getContext();
    EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
    eventDispatcher.dispatchEvent(
            new ReactAztecEnterEvent(getId(), content, cursorPositionStart, cursorPositionEnd)
    );
    return true;
}
 
Example #22
Source File: UIImplementationProvider.java    From react-native-GPay with MIT License 5 votes vote down vote up
public UIImplementation createUIImplementation(
    ReactApplicationContext reactContext,
    UIManagerModule.ViewManagerResolver viewManagerResolver,
    EventDispatcher eventDispatcher,
    int minTimeLeftInFrameForNonBatchedOperationMs) {
  return new UIImplementation(
      reactContext,
      viewManagerResolver,
      eventDispatcher,
      minTimeLeftInFrameForNonBatchedOperationMs);
}
 
Example #23
Source File: SyncUiImplementation.java    From react-native-navigation with MIT License 4 votes vote down vote up
public SyncUiImplementation(ReactApplicationContext reactContext, UIManagerModule.ViewManagerResolver viewManagerResolver, EventDispatcher eventDispatcher, int minTimeLeftInFrameForNonBatchedOperationMs) {
    super(reactContext, viewManagerResolver, eventDispatcher, minTimeLeftInFrameForNonBatchedOperationMs);
}
 
Example #24
Source File: SyncUiImplementation.java    From react-native-navigation with MIT License 4 votes vote down vote up
public SyncUiImplementation(ReactApplicationContext reactContext, UIManagerModule.ViewManagerResolver viewManagerResolver, EventDispatcher eventDispatcher, int minTimeLeftInFrameForNonBatchedOperationMs) {
    super(reactContext, viewManagerResolver, eventDispatcher, minTimeLeftInFrameForNonBatchedOperationMs);
}
 
Example #25
Source File: ScrollEventListener.java    From react-native-navigation with MIT License 4 votes vote down vote up
public ScrollEventListener(EventDispatcher eventDispatcher) {
    this.eventDispatcher = eventDispatcher;
}
 
Example #26
Source File: ReactView.java    From react-native-navigation with MIT License 4 votes vote down vote up
public EventDispatcher getEventDispatcher() {
    ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
    return reactContext == null ? null : reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
}
 
Example #27
Source File: SyncUiImplementation.java    From react-native-navigation with MIT License 4 votes vote down vote up
public SyncUiImplementation(ReactApplicationContext reactContext, List<ViewManager> viewManagerList, EventDispatcher eventDispatcher, int minTimeLeftInFrameForNonBatchedOperationMs) {
    super(reactContext, viewManagerList, eventDispatcher, minTimeLeftInFrameForNonBatchedOperationMs);
}
 
Example #28
Source File: SyncUiImplementation.java    From react-native-navigation with MIT License 4 votes vote down vote up
public SyncUiImplementation(ReactApplicationContext reactContext, UIManagerModule.ViewManagerResolver viewManagerResolver, EventDispatcher eventDispatcher, int minTimeLeftInFrameForNonBatchedOperationMs) {
    super(reactContext, viewManagerResolver, eventDispatcher, minTimeLeftInFrameForNonBatchedOperationMs);
}
 
Example #29
Source File: SyncUiImplementation.java    From react-native-navigation with MIT License 4 votes vote down vote up
@Override
public UIImplementation createUIImplementation(ReactApplicationContext reactContext, List<ViewManager> viewManagerList, EventDispatcher eventDispatcher, int minTimeLeftInFrameForNonBatchedOperationMs) {
    return new SyncUiImplementation(reactContext, viewManagerList, eventDispatcher, minTimeLeftInFrameForNonBatchedOperationMs);
}
 
Example #30
Source File: SyncUiImplementation.java    From react-native-navigation with MIT License 4 votes vote down vote up
@Override
public UIImplementation createUIImplementation(ReactApplicationContext reactContext, UIManagerModule.ViewManagerResolver viewManagerResolver, EventDispatcher eventDispatcher, int minTimeLeftInFrameForNonBatchedOperationMs) {
    return new SyncUiImplementation(reactContext, viewManagerResolver, eventDispatcher, minTimeLeftInFrameForNonBatchedOperationMs);
}