Java Code Examples for com.facebook.react.common.LifecycleState#RESUMED

The following examples show how to use com.facebook.react.common.LifecycleState#RESUMED . 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 File: ReactInstanceManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
private void tearDownReactContext(ReactContext reactContext) {
  Log.d(ReactConstants.TAG, "ReactInstanceManager.tearDownReactContext()");
  UiThreadUtil.assertOnUiThread();
  if (mLifecycleState == LifecycleState.RESUMED) {
    reactContext.onHostPause();
  }

  synchronized (mAttachedRootViews) {
    for (ReactRootView rootView : mAttachedRootViews) {
      rootView.removeAllViews();
      rootView.setId(View.NO_ID);
    }
  }

  reactContext.destroy();
  mDevSupportManager.onReactInstanceDestroyed(reactContext);
  mMemoryPressureRouter.removeMemoryPressureListener(reactContext.getCatalystInstance());
}
 
Example 2
Source File: HeadlessJsTaskContext.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Start a JS task. Handles invoking {@link AppRegistry#startHeadlessTask} and notifying
 * listeners.
 *
 * @return a unique id representing this task instance.
 */
public synchronized int startTask(final HeadlessJsTaskConfig taskConfig) {
  UiThreadUtil.assertOnUiThread();
  ReactContext reactContext = Assertions.assertNotNull(
    mReactContext.get(),
    "Tried to start a task on a react context that has already been destroyed");
  if (reactContext.getLifecycleState() == LifecycleState.RESUMED &&
    !taskConfig.isAllowedInForeground()) {
    throw new IllegalStateException(
      "Tried to start task " + taskConfig.getTaskKey() +
        " while in foreground, but this is not allowed.");
  }
  final int taskId = mLastTaskId.incrementAndGet();
  mActiveTasks.add(taskId);
  reactContext.getJSModule(AppRegistry.class)
    .startHeadlessTask(taskId, taskConfig.getTaskKey(), taskConfig.getData());
  if (taskConfig.getTimeout() > 0) {
    scheduleTaskTimeout(taskId, taskConfig.getTimeout());
  }
  for (HeadlessJsTaskEventListener listener : mHeadlessJsTaskEventListeners) {
    listener.onHeadlessJsTaskStart(taskId);
  }
  return taskId;
}
 
Example 3
Source File: ReactFragment.java    From react-native-android-fragment with Apache License 2.0 6 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    if (mReactRootView != null) {
        mReactRootView.unmountReactApplication();
        mReactRootView = null;
    }
    if (getReactNativeHost().hasInstance()) {
        ReactInstanceManager reactInstanceMgr = getReactNativeHost().getReactInstanceManager();

        // onDestroy may be called on a ReactFragment after another ReactFragment has been
        // created and resumed with the same React Instance Manager. Make sure we only clean up
        // host's React Instance Manager if no other React Fragment is actively using it.
        if (reactInstanceMgr.getLifecycleState() != LifecycleState.RESUMED) {
            reactInstanceMgr.onHostDestroy(getActivity());
            getReactNativeHost().clear();
        }
    }
}
 
Example 4
Source File: ReactContext.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * Should be called by the hosting Fragment in {@link Fragment#onResume}
 */
public void onHostResume(@Nullable Activity activity) {
  mLifecycleState = LifecycleState.RESUMED;
  mCurrentActivity = new WeakReference(activity);
  ReactMarker.logMarker(ReactMarkerConstants.ON_HOST_RESUME_START);
  for (LifecycleEventListener listener : mLifecycleEventListeners) {
    try {
      listener.onHostResume();
    } catch (RuntimeException e) {
      handleException(e);
    }
  }
  ReactMarker.logMarker(ReactMarkerConstants.ON_HOST_RESUME_END);
}
 
Example 5
Source File: ReactInstanceManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
private synchronized void moveToResumedLifecycleState(boolean force) {
  ReactContext currentContext = getCurrentReactContext();
  if (currentContext != null) {
    // we currently don't have an onCreate callback so we call onResume for both transitions
    if (force ||
        mLifecycleState == LifecycleState.BEFORE_RESUME ||
        mLifecycleState == LifecycleState.BEFORE_CREATE) {
      currentContext.onHostResume(mCurrentActivity);
    }
  }
  mLifecycleState = LifecycleState.RESUMED;
}
 
Example 6
Source File: ReactInstanceManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
private synchronized void moveToBeforeResumeLifecycleState() {
  ReactContext currentContext = getCurrentReactContext();
  if (currentContext != null) {
    if (mLifecycleState == LifecycleState.BEFORE_CREATE) {
      currentContext.onHostResume(mCurrentActivity);
      currentContext.onHostPause();
    } else if (mLifecycleState == LifecycleState.RESUMED) {
      currentContext.onHostPause();
    }
  }
  mLifecycleState = LifecycleState.BEFORE_RESUME;
}
 
Example 7
Source File: ReactInstanceManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
private synchronized void moveToBeforeCreateLifecycleState() {
  ReactContext currentContext = getCurrentReactContext();
  if (currentContext != null) {
    if (mLifecycleState == LifecycleState.RESUMED) {
      currentContext.onHostPause();
      mLifecycleState = LifecycleState.BEFORE_RESUME;
    }
    if (mLifecycleState == LifecycleState.BEFORE_RESUME) {
      currentContext.onHostDestroy();
    }
  }
  mLifecycleState = LifecycleState.BEFORE_CREATE;
}
 
Example 8
Source File: ReactAppTestActivity.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
protected void onResume() {
  super.onResume();

  mLifecycleState = LifecycleState.RESUMED;

  if (mReactInstanceManager != null) {
    mReactInstanceManager.onHostResume(this, this);
  }
}
 
Example 9
Source File: Utils.java    From react-native-background-job with 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 10
Source File: ReactInstanceManager.java    From react-native-GPay with MIT License 4 votes vote down vote up
private synchronized void moveReactContextToCurrentLifecycleState() {
  if (mLifecycleState == LifecycleState.RESUMED) {
    moveToResumedLifecycleState(true);
  }
}