com.facebook.react.uimanager.UIManagerModule Java Examples

The following examples show how to use com.facebook.react.uimanager.UIManagerModule. 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: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 7 votes vote down vote up
@ReactMethod
public void play(final int reactTag) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.play();
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example #2
Source File: Dropdown.java    From ReactNativeDropdownAndroid with MIT License 6 votes vote down vote up
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
    selected = pos;
    // It always fire this event when the component starts, thus we need to surpress
    // the first event
    if (!firstEventFired) {
        firstEventFired = true;
        return;
    }
    ReactContext reactContext = (ReactContext) view.getContext();
    reactContext
            .getNativeModule(UIManagerModule.class)
            .getEventDispatcher().dispatchEvent(
                new DropdownEvent(
                    getId(),
                    SystemClock.uptimeMillis(),
                    pos,
                    parent.getSelectedItem().toString()));
}
 
Example #3
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void state(final int reactTag, final Promise promise) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          PlayerState playerState = playerView.mPlayer.getState();
          promise.resolve(stateToInt(playerState));
        } else {
          promise.reject("RNJW Error", "Player is null");
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    promise.reject("RNJW Error", e);
  }
}
 
Example #4
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void seekTo(final int reactTag, final double time) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.seek(time);
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example #5
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void setPlaylistIndex(final int reactTag, final int index) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.setCurrentAudioTrack(index);
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example #6
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void stop(final int reactTag) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.stop();
          playerView.userPaused = true;
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example #7
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void pause(final int reactTag) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.pause();
          playerView.userPaused = true;
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example #8
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void setSpeed(final int reactTag, final float speed) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.setPlaybackRate(speed);
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example #9
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void toggleSpeed(final int reactTag) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          float rate = playerView.mPlayer.getPlaybackRate();
          if (rate < 2) {
            playerView.mPlayer.setPlaybackRate(rate += 0.5);
          } else {
            playerView.mPlayer.setPlaybackRate((float) 0.5);
          }
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example #10
Source File: YouTubeModule.java    From react-native-youtube with MIT License 6 votes vote down vote up
@ReactMethod
public void getCurrentTime(final int reactTag, final Promise promise) {
    try {
        UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
        uiManager.addUIBlock(new UIBlock() {
            public void execute (NativeViewHierarchyManager nvhm) {
                YouTubeView youTubeView = (YouTubeView) nvhm.resolveView(reactTag);
                YouTubeManager youTubeManager = (YouTubeManager) nvhm.resolveViewManager(reactTag);
                int currentTime = youTubeManager.getCurrentTime(youTubeView);
                promise.resolve(currentTime);
            }
        });
    } catch (IllegalViewOperationException e) {
        promise.reject(E_MODULE_ERROR, e);
    }
}
 
Example #11
Source File: ReactTextTest.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineLineThroughApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline line-through"),
      JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));

  UnderlineSpan underlineSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), UnderlineSpan.class);
  StrikethroughSpan strikeThroughSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), StrikethroughSpan.class);
  assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
  assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
}
 
Example #12
Source File: ReactTextTest.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Test
public void testFontFamilyBoldItalicStyleApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(
          ViewProps.FONT_FAMILY, "sans-serif",
          ViewProps.FONT_WEIGHT, "500",
          ViewProps.FONT_STYLE, "italic"),
      JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));

  CustomStyleSpan customStyleSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
  assertThat(customStyleSpan.getFontFamily()).isEqualTo("sans-serif");
  assertThat(customStyleSpan.getStyle() & Typeface.ITALIC).isNotZero();
  assertThat(customStyleSpan.getWeight() & Typeface.BOLD).isNotZero();
}
 
Example #13
Source File: RNInstabugReactnativeModule.java    From Instabug-React-Native with MIT License 6 votes vote down vote up
@ReactMethod
public void hideView(final ReadableArray ids) {
    MainThreadHandler.runOnMainThread(new Runnable() {
        @Override
        public void run() {
            UIManagerModule uiManagerModule = getReactApplicationContext().getNativeModule(UIManagerModule.class);
            uiManagerModule.prependUIBlock(new UIBlock() {
                @Override
                public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
                    final View[] arrayOfViews = new View[ids.size()];
                    for (int i = 0; i < ids.size(); i++) {
                        int viewId = (int) ids.getDouble(i);
                        try {
                            arrayOfViews[i] = nativeViewHierarchyManager.resolveView(viewId);
                        } catch(Exception e) {
                            e.printStackTrace();
                        }
                    }
                    Instabug.setViewsAsPrivate(arrayOfViews);
                }
            });
        }
    });
}
 
