Java Code Examples for com.facebook.react.common.SystemClock#uptimeMillis()

The following examples show how to use com.facebook.react.common.SystemClock#uptimeMillis() . 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: Timing.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public void run() {
  if (mCancelled) {
    return;
  }

  long frameTimeMillis = mFrameStartTime / 1000000;
  long timeSinceBoot = SystemClock.uptimeMillis();
  long frameTimeElapsed = timeSinceBoot - frameTimeMillis;
  long time = SystemClock.currentTimeMillis();
  long absoluteFrameStartTime = time - frameTimeElapsed;

  if (FRAME_DURATION_MS - (float) frameTimeElapsed < IDLE_CALLBACK_FRAME_DEADLINE_MS) {
    return;
  }

  boolean sendIdleEvents;
  synchronized (mIdleCallbackGuard) {
    sendIdleEvents = mSendIdleEvents;
  }

  if (sendIdleEvents) {
    getReactApplicationContext().getJSModule(JSTimers.class)
        .callIdleCallbacks(absoluteFrameStartTime);
  }

  mCurrentIdleCallbackRunnable = null;
}
 
Example 2
Source File: Event.java    From react-native-GPay with MIT License 4 votes vote down vote up
/**
 * This method needs to be called before event is sent to event dispatcher.
 */
protected void init(int viewTag) {
  mViewTag = viewTag;
  mTimestampMs = SystemClock.uptimeMillis();
  mInitialized = true;
}
 
Example 3
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);
}