Java Code Examples for com.facebook.react.bridge.JavaOnlyMap#of()

The following examples show how to use com.facebook.react.bridge.JavaOnlyMap#of() . 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: ReactTextInputPropertyTest.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Test
public void testSelection() {
  ReactEditText view = mManager.createViewInstance(mThemedContext);
  view.setText("Need some text to select something...");

  mManager.updateProperties(view, buildStyles());
  assertThat(view.getSelectionStart()).isEqualTo(0);
  assertThat(view.getSelectionEnd()).isEqualTo(0);

  JavaOnlyMap selection = JavaOnlyMap.of("start", 5, "end", 10);
  mManager.updateProperties(view, buildStyles("selection", selection));
  assertThat(view.getSelectionStart()).isEqualTo(5);
  assertThat(view.getSelectionEnd()).isEqualTo(10);

  mManager.updateProperties(view, buildStyles("selection", null));
  assertThat(view.getSelectionStart()).isEqualTo(5);
  assertThat(view.getSelectionEnd()).isEqualTo(10);
}
 
Example 2
Source File: ReactTextInputPropertyTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
public ReactStylesDiffMap buildStyles(Object... keysAndValues) {
  return new ReactStylesDiffMap(JavaOnlyMap.of(keysAndValues));
}
 
Example 3
Source File: ReactSliderPropertyTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
public ReactStylesDiffMap buildStyles(Object... keysAndValues) {
  return new ReactStylesDiffMap(JavaOnlyMap.of(keysAndValues));
}
 
Example 4
Source File: ReactImagePropertyTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
public ReactStylesDiffMap buildStyles(Object... keysAndValues) {
  return new ReactStylesDiffMap(JavaOnlyMap.of(keysAndValues));
}
 
Example 5
Source File: SimpleViewPropertyTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
public ReactStylesDiffMap buildStyles(Object... keysAndValues) {
  return new ReactStylesDiffMap(JavaOnlyMap.of(keysAndValues));
}
 
Example 6
Source File: ReactPropForShadowNodeSetterTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
public static ReactStylesDiffMap buildStyles(Object... keysAndValues) {
  return new ReactStylesDiffMap(JavaOnlyMap.of(keysAndValues));
}
 
Example 7
Source File: ReactPropAnnotationSetterTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
public static ReactStylesDiffMap buildStyles(Object... keysAndValues) {
  return new ReactStylesDiffMap(JavaOnlyMap.of(keysAndValues));
}
 
Example 8
Source File: LayoutPropertyApplicatorTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
public ReactStylesDiffMap buildStyles(Object... keysAndValues) {
  return new ReactStylesDiffMap(JavaOnlyMap.of(keysAndValues));
}
 
Example 9
Source File: NativeAnimatedNodeTraversalTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
/**
 * In this test we verify that when value is being tracked we can update destination value in the
 * middle of ongoing animation and the animation will update and animate to the new spot. This is
 * tested using simple 5 frame backed timing animation.
 */
