Skip to content

Instantly share code, notes, and snippets.

@christocracy
Last active June 24, 2022 07:38
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save christocracy/ab133408cd6458d406a3 to your computer and use it in GitHub Desktop.
Save christocracy/ab133408cd6458d406a3 to your computer and use it in GitHub Desktop.
Listening to React-Native life-cycle events in your custom Views or Modules
public class MyView extends SimpleViewManager<MapView> {
public static final String TAG = "MyView";
@Override
public String getName() {
return TAG;
}
@Override
protected MapView createViewInstance(ThemedReactContext context) {
// Create listener:
LifecycleEventListener listener = new LifecycleEventListener() {
@Override
public void onHostResume() {
Log.i(TAG, "- onResume");
}
@Override
public void onHostPause() {
Log.i(TAG, "- onPauase");
}
@Override
public void onHostDestroy() {
Log.i(TAG, "- onDestroy");
}
};
// Add it. Done.
context.addLifecycleEventListener(listener);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment