當前位置: 首頁>>代碼示例>>Java>>正文


Java ReactNativeHost類代碼示例

本文整理匯總了Java中com.facebook.react.ReactNativeHost的典型用法代碼示例。如果您正苦於以下問題:Java ReactNativeHost類的具體用法?Java ReactNativeHost怎麽用?Java ReactNativeHost使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ReactNativeHost類屬於com.facebook.react包,在下文中一共展示了ReactNativeHost類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: callJavaScript

import com.facebook.react.ReactNativeHost; //導入依賴的package包/類
@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!");
            catalystInstance.callFunction("JavaScriptVisibleToJava", "alert", params);
        }
    }
}
 
開發者ID:petterh,項目名稱:react-native-android-activity,代碼行數:18,代碼來源:ActivityStarterModule.java

示例2: RNThreadModule

import com.facebook.react.ReactNativeHost; //導入依賴的package包/類
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);
}
 
開發者ID:joltup,項目名稱:react-native-threads,代碼行數:9,代碼來源:RNThreadModule.java

示例3: onCreate

import com.facebook.react.ReactNativeHost; //導入依賴的package包/類
/**
 * Demonstrates how to add a custom option to the dev menu.
 * https://stackoverflow.com/a/44882371/3968276
 */
@Override
protected void onCreate(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() {
            Toast.makeText(MainActivity.this, "Hello from custom dev option", Toast.LENGTH_SHORT).show();
        }
    });
}
 
開發者ID:petterh,項目名稱:react-native-android-activity,代碼行數:19,代碼來源:MainActivity.java

示例4: getTaskConfig

import com.facebook.react.ReactNativeHost; //導入依賴的package包/類
@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);
}
 
開發者ID:vikeri,項目名稱:react-native-background-job,代碼行數:16,代碼來源:ReactNativeEventStarter.java

示例5: isReactNativeAppInForeground

import com.facebook.react.ReactNativeHost; //導入依賴的package包/類
/** 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;
}
 
開發者ID:vikeri,項目名稱:react-native-background-job,代碼行數:10,代碼來源:Utils.java

示例6: getReactNativeHost

import com.facebook.react.ReactNativeHost; //導入依賴的package包/類
@Override
public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
}
 
開發者ID:hiteshsahu,項目名稱:FingerPrint-Authentication-With-React-Native-Android,代碼行數:5,代碼來源:MainApplication.java

示例7: getReactNativeHost

import com.facebook.react.ReactNativeHost; //導入依賴的package包/類
@Override
public ReactNativeHost getReactNativeHost() {
  return mReactNativeHost;
}
 
開發者ID:miguelespinoza,項目名稱:react-native-nearby,代碼行數:5,代碼來源:MainApplication.java

示例8: RNThreadPackage

import com.facebook.react.ReactNativeHost; //導入依賴的package包/類
public RNThreadPackage(ReactNativeHost reactNativeHost, ReactPackage... additionalThreadPackages) {
    this.reactNativeHost = reactNativeHost;
    this.additionalThreadPackages = additionalThreadPackages;
}
 
開發者ID:joltup,項目名稱:react-native-threads,代碼行數:5,代碼來源:RNThreadPackage.java


注:本文中的com.facebook.react.ReactNativeHost類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。