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

The following examples show how to use com.facebook.react.uimanager.events.Event. 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: NativeAnimatedNodesManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
private void handleEvent(Event event) {
  if (!mEventDrivers.isEmpty()) {
    // If the event has a different name in native convert it to it's JS name.
    String eventName = mCustomEventNamesResolver.resolveCustomEventName(event.getEventName());
    List<EventAnimationDriver> driversForKey = mEventDrivers.get(event.getViewTag() + eventName);
    if (driversForKey != null) {
      for (EventAnimationDriver driver : driversForKey) {
        stopAnimationsForNode(driver.mValueNode);
        event.dispatch(driver);
        mRunUpdateNodeList.add(driver.mValueNode);
      }
      updateNodes(mRunUpdateNodeList);
      mRunUpdateNodeList.clear();
    }
  }
}
 
Example #2
Source File: NativeAnimatedNodesManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public void onEventDispatch(final Event event) {
  // Events can be dispatched from any thread so we have to make sure handleEvent is run from the
  // UI thread.
  if (UiThreadUtil.isOnUiThread()) {
    handleEvent(event);
  } else {
    UiThreadUtil.runOnUiThread(new Runnable() {
      @Override
      public void run() {
        handleEvent(event);
      }
    });
  }
}
 
Example #3
Source File: NativeAnimatedNodeTraversalTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
private Event createScrollEvent(final int tag, final double value) {
  return new Event(tag) {
    @Override
    public String getEventName() {
      return "topScroll";
    }

    @Override
    public void dispatch(RCTEventEmitter rctEventEmitter) {
      rctEventEmitter.receiveEvent(tag, "topScroll", JavaOnlyMap.of(
        "contentOffset", JavaOnlyMap.of("y", value)));
    }
  };
}
 
Example #4
Source File: Web3WebviewManager.java    From react-native-web3-webview with MIT License 4 votes vote down vote up
protected static void dispatchEvent(WebView webView, Event event) {
    ReactContext reactContext = (ReactContext) webView.getContext();
    EventDispatcher eventDispatcher =
            reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
    eventDispatcher.dispatchEvent(event);
}
 
Example #5
Source File: ReactWebViewManager.java    From react-native-GPay with MIT License 4 votes vote down vote up
protected static void dispatchEvent(WebView webView, Event event) {
  ReactContext reactContext = (ReactContext) webView.getContext();
  EventDispatcher eventDispatcher =
    reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
  eventDispatcher.dispatchEvent(event);
}
 
Example #6
Source File: RootViewTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Test
public void testTouchEmitter() {
  ReactInstanceManager instanceManager = mock(ReactInstanceManager.class);
  when(instanceManager.getCurrentReactContext()).thenReturn(mReactContext);

  UIManagerModule uiManager = mock(UIManagerModule.class);
  EventDispatcher eventDispatcher = mock(EventDispatcher.class);
  RCTEventEmitter eventEmitterModuleMock = mock(RCTEventEmitter.class);
  when(mCatalystInstanceMock.getNativeModule(UIManagerModule.class))
      .thenReturn(uiManager);
  when(uiManager.getEventDispatcher()).thenReturn(eventDispatcher);

  int rootViewId = 7;

  ReactRootView rootView = new ReactRootView(mReactContext);
  rootView.setId(rootViewId);
  rootView.startReactApplication(instanceManager, "");
  rootView.simulateAttachForTesting();

  long ts = SystemClock.uptimeMillis();

  // Test ACTION_DOWN event
  rootView.onTouchEvent(
      MotionEvent.obtain(100, ts, MotionEvent.ACTION_DOWN, 0, 0, 0));

  ArgumentCaptor<Event> downEventCaptor = ArgumentCaptor.forClass(Event.class);
  verify(eventDispatcher).dispatchEvent(downEventCaptor.capture());
  verifyNoMoreInteractions(eventDispatcher);

  downEventCaptor.getValue().dispatch(eventEmitterModuleMock);

  ArgumentCaptor<JavaOnlyArray> downActionTouchesArgCaptor =
      ArgumentCaptor.forClass(JavaOnlyArray.class);
  verify(eventEmitterModuleMock).receiveTouches(
      eq("topTouchStart"),
      downActionTouchesArgCaptor.capture(),
      any(JavaOnlyArray.class));
  verifyNoMoreInteractions(eventEmitterModuleMock);

  assertThat(downActionTouchesArgCaptor.getValue().size()).isEqualTo(1);
  assertThat(downActionTouchesArgCaptor.getValue().getMap(0)).isEqualTo(
      JavaOnlyMap.of(
          "pageX",
          0.,
          "pageY",
          0.,
          "locationX",
          0.,
          "locationY",
          0.,
          "target",
          rootViewId,
          "timestamp",
          (double) ts,
          "identifier",
          0.));

  // Test ACTION_UP event
  reset(eventEmitterModuleMock, eventDispatcher);

  ArgumentCaptor<Event> upEventCaptor = ArgumentCaptor.forClass(Event.class);
  ArgumentCaptor<JavaOnlyArray> upActionTouchesArgCaptor =
      ArgumentCaptor.forClass(JavaOnlyArray.class);

  rootView.onTouchEvent(
      MotionEvent.obtain(50, ts, MotionEvent.ACTION_UP, 0, 0, 0));
  verify(eventDispatcher).dispatchEvent(upEventCaptor.capture());
  verifyNoMoreInteractions(eventDispatcher);

  upEventCaptor.getValue().dispatch(eventEmitterModuleMock);
  verify(eventEmitterModuleMock).receiveTouches(
      eq("topTouchEnd"),
      upActionTouchesArgCaptor.capture(),
      any(WritableArray.class));
  verifyNoMoreInteractions(eventEmitterModuleMock);

  assertThat(upActionTouchesArgCaptor.getValue().size()).isEqualTo(1);
  assertThat(upActionTouchesArgCaptor.getValue().getMap(0)).isEqualTo(
      JavaOnlyMap.of(
          "pageX",
          0.,
          "pageY",
          0.,
          "locationX",
          0.,
          "locationY",
          0.,
          "target",
          rootViewId,
          "timestamp",
          (double) ts,
          "identifier",
          0.));

  // Test other action
  reset(eventDispatcher);
  rootView.onTouchEvent(
      MotionEvent.obtain(50, new Date().getTime(), MotionEvent.ACTION_HOVER_MOVE, 0, 0, 0));
  verifyNoMoreInteractions(eventDispatcher);
}
 
Example #7
Source File: ScrollEventListener.java    From react-native-navigation with MIT License 4 votes vote down vote up
@Override
public void onEventDispatch(Event event) {
    if (event instanceof ScrollEvent) {
        handleScrollEvent((ScrollEvent) event);
    }
}
 
Example #8
Source File: RNX5WebViewManager.java    From react-native-x5 with MIT License 4 votes vote down vote up
private static void dispatchEvent(WebView webView, Event event) {
    ReactContext reactContext = (ReactContext) webView.getContext();
    EventDispatcher eventDispatcher =
            reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
    eventDispatcher.dispatchEvent(event);
}