@Test
public void testTracking() {
  JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.25d, 0.5d, 0.75d, 1d);
  JavaOnlyMap animationConfig = JavaOnlyMap.of("type", "frames", "frames", frames);

  createAnimatedGraphWithTrackingNode(1000, 0d, animationConfig);

  ArgumentCaptor<ReactStylesDiffMap> stylesCaptor =
          ArgumentCaptor.forClass(ReactStylesDiffMap.class);

  reset(mUIImplementationMock);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verify(mUIImplementationMock).synchronouslyUpdateViewOnUIThread(eq(1000), stylesCaptor.capture());
  assertThat(stylesCaptor.getValue().getDouble("translateX", Double.NaN)).isEqualTo(0d);

  // update "toValue" to 100, we expect tracking animation to animate now from 0 to 100 in 5 steps
  mNativeAnimatedNodesManager.setAnimatedNodeValue(1, 100d);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); // kick off the animation

  for (int i = 0; i < frames.size(); i++) {
    reset(mUIImplementationMock);
    mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
    verify(mUIImplementationMock)
            .synchronouslyUpdateViewOnUIThread(eq(1000), stylesCaptor.capture());
    assertThat(stylesCaptor.getValue().getDouble("translateX", Double.NaN))
            .isEqualTo(frames.getDouble(i) * 100d);
  }

  // update "toValue" to 0 but run only two frames from the animation,
  // we expect tracking animation to animate now from 100 to 75
  mNativeAnimatedNodesManager.setAnimatedNodeValue(1, 0d);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); // kick off the animation

  for (int i = 0; i < 2; i++) {
    reset(mUIImplementationMock);
    mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
    verify(mUIImplementationMock)
            .synchronouslyUpdateViewOnUIThread(eq(1000), stylesCaptor.capture());
    assertThat(stylesCaptor.getValue().getDouble("translateX", Double.NaN))
            .isEqualTo(100d * (1d - frames.getDouble(i)));
  }

  // at this point we expect tracking value to be at 75
  assertThat(((ValueAnimatedNode) mNativeAnimatedNodesManager.getNodeById(3)).getValue())
          .isEqualTo(75d);

  // we update "toValue" again to 100 and expect the animation to restart from the current place
  mNativeAnimatedNodesManager.setAnimatedNodeValue(1, 100d);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); // kick off the animation

  for (int i = 0; i < frames.size(); i++) {
    reset(mUIImplementationMock);
    mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
    verify(mUIImplementationMock)
            .synchronouslyUpdateViewOnUIThread(eq(1000), stylesCaptor.capture());
    assertThat(stylesCaptor.getValue().getDouble("translateX", Double.NaN))
            .isEqualTo(50d + 50d * frames.getDouble(i));
  }
}
 
Example 10
Source File: NativeAnimatedNodeTraversalTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
/**
 * In this test we verify that when tracking is set up for a given animated node and when the
 * animation settles it will not be registered as an active animation and therefore will not
 * consume resources on running the animation that has already completed. Then we verify that when
 * the value updates the animation will resume as expected and the complete again when reaches the
 * end.
 */
@Test
public void testTrackingPausesWhenEndValueIsReached() {
  JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.5d, 1d);
  JavaOnlyMap animationConfig = JavaOnlyMap.of("type", "frames", "frames", frames);

  createAnimatedGraphWithTrackingNode(1000, 0d, animationConfig);
  mNativeAnimatedNodesManager.setAnimatedNodeValue(1, 100d);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); // make sure animation starts

  reset(mUIImplementationMock);
  for (int i = 0; i < frames.size(); i++) {
    assertThat(mNativeAnimatedNodesManager.hasActiveAnimations()).isTrue();
    mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  }
  verify(mUIImplementationMock, times(frames.size()))
          .synchronouslyUpdateViewOnUIThread(eq(1000), any(ReactStylesDiffMap.class));

  // the animation has completed, we expect no updates to be done
  reset(mUIImplementationMock);
  assertThat(mNativeAnimatedNodesManager.hasActiveAnimations()).isFalse();
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verifyNoMoreInteractions(mUIImplementationMock);


  // we update end value and expect the animation to restart
  mNativeAnimatedNodesManager.setAnimatedNodeValue(1, 200d);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime()); // make sure animation starts

  reset(mUIImplementationMock);
  for (int i = 0; i < frames.size(); i++) {
    assertThat(mNativeAnimatedNodesManager.hasActiveAnimations()).isTrue();
    mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  }
  verify(mUIImplementationMock, times(frames.size()))
          .synchronouslyUpdateViewOnUIThread(eq(1000), any(ReactStylesDiffMap.class));

  // the animation has completed, we expect no updates to be done
  reset(mUIImplementationMock);
  assertThat(mNativeAnimatedNodesManager.hasActiveAnimations()).isFalse();
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verifyNoMoreInteractions(mUIImplementationMock);
}