Java Code Examples for com.facebook.react.ReactRootView
The following examples show how to use
com.facebook.react.ReactRootView. 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: imsdk-android Source File: QtalkServiceExternalRNActivity.java License: MIT License | 6 votes |
private void bindView() { try { qtNewActionBar = (QtNewActionBar) this.findViewById(R.id.my_action_bar); setNewActionBar(qtNewActionBar); boolean isShow = Boolean.parseBoolean(getIntent().getStringExtra("showNativeNav")); if (isShow) { String title = getIntent().getStringExtra("navTitle"); setActionBarTitle(title); setActionBarVisibility(true); } else { setActionBarVisibility(false); } // mReactRootView = new ReactRootView(this); mReactRootView = (ReactRootView) findViewById(R.id.mReactRootView); startRNApplicationWithBundle(getExtendBundle()); // setContentView(mReactRootView); }catch (Exception e){ Logger.i("打开外部RN应用出现不可预知错误:"+e.getMessage()); } }
Example 2
Source Project: react-native-custom-keyboard-kit Source File: RNCustomKeyboardKitModule.java License: MIT License | 6 votes |
private View createCustomKeyboardKit(Activity activity, int tag, String type) { RelativeLayout layout = new RelativeLayout(activity); rootView = new ReactRootView(this.getReactApplicationContext()); rootView.setBackgroundColor(Color.WHITE); Bundle bundle = new Bundle(); bundle.putInt("tag", tag); bundle.putString("type", type); rootView.startReactApplication( ((ReactApplication) activity.getApplication()).getReactNativeHost().getReactInstanceManager(), "CustomKeyboardKit", bundle); final float scale = activity.getResources().getDisplayMetrics().density; RelativeLayout.LayoutParams lParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Math.round(216*scale)); lParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); layout.addView(rootView, lParams); // activity.addContentView(layout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); return layout; }
Example 3
Source Project: react-native-GPay Source File: ReactRootViewTestCase.java License: MIT License | 6 votes |
@Ignore("t6596940: fix intermittently failing test") public void testResizeRootView() throws Throwable { final ReactRootView rootView = (ReactRootView) getRootView(); final View childView = rootView.getChildAt(0); assertEquals(rootView.getWidth(), childView.getWidth()); final int newWidth = rootView.getWidth() / 2; runTestOnUiThread( new Runnable() { @Override public void run() { rootView.setLayoutParams(new FrameLayout.LayoutParams( newWidth, ViewGroup.LayoutParams.MATCH_PARENT)); } }); getInstrumentation().waitForIdleSync(); waitForBridgeAndUIIdle(); assertEquals(newWidth, childView.getWidth()); }
Example 4
Source Project: react-native-GPay Source File: CatalystUIManagerTestCase.java License: MIT License | 6 votes |
public void _testCenteredText(String text) { ReactRootView rootView = new ReactRootView(getContext()); int rootTag = uiManager.addRootView(rootView); jsModule.renderCenteredTextViewTestApplication(rootTag, text); waitForBridgeAndUIIdle(); TextView textView = getViewByTestId(rootView, "text"); // text view should be centered String msg = "text `" + text + "` is not centered"; assertTrue(msg, textView.getLeft() > 0.1); assertTrue(msg, textView.getTop() > 0.1); assertEquals( msg, (int) Math.ceil((inPixelRounded(200) - textView.getWidth()) * 0.5f), textView.getLeft()); assertEquals( msg, (int) Math.ceil((inPixelRounded(100) - textView.getHeight()) * 0.5f), textView.getTop()); }
Example 5
Source Project: react-native-GPay Source File: ReactAppTestActivity.java License: MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); overridePendingTransition(0, 0); // We wrap screenshot layout in another FrameLayout in order to handle custom dimensions of the // screenshot view set through {@link #setScreenshotDimensions} FrameLayout rootView = new FrameLayout(this); setContentView(rootView); mScreenshotingFrameLayout = new ScreenshotingFrameLayout(this); mScreenshotingFrameLayout.setId(ROOT_VIEW_ID); rootView.addView(mScreenshotingFrameLayout); mReactRootView = new ReactRootView(this); Intent intent = getIntent(); if (intent != null && intent.getBooleanExtra(EXTRA_IS_FABRIC_TEST, false)) { mReactRootView.setIsFabric(true); } mScreenshotingFrameLayout.addView(mReactRootView); }
Example 6
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 7
Source Project: react-native-GPay Source File: ReactTextTest.java License: MIT License | 6 votes |
@Test public void testTextDecorationLineUnderlineApplied() { UIManagerModule uiManager = getUIManagerModule(); ReactRootView rootView = createText( uiManager, JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline"), JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text")); TextView textView = (TextView) rootView.getChildAt(0); Spanned text = (Spanned) textView.getText(); UnderlineSpan underlineSpan = getSingleSpan(textView, UnderlineSpan.class); StrikethroughSpan[] strikeThroughSpans = text.getSpans(0, text.length(), StrikethroughSpan.class); assertThat(underlineSpan instanceof UnderlineSpan).isTrue(); assertThat(strikeThroughSpans).hasSize(0); }
Example 8
Source Project: react-native-GPay Source File: ReactTextTest.java License: MIT License | 6 votes |
@Test public void testTextDecorationLineLineThroughApplied() { UIManagerModule uiManager = getUIManagerModule(); ReactRootView rootView = createText( uiManager, JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "line-through"), JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text")); TextView textView = (TextView) rootView.getChildAt(0); Spanned text = (Spanned) textView.getText(); UnderlineSpan[] underlineSpans = text.getSpans(0, text.length(), UnderlineSpan.class); StrikethroughSpan strikeThroughSpan = getSingleSpan(textView, StrikethroughSpan.class); assertThat(underlineSpans).hasSize(0); assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue(); }
Example 9
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 10
Source Project: react-native-GPay Source File: FabricUIManagerTest.java License: MIT License | 6 votes |
@Test public void testSealReactShadowNode() { ReactRootView rootView = new ReactRootView(RuntimeEnvironment.application.getApplicationContext()); int rootTag = mFabricUIManager.addRootView(rootView); String viewClass = ReactViewManager.REACT_CLASS; ReactShadowNode container = mFabricUIManager.createNode(6, viewClass, rootTag, null, randomInstanceHandle()); List<ReactShadowNode> childSet = mFabricUIManager.createChildSet(rootTag); mFabricUIManager.appendChildToSet(childSet, container); assertThat(container.isSealed()).isFalse(); mFabricUIManager.completeRoot(rootTag, childSet); assertThat(container.isSealed()).isTrue(); }
Example 11
Source Project: react-native-GPay Source File: FabricUIManagerTest.java License: MIT License | 6 votes |
/** * Tests that cloned text nodes will not share measure functions */ @Test public void testTextMutableClone() { ReactRootView rootView = new ReactRootView(RuntimeEnvironment.application.getApplicationContext()); int rootTag = mFabricUIManager.addRootView(rootView); ReactShadowNode text = mFabricUIManager.createNode(0, ReactTextViewManager.REACT_CLASS, rootTag, null, randomInstanceHandle()); assertThat(text.isMeasureDefined()).isTrue(); ReactShadowNode textCopy = text.mutableCopy(randomInstanceHandle()); assertThat(textCopy.isMeasureDefined()).isTrue(); textCopy.setStyleWidth(200); text.onBeforeLayout(); text.calculateLayout(); textCopy.onBeforeLayout(); textCopy.calculateLayout(); assertThat(text.getLayoutWidth()).isNotEqualTo(textCopy.getLayoutWidth()); }
Example 12
Source Project: native-navigation Source File: ReactNativeIntents.java License: MIT License | 6 votes |
static Bundle getSharedElementOptionsBundle( Activity activity, Intent intent, @Nullable ReadableMap options) { ViewGroup transitionGroup = null; if (activity instanceof ReactInterface && options != null && options.hasKey(SHARED_ELEMENT_TRANSITION_GROUP_OPTION)) { ReactRootView reactRootView = ((ReactInterface) activity).getReactRootView(); transitionGroup = ViewUtils.findViewGroupWithTag( reactRootView, R.id.react_shared_element_group_id, options.getString(SHARED_ELEMENT_TRANSITION_GROUP_OPTION)); } if (transitionGroup == null) { // Even though there is no transition group, we want the activity options to include a scene // transition so that we can postpone the enter transition. //noinspection unchecked return ActivityOptionsCompat.makeSceneTransitionAnimation(activity).toBundle(); } else { ReactNativeUtils.setIsSharedElementTransition(intent); return AutoSharedElementCallback.getActivityOptionsBundle(activity, transitionGroup); } }
Example 13
Source Project: react-native-android-audio-streaming-aac Source File: MainActivity.java License: MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mReactRootView = new ReactRootView(this); mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setBundleAssetName("index.android.bundle") .setJSMainModuleName("index.android") .addPackage(new MainReactPackage()) .addPackage(new AACStreamingPackage(MainActivity.class)) // <------- add package .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build(); mReactRootView.startReactApplication(mReactInstanceManager, "example", null); setContentView(mReactRootView); }
Example 14
Source Project: rn-camera-roll Source File: MainActivity.java License: MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mReactRootView = new ReactRootView(this); mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setBundleAssetName("index.android.bundle") .setJSMainModuleName("index.android") .addPackage(new MainReactPackage()) // Add Camera Roll for android .addPackage(new CameraRollPackage()) .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build(); mReactRootView.startReactApplication(mReactInstanceManager, "example", null); setContentView(mReactRootView); }
Example 15
Source Project: dingo Source File: MainActivity.java License: GNU General Public License v3.0 | 5 votes |
@Override protected ReactActivityDelegate createReactActivityDelegate() { return new ReactActivityDelegate(this, getMainComponentName()) { @Override protected ReactRootView createRootView() { return new RNGestureHandlerEnabledRootView(MainActivity.this); } }; }
Example 16
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 17
Source Project: react-native-image-filter-kit Source File: MainActivity.java License: MIT License | 5 votes |
@Override protected ReactActivityDelegate createReactActivityDelegate() { return new ReactActivityDelegate(this, getMainComponentName()) { @Override protected ReactRootView createRootView() { return new RNGestureHandlerEnabledRootView(MainActivity.this); } }; }
Example 18
Source Project: react-native-callkeep Source File: MainActivity.java License: ISC License | 5 votes |
@Override protected ReactActivityDelegate createReactActivityDelegate() { return new ReactActivityDelegate(this, getMainComponentName()) { @Override protected ReactRootView createRootView() { return new RNGestureHandlerEnabledRootView(MainActivity.this); } }; }
Example 19
Source Project: imsdk-android Source File: RNFoundFragment.java License: MIT License | 5 votes |
@Override public void onAttach(Context context) { super.onAttach(context); mReactRootView = new ReactRootView(context); activity = getActivity(); mReactInstanceManager = QtalkServiceRNViewInstanceManager.getInstanceManager(activity); }
Example 20
Source Project: imsdk-android Source File: RNMineFragment.java License: MIT License | 5 votes |
@Override public void onAttach(Context context) { super.onAttach(context); mReactRootView = new ReactRootView(context); activity = getActivity(); mReactInstanceManager = QtalkServiceRNViewInstanceManager.getInstanceManager(activity); }
Example 21
Source Project: imsdk-android Source File: QtalkServiceRNActivity.java License: MIT License | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mReactRootView = new ReactRootView(this); addEvent(); startRNApplicationWithBundle(getExtendBundle()); setContentView(mReactRootView); }
Example 22
Source Project: react-native-aztec Source File: MyFragment.java License: GNU General Public License v2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (mReactInstanceManager == null) { try { mReactInstanceManager = ((SampleRNBaseActivity) getActivity()).getReactInstanceManager(); } catch (ClassCastException e) { throw new ClassCastException(getActivity().toString() + " must extends SampleRNBaseActivity"); } } ReactRootView reactRootView = new ReactRootView(getContext()); reactRootView.startReactApplication(mReactInstanceManager, "example", null); return reactRootView; }
Example 23
Source Project: react-native-GPay 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 24
Source Project: react-native-GPay Source File: ViewRenderingTestCase.java License: MIT License | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); List<ViewManager> viewManagers = Arrays.<ViewManager>asList(new ReactViewManager()); final UIManagerModule uiManager = new UIManagerModule(getContext(), viewManagers, 0); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { uiManager.onHostResume(); } }); waitForIdleSync(); mCatalystInstance = ReactTestHelper.catalystInstanceBuilder(this) .addNativeModule(uiManager) .addNativeModule(new AndroidInfoModule(getContext())) .addNativeModule(new DeviceInfoModule(getContext())) .addNativeModule(new AppStateModule(getContext())) .addNativeModule(new FakeWebSocketModule()) .build(); mRootView = new ReactRootView(getContext()); mRootTag = uiManager.addRootView(mRootView); }
Example 25
Source Project: react-native-GPay Source File: ReactRootViewTestCase.java License: MIT License | 5 votes |
/** * Verify that removing the root view from hierarchy will trigger subviews removal both on JS and * native side */ public void testRemoveRootView() throws Throwable { final ReactRootView rootView = (ReactRootView) getRootView(); assertEquals(1, rootView.getChildCount()); runTestOnUiThread( new Runnable() { @Override public void run() { ViewGroup parent = (ViewGroup) rootView.getParent(); parent.removeView(rootView); // removing from parent should not remove child views, child views should be removed as // an effect of native call to UIManager.removeRootView assertEquals(1, rootView.getChildCount()); } }); getInstrumentation().waitForIdleSync(); waitForBridgeAndUIIdle(); assertEquals("root component should not be automatically unmounted", 0, mRecordingModule.getCalls().size()); assertEquals(1, rootView.getChildCount()); runTestOnUiThread( new Runnable() { @Override public void run() { rootView.unmountReactApplication(); } }); waitForBridgeAndUIIdle(); assertEquals(1, mRecordingModule.getCalls().size()); assertEquals("RootComponentWillUnmount", mRecordingModule.getCalls().get(0)); assertEquals(0, rootView.getChildCount()); }
Example 26
Source Project: react-native-GPay Source File: CatalystUIManagerTestCase.java License: MIT License | 5 votes |
private ReactRootView createRootView() { ReactRootView rootView = new ReactRootView(getContext()); final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); rootView.setLayoutParams( new FrameLayout.LayoutParams(metrics.widthPixels, metrics.heightPixels)); uiManager.addRootView(rootView); // We add the root view by posting to the main thread so wait for that to complete so that the // root view tag is added to the view waitForIdleSync(); return rootView; }
Example 27
Source Project: react-native-GPay Source File: TextInputTest.java License: MIT License | 5 votes |
@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 28
Source Project: react-native-GPay Source File: ReactTextTest.java License: MIT License | 5 votes |
@Test public void testFontSizeApplied() { UIManagerModule uiManager = getUIManagerModule(); ReactRootView rootView = createText( uiManager, JavaOnlyMap.of(ViewProps.FONT_SIZE, 21.0), JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text")); AbsoluteSizeSpan sizeSpan = getSingleSpan( (TextView) rootView.getChildAt(0), AbsoluteSizeSpan.class); assertThat(sizeSpan.getSize()).isEqualTo(21); }
Example 29
Source Project: react-native-GPay Source File: ReactTextTest.java License: MIT License | 5 votes |
@Test public void testBoldFontApplied() { UIManagerModule uiManager = getUIManagerModule(); ReactRootView rootView = createText( uiManager, JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "bold"), JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text")); CustomStyleSpan customStyleSpan = getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class); assertThat(customStyleSpan.getWeight() & Typeface.BOLD).isNotZero(); assertThat(customStyleSpan.getStyle() & Typeface.ITALIC).isZero(); }
Example 30
Source Project: react-native-GPay Source File: ReactTextTest.java License: MIT License | 5 votes |
@Test public void testNumericBoldFontApplied() { UIManagerModule uiManager = getUIManagerModule(); ReactRootView rootView = createText( uiManager, JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "500"), JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text")); CustomStyleSpan customStyleSpan = getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class); assertThat(customStyleSpan.getWeight() & Typeface.BOLD).isNotZero(); assertThat(customStyleSpan.getStyle() & Typeface.ITALIC).isZero(); }