Java Code Examples for com.facebook.react.ReactApplication
The following examples show how to use
com.facebook.react.ReactApplication. 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-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 2
Source Project: react-native-restart Source File: RestartModule.java License: MIT License | 6 votes |
private ReactInstanceManager resolveInstanceManager() throws NoSuchFieldException, IllegalAccessException { ReactInstanceManager instanceManager = getReactInstanceManager(); if (instanceManager != null) { return instanceManager; } final Activity currentActivity = getCurrentActivity(); if (currentActivity == null) { return null; } ReactApplication reactApplication = (ReactApplication) currentActivity.getApplication(); instanceManager = reactApplication.getReactNativeHost().getReactInstanceManager(); return instanceManager; }
Example 3
Source Project: react-native-workers Source File: RNWorkersManager.java License: Apache License 2.0 | 5 votes |
public <T extends Application & ReactApplication> void init(final T reactApp, final RNWorker... workers) { mMainHost = reactApp.getReactNativeHost(); mRNWorkers = new ArrayList<>(); if (workers != null && workers.length > 0) { mRNWorkers.addAll(Arrays.asList(workers)); } mMainHost.getReactInstanceManager().addReactInstanceEventListener(mMainHostListener); reactApp.registerActivityLifecycleCallbacks(mLifecycleCallbacks); }
Example 4
Source Project: react-native-workers Source File: RNWorker.java License: Apache License 2.0 | 5 votes |
public static <T extends Application & ReactApplication> RNWorker createDefault( final T application, final boolean developerSupport) { return new Builder(application, developerSupport) .entryPoint(DEFAULT_JS_ENTRY_POINT) .bundleAsset(DEFAULT_JS_BUNDLE_ASSET) .port(DEFAULT_WORKER_PORT) .build(); }
Example 5
Source Project: react-native-dev-menu Source File: RNDevMenuModule.java License: MIT License | 5 votes |
@ReactMethod public void addItem(final String name, Promise promise) { if (mNames == null) { mNames = new ArrayList<>(); } if (mNames.contains(name)) { promise.resolve(null); } try { ReactApplication application = (ReactApplication)getReactApplicationContext() .getCurrentActivity() .getApplication(); DevSupportManager manager = application .getReactNativeHost() .getReactInstanceManager() .getDevSupportManager(); manager.addCustomDevOption(name, new DevOptionHandler() { @Override public void onOptionSelected() { getReactApplicationContext().getJSModule(RCTDeviceEventEmitter.class) .emit("customDevOptionTap", name); } }); mNames.add(name); promise.resolve(null); } catch (Exception e) { promise.reject(e); } }
Example 6
Source Project: react-native-background-job Source File: ReactNativeEventStarter.java License: MIT License | 5 votes |
@Nullable @Override protected HeadlessJsTaskConfig getTaskConfig(Intent intent) { Log.d(LOG_TAG, "getTaskConfig() called with: intent = [" + intent + "]"); Bundle extras = intent.getExtras(); boolean allowExecutionInForeground = extras.getBoolean("allowExecutionInForeground", false); long timeout = extras.getLong("timeout", 2000); // For task with quick execution period additional check is required ReactNativeHost reactNativeHost = ((ReactApplication) getApplicationContext()).getReactNativeHost(); boolean appInForeground = Utils.isReactNativeAppInForeground(reactNativeHost); if (appInForeground && !allowExecutionInForeground) { return null; } return new HeadlessJsTaskConfig(intent.getStringExtra("jobKey"), Arguments.fromBundle(extras), timeout, allowExecutionInForeground); }
Example 7
Source Project: react-native-preloader Source File: ReactPreLoader.java License: Apache License 2.0 | 5 votes |
/** * Pre-load {@link ReactRootView} to local {@link Map}, you may want to * load it in previous activity. */ public static void init(Activity activity, ReactInfo reactInfo) { if (CACHE_VIEW_MAP.get(reactInfo.getMainComponentName()) != null) { return; } ReactRootView rootView = new ReactRootView(new MutableContextWrapper(activity)); rootView.startReactApplication( ((ReactApplication) activity.getApplication()).getReactNativeHost().getReactInstanceManager(), reactInfo.getMainComponentName(), reactInfo.getLaunchOptions()); CACHE_VIEW_MAP.put(reactInfo.getMainComponentName(), rootView); }
Example 8
Source Project: react-native-update Source File: RCTUpdate.java License: MIT License | 5 votes |
private ReactInstanceManager resolveInstanceManager() throws NoSuchFieldException, IllegalAccessException { ReactInstanceManager instanceManager; final Activity currentActivity = getCurrentActivity(); if (currentActivity == null) { return null; } ReactApplication reactApplication = (ReactApplication) currentActivity.getApplication(); instanceManager = reactApplication.getReactNativeHost().getReactInstanceManager(); return instanceManager; }
Example 9
Source Project: rn-floating-video-widget Source File: FloatingVideoWidgetShowService.java License: MIT License | 4 votes |
protected ReactNativeHost getReactNativeHost() { return ((ReactApplication) getApplication()).getReactNativeHost(); }
Example 10
Source Project: MetroExample Source File: JsLoaderUtil.java License: Apache License 2.0 | 4 votes |
public static ReactInstanceManager getReactIM(Application application) { return ((ReactApplication) application).getReactNativeHost().getReactInstanceManager(); }
Example 11
Source Project: react-native-workers Source File: RNWorkersManager.java License: Apache License 2.0 | 4 votes |
public <T extends Application & ReactApplication> void init( final T reactApp, boolean developerSupport) { init(reactApp, RNWorker.createDefault(reactApp, developerSupport)); }
Example 12
Source Project: react-native-workers Source File: WorkerModule.java License: BSD 2-Clause "Simplified" License | 4 votes |
private ReactInstanceManager getReactInstanceManager() { ReactApplication reactApplication = (ReactApplication)getCurrentActivity().getApplication(); return reactApplication.getReactNativeHost().getReactInstanceManager(); }
Example 13
Source Project: react-native-background-job Source File: ReactNativeEventStarter.java License: MIT License | 4 votes |
public ReactNativeEventStarter(@NonNull Context context) { this.context = context; reactNativeHost = ((ReactApplication) context.getApplicationContext()).getReactNativeHost(); }
Example 14
Source Project: react-native-android-fragment Source File: ReactFragment.java License: Apache License 2.0 | 2 votes |
/** * Get the {@link ReactNativeHost} used by this app. By default, assumes * {@link Activity#getApplication()} is an instance of {@link ReactApplication} and calls * {@link ReactApplication#getReactNativeHost()}. Override this method if your application class * does not implement {@code ReactApplication} or you simply have a different mechanism for * storing a {@code ReactNativeHost}, e.g. as a static field somewhere. */ protected ReactNativeHost getReactNativeHost() { return ((ReactApplication) getActivity().getApplication()).getReactNativeHost(); }
Example 15
Source Project: react-native-preloader Source File: MrReactActivity.java License: Apache License 2.0 | 2 votes |
/** * Get the {@link ReactNativeHost} used by this app. By default, assumes {@link #getApplication()} * is an instance of {@link ReactApplication} and calls * {@link ReactApplication#getReactNativeHost()}. Override this method if your application class * does not implement {@code ReactApplication} or you simply have a different mechanism for * storing a {@code ReactNativeHost}, e.g. as a static field somewhere. */ protected ReactNativeHost getReactNativeHost() { return ((ReactApplication) getApplication()).getReactNativeHost(); }