Java Code Examples for com.facebook.react.uimanager.UIManagerModule
The following examples show how to use
com.facebook.react.uimanager.UIManagerModule. These examples are extracted from open source projects.
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 Project: react-native-jw-media-player Source File: RNJWPlayerModule.java License: MIT License | 6 votes |
@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 Project: react-native-jw-media-player Source File: RNJWPlayerModule.java License: MIT License | 6 votes |
@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 3
Source Project: react-native-jw-media-player Source File: RNJWPlayerModule.java License: MIT License | 6 votes |
@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 4
Source Project: react-native-jw-media-player Source File: RNJWPlayerModule.java License: MIT License | 6 votes |
@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 5
Source Project: react-native-jw-media-player Source File: RNJWPlayerModule.java License: MIT License | 6 votes |
@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 6
Source Project: react-native-jw-media-player Source File: RNJWPlayerModule.java License: MIT License | 6 votes |
@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 7
Source Project: react-native-jw-media-player Source File: RNJWPlayerModule.java License: MIT License | 6 votes |
@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 8
Source Project: react-native-GPay Source File: ReactTextTest.java License: MIT License | 6 votes |
@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 9
Source Project: react-native-jw-media-player Source File: RNJWPlayerModule.java License: MIT License | 6 votes |
@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 10
Source Project: react-native-GPay Source File: ReactTextTest.java License: MIT License | 6 votes |
@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 11
Source Project: react-native-directed-scrollview Source File: DirectedScrollView.java License: MIT License | 6 votes |
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 12
Source Project: Instabug-React-Native Source File: RNInstabugReactnativeModule.java License: MIT License | 6 votes |
@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 13
Source Project: react-native-screens Source File: Screen.java License: MIT License | 6 votes |
@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 14
Source Project: react-native-text-gradient Source File: RNShadowTextGradient.java License: MIT License | 6 votes |
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 15
Source Project: react-native-custom-keyboard-kit Source File: RNCustomKeyboardKitModule.java License: MIT License | 6 votes |
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 16
Source Project: react-native-youtube Source File: YouTubeModule.java License: MIT License | 6 votes |
@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 17
Source Project: react-native-GPay Source File: ReactModalHostView.java License: MIT License | 6 votes |
@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 18
Source Project: react-native-GPay Source File: ReactRootView.java License: MIT License | 6 votes |
@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 19
Source Project: react-native-GPay Source File: ReactRootView.java License: MIT License | 6 votes |
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 20
Source Project: react-native-youtube Source File: YouTubeModule.java License: MIT License | 6 votes |
@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 21
Source Project: ReactNativeDropdownAndroid Source File: Dropdown.java License: MIT License | 6 votes |
@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 22
Source Project: react-native-GPay Source File: CatalystNativeJavaToJSReturnValuesTestCase.java License: MIT License | 6 votes |
@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 23
Source Project: react-native-youtube Source File: YouTubeModule.java License: MIT License | 6 votes |
@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 24
Source Project: react-native-GPay Source File: ReactTextTest.java License: MIT License | 5 votes |
@Test public void testTextTransformLowercaseApplied() { UIManagerModule uiManager = getUIManagerModule(); String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd "; String testTextTransformed = ".aa\tbb\t\tcc dd ee \r\nzz i like to eat apples. \n中文éé 我喜欢吃苹果。awdawd "; ReactRootView rootView = createText( uiManager, JavaOnlyMap.of("textTransform", "lowercase"), JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered)); TextView textView = (TextView) rootView.getChildAt(0); assertThat(textView.getText().toString()).isEqualTo(testTextTransformed); }
Example 25
Source Project: progress-bar-android Source File: ProgressBarTestCase.java License: MIT License | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); List<ViewManager> viewManagers = Arrays.<ViewManager>asList( new ReactViewManager(), new ReactProgressBarViewManager()); mUIManager = new UIManagerModule(getContext(), viewManagers, 0); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { mUIManager.onHostResume(); } }); waitForIdleSync(); mInstance = ReactTestHelper.catalystInstanceBuilder(this) .addNativeModule(mUIManager) .addNativeModule(new AndroidInfoModule(getContext())) .addNativeModule(new DeviceInfoModule(getContext())) .addNativeModule(new AppStateModule(getContext())) .addNativeModule(new FakeWebSocketModule()) .build(); mRootView = new ReactRootView(getContext()); DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); mRootView.setLayoutParams( new FrameLayout.LayoutParams(metrics.widthPixels, metrics.heightPixels)); int rootTag = mUIManager.addRootView(mRootView); mInstance.getJSModule(ProgressBarTestModule.class).renderProgressBarApplication(rootTag); waitForBridgeAndUIIdle(); }
Example 26
Source Project: react-native-youtube-sdk Source File: YouTubeSdkModule.java License: Apache License 2.0 | 5 votes |
@ReactMethod public void getCurrentTime(final int reactTag, final Promise promise) { try { UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class); uiManager.addUIBlock(nvhm -> { YouTubeView youTubeView = (YouTubeView) nvhm.resolveView(reactTag); promise.resolve(youTubeView.getYouTubePlayerProps().getTracker().getCurrentSecond()); }); } catch (Exception e) { promise.reject("getCurrentTime", e); } }
Example 27
Source Project: react-native-GPay Source File: ReactTextTest.java License: MIT License | 5 votes |
private ReactRootView createText( UIManagerModule uiManager, JavaOnlyMap textProps, JavaOnlyMap rawTextProps) { ReactRootView rootView = new ReactRootView(RuntimeEnvironment.application); int rootTag = uiManager.addRootView(rootView); int textTag = rootTag + 1; int rawTextTag = textTag + 1; uiManager.createView( textTag, ReactTextViewManager.REACT_CLASS, rootTag, textProps); uiManager.createView( rawTextTag, ReactRawTextManager.REACT_CLASS, rootTag, rawTextProps); uiManager.manageChildren( textTag, null, null, JavaOnlyArray.of(rawTextTag), JavaOnlyArray.of(0), null); uiManager.manageChildren( rootTag, null, null, JavaOnlyArray.of(textTag), JavaOnlyArray.of(0), null); uiManager.onBatchComplete(); executePendingFrameCallbacks(); return rootView; }
Example 28
Source Project: react-native-GPay Source File: ReactTextTest.java License: MIT License | 5 votes |
@Test public void testFontFamilyStyleApplied() { UIManagerModule uiManager = getUIManagerModule(); ReactRootView rootView = createText( uiManager, JavaOnlyMap.of(ViewProps.FONT_FAMILY, "sans-serif"), 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).isZero(); assertThat(customStyleSpan.getWeight() & Typeface.BOLD).isZero(); }
Example 29
Source Project: react-native-aztec Source File: ReactAztecManager.java License: GNU General Public License v2.0 | 5 votes |
@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 30
Source Project: react-native-GPay Source File: ReactTextTest.java License: MIT License | 5 votes |
@Test public void testTextTransformNoneApplied() { UIManagerModule uiManager = getUIManagerModule(); String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd "; String testTextTransformed = testTextEntered; ReactRootView rootView = createText( uiManager, JavaOnlyMap.of("textTransform", "none"), JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered)); TextView textView = (TextView) rootView.getChildAt(0); assertThat(textView.getText().toString()).isEqualTo(testTextTransformed); }