Example #14
Source File: Screen.java    From react-native-screens with MIT License 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
  if (changed) {
    final int width = r - l;
    final int height = b - t;
    final ReactContext reactContext = (ReactContext) getContext();
    reactContext.runOnNativeModulesQueueThread(
            new GuardedRunnable(reactContext) {
              @Override
              public void runGuarded() {
                reactContext.getNativeModule(UIManagerModule.class)
                        .updateNodeSize(getId(), width, height);
              }
            });
  }
}
 
Example #15
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 #16
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 #17
Source File: YouTubeModule.java    From react-native-youtube with MIT License 6 votes vote down vote up
@ReactMethod
public void getVideosIndex(final int reactTag, final Promise promise) {
    try {
        UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
        uiManager.addUIBlock(new UIBlock() {
            public void execute (NativeViewHierarchyManager nvhm) {
                YouTubeView youTubeView = (YouTubeView) nvhm.resolveView(reactTag);
                YouTubeManager youTubeManager = (YouTubeManager) nvhm.resolveViewManager(reactTag);
                int index = youTubeManager.getVideosIndex(youTubeView);
                promise.resolve(index);
            }
        });
    } catch (IllegalViewOperationException e) {
        promise.reject(E_MODULE_ERROR, e);
    }
}
 
Example #18
Source File: CatalystNativeJavaToJSReturnValuesTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();

  final UIManagerModule mUIManager =
      new UIManagerModule(
          getContext(), new ArrayList<ViewManager>(), 0);

  mAssertModule = new AssertModule();

  mInstance = ReactTestHelper.catalystInstanceBuilder(this)
      .addNativeModule(mAssertModule)
      .addNativeModule(new DeviceInfoModule(getContext()))
      .addNativeModule(new AppStateModule(getContext()))
      .addNativeModule(new FakeWebSocketModule())
      .addNativeModule(mUIManager)
      .addNativeModule(new TestModule())
      .build();
}
 
Example #19
Source File: YouTubeModule.java    From react-native-youtube with MIT License 6 votes vote down vote up
@ReactMethod
public void getDuration(final int reactTag, final Promise promise) {
    try {
        UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
        uiManager.addUIBlock(new UIBlock() {
            public void execute (NativeViewHierarchyManager nvhm) {
                YouTubeView youTubeView = (YouTubeView) nvhm.resolveView(reactTag);
                YouTubeManager youTubeManager = (YouTubeManager) nvhm.resolveViewManager(reactTag);
                int duration = youTubeManager.getDuration(youTubeView);
                promise.resolve(duration);
            }
        });
    } catch (IllegalViewOperationException e) {
        promise.reject(E_MODULE_ERROR, e);
    }
}
 
Example #20
Source File: DirectedScrollView.java    From react-native-directed-scrollview with MIT License 6 votes vote down vote up
private void emitScrollEvent(
  ScrollEventType scrollEventType,
  float xVelocity,
  float yVelocity) {
  reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
    ScrollEvent.obtain(
      getId(),
      scrollEventType,
      Math.round(scrollX * -1),
      Math.round(scrollY * -1),
      xVelocity,
      yVelocity,
      Math.round(getContentContainerWidth()),
      Math.round(getContentContainerHeight()),
      getWidth(),
      getHeight()));
}
 
Example #21
Source File: RNShadowTextGradient.java    From react-native-text-gradient with MIT License 6 votes vote down vote up
private @Nullable View resolveView(int tag) {
  UiThreadUtil.assertOnUiThread();
  ReactApplicationContext context = mContext.get();

  if (context != null) {
    UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);

    NativeViewHierarchyManager manager = ReflectUtils.getFieldValue(
      ReflectUtils.getFieldValue(
        uiManager.getUIImplementation(),
        "mOperationsQueue",
        null
      ),
      "mNativeViewHierarchyManager",
      null
    );

    if (manager != null) {
      return manager.resolveView(tag);
    }
  }

  return null;
}
 
Example #22
Source File: ReactModalHostView.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
protected void onSizeChanged(final int w, final int h, int oldw, int oldh) {
  super.onSizeChanged(w, h, oldw, oldh);
  if (getChildCount() > 0) {
    final int viewTag = getChildAt(0).getId();
    ReactContext reactContext = getReactContext();
    reactContext.runOnNativeModulesQueueThread(
      new GuardedRunnable(reactContext) {
        @Override
        public void runGuarded() {
          (getReactContext()).getNativeModule(UIManagerModule.class)
            .updateNodeSize(viewTag, w, h);
        }
      });
  }
}
 
Example #23
Source File: RNCustomKeyboardKitModule.java    From react-native-custom-keyboard-kit with MIT License 6 votes vote down vote up
private ReactEditText getEditById(int id) {
  // UIViewOperationQueue uii = this.getReactApplicationContext().getNativeModule(UIManagerModule.class).getUIImplementation().getUIViewOperationQueue();
  // return (ReactEditText) uii.getNativeViewHierarchyManager().resolveView(id);

  UIViewOperationQueue uii = null;
  ReactEditText edit = null;

  while (edit == null) {
    uii = this.getReactApplicationContext().getNativeModule(UIManagerModule.class).getUIImplementation().getUIViewOperationQueue();

    try {
      edit = (ReactEditText) uii.getNativeViewHierarchyManager().resolveView(id);
    } catch (IllegalViewOperationException e) {

    }
  }

  return edit;
}
 
Example #24
Source File: ReactViewPager.java    From react-native-GPay with MIT License 5 votes vote down vote up
public ReactViewPager(ReactContext reactContext) {
  super(reactContext);
  mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
  mIsCurrentItemFromJs = false;
  setOnPageChangeListener(new PageChangeListener());
  setAdapter(new Adapter());
}
 
Example #25
Source File: RCTCaptureManager.java    From react-native-smart-barcode with MIT License 5 votes vote down vote up
@Override
protected void addEventEmitters(
        final ThemedReactContext reactContext,
        final CaptureView view) {
    view.setOnEvChangeListener(
            new CaptureView.OnEvChangeListener() {
                @Override
                public void getQRCodeResult(String result,BarcodeFormat format) {
                    reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()
                            .dispatchEvent(new QRCodeResultEvent(view.getId(), SystemClock.nanoTime(), result,format));
                }

            });
}
 
Example #26
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 #27
Source File: NativeAnimatedModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public void initialize() {
  ReactApplicationContext reactCtx = getReactApplicationContext();
  UIManagerModule uiManager = reactCtx.getNativeModule(UIManagerModule.class);
  reactCtx.addLifecycleEventListener(this);
  uiManager.addUIManagerListener(this);
}
 
Example #28
Source File: TextInputTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Test
public void testPropsApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = new ReactRootView(RuntimeEnvironment.application);
  rootView.setLayoutParams(new ReactRootView.LayoutParams(100, 100));
  int rootTag = uiManager.addRootView(rootView);
  int textInputTag = rootTag + 1;
  final String hintStr = "placeholder text";

  uiManager.createView(
      textInputTag,
      ReactTextInputManager.REACT_CLASS,
      rootTag,
      JavaOnlyMap.of(
          ViewProps.FONT_SIZE, 13.37, ViewProps.HEIGHT, 20.0, "placeholder", hintStr));

  uiManager.manageChildren(
      rootTag,
      null,
      null,
      JavaOnlyArray.of(textInputTag),
      JavaOnlyArray.of(0),
      null);

  uiManager.onBatchComplete();
  executePendingChoreographerCallbacks();

  EditText editText = (EditText) rootView.getChildAt(0);
  assertThat(editText.getHint()).isEqualTo(hintStr);
  assertThat(editText.getTextSize()).isEqualTo((float) Math.ceil(13.37));
  assertThat(editText.getHeight()).isEqualTo(20);
}
 
Example #29
Source File: NativeAnimatedModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
private NativeAnimatedNodesManager getNodesManager() {
  if (mNodesManager == null) {
    UIManagerModule uiManager = getReactApplicationContext().getNativeModule(UIManagerModule.class);
    mNodesManager = new NativeAnimatedNodesManager(uiManager);
  }

  return mNodesManager;
}
 
Example #30
Source File: CoreModulesPackage.java    From react-native-GPay with MIT License 5 votes vote down vote up
private UIManagerModule createUIManager(final ReactApplicationContext reactContext) {
  ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_START);
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createUIManagerModule");
  try {
    if (mLazyViewManagersEnabled) {
      UIManagerModule.ViewManagerResolver resolver = new UIManagerModule.ViewManagerResolver() {
        @Override
        public @Nullable ViewManager getViewManager(String viewManagerName) {
          return mReactInstanceManager.createViewManager(viewManagerName);
        }
        @Override
        public List<String> getViewManagerNames() {
          return mReactInstanceManager.getViewManagerNames();
        }
      };

      return new UIManagerModule(
          reactContext,
          resolver,
          mMinTimeLeftInFrameForNonBatchedOperationMs);
    } else {
      return new UIManagerModule(
          reactContext,
          mReactInstanceManager.getOrCreateViewManagers(reactContext),
          mMinTimeLeftInFrameForNonBatchedOperationMs);
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END);
  }
}