Last active
June 24, 2022 07:38
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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