Forked from christocracy/LifecycleEventLIstener.java
Created
January 30, 2022 21:56
-
-
Save EfeAgare/791b296bd7895ae5f1ba59fae3a6e6f0 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 hidden or 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