Java Code Examples for com.facebook.react.ReactNativeHost

The following examples show how to use com.facebook.react.ReactNativeHost. 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
@ReactMethod
void callJavaScript() {
    Activity activity = getCurrentActivity();
    if (activity != null) {
        MainApplication application = (MainApplication) activity.getApplication();
        ReactNativeHost reactNativeHost = application.getReactNativeHost();
        ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
        ReactContext reactContext = reactInstanceManager.getCurrentReactContext();

        if (reactContext != null) {
            CatalystInstance catalystInstance = reactContext.getCatalystInstance();
            WritableNativeArray params = new WritableNativeArray();
            params.pushString("Hello, JavaScript!");

            // AFAIK, this approach to communicate from Java to JavaScript is officially undocumented.
            // Use at own risk; prefer events.
            // Note: Here we call 'alert', which shows UI. If this is done from an activity that
            // doesn't forward lifecycle events to React Native, it wouldn't work.
            catalystInstance.callFunction("JavaScriptVisibleToJava", "alert", params);
        }
    }
}
 
Example 2
Source Project: react-native-android-activity   Source File: MainActivity.java    License: MIT License 6 votes vote down vote up
/**
 * Demonstrates how to add a custom option to the dev menu.
 * https://stackoverflow.com/a/44882371/3968276
 * This only works from the debug build with dev options enabled.
 */
@Override
@CallSuper
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MainApplication application = (MainApplication) getApplication();
    ReactNativeHost reactNativeHost = application.getReactNativeHost();
    ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
    DevSupportManager devSupportManager = reactInstanceManager.getDevSupportManager();
    devSupportManager.addCustomDevOption("Custom dev option", new DevOptionHandler() {
        @Override
        public void onOptionSelected() {
            if (NotificationManagerCompat.from(MainActivity.this).areNotificationsEnabled()) {
                Toast.makeText(MainActivity.this, CUSTOM_DEV_OPTION_MESSAGE, Toast.LENGTH_LONG).show();
            } else {
                AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).create();
                dialog.setTitle("Dev option");
                dialog.setMessage(CUSTOM_DEV_OPTION_MESSAGE);
                dialog.show();
            }
        }
    });
}
 
Example 3
Source Project: react-native-threads   Source File: RNThreadModule.java    License: MIT License 5 votes vote down vote up
public RNThreadModule(final ReactApplicationContext reactContext, ReactNativeHost reactNativehost, ReactPackage additionalThreadPackages[]) {
  super(reactContext);
  this.reactApplicationContext = reactContext;
  threads = new HashMap<>();
  this.reactNativeHost = reactNativehost;
  this.additionalThreadPackages = additionalThreadPackages;
  reactContext.addLifecycleEventListener(this);
}
 
Example 4
Source Project: react-native-multibundler   Source File: ScriptLoadUtil.java    License: The Unlicense 5 votes vote down vote up
@Nullable
public static CatalystInstance getCatalystInstance(ReactNativeHost host) {
    ReactInstanceManager manager = host.getReactInstanceManager();
    if (manager == null) {
        Log.e(TAG,"manager is null!!");
        return null;
    }

    ReactContext context = manager.getCurrentReactContext();
    if (context == null) {
        Log.e(TAG,"context is null!!");
        return null;
    }
    return context.getCatalystInstance();
}
 
Example 5
Source Project: react-native-background-job   Source File: Utils.java    License: MIT License 5 votes vote down vote up
/** Check whether on not the React Native application is in foreground. */
public static boolean isReactNativeAppInForeground(@NonNull ReactNativeHost reactNativeHost) {
  if (!reactNativeHost.hasInstance()) {
    // If the app was force-stopped the instace will be destroyed. The instance can't be created from a background thread.
    return false;
  }
  ReactContext reactContext = reactNativeHost.getReactInstanceManager().getCurrentReactContext();
  return reactContext != null && reactContext.getLifecycleState() == LifecycleState.RESUMED;
}
 
Example 6
Source Project: rn-floating-video-widget   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 7
Source Project: react-native-sync-adapter   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 8
Source Project: react-native-get-location   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 9
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 10
Source Project: react-native-advertising-id   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 11
Source Project: react-native-tcp-socket   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 12
Source Project: react-native-obd2   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
}
 
Example 13
Source Project: react-native-wifi-reborn   Source File: MainApplication.java    License: ISC License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 14
Source Project: react-native-tesseract-ocr   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 15
Source Project: react-native-streetview   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 16
Source Project: rn-heartbeat   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 17
Source Project: react-native-contacts   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 18
Source Project: react-native-kakao-login   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 19
Source Project: clipboard   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 20
Source Project: react-native-android-wifi   Source File: MainApplication.java    License: ISC License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 21
Source Project: react-native-background-upload   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 22
Source Project: react-native-jw-media-player   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 23
Source Project: react-native-image-filter-kit   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 24
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 25
Source Project: things-notification   Source File: MainApplication.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
}
 
Example 26
Source Project: Musicly   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 27
Source Project: react-native-modal-translucent   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
}
 
Example 28
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 29
Source Project: react-native-fbads   Source File: MainApplication.java    License: MIT License 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
Example 30
Source Project: react-native-jitsi-meet   Source File: MainApplication.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}