-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhanced lifecycle-aware module registry #849
base: main
Are you sure you want to change the base?
Conversation
@implementation AppDelegate | ||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | ||
[[RNLifecycleManager sharedInstance] notifyModulesWithSelector:@selector(applicationDidFinishLaunching:) application:application]; | ||
return YES; | ||
} | ||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it would be best if this was internal in RN itself (maybe via method swizzling or having some standard interface from core that is exposed and the app delegate implements) this way we can make changes without any user facing breaking API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main goal is simply to show, in basic terms, how this works. The actual implementation will occur internally inRCTAppDelegate
, so there’s no need for user-facing changes. I’ll revise the examples to avoid confusion for others.
class MainApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
LifecycleManager.notify { it.onCreate(this) } | ||
} | ||
|
||
override fun onTerminate() { | ||
super.onTerminate() | ||
LifecycleManager.notify { it.onDestroy() } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
This RFC proposes a framework to enhance the module registry in React Native by introducing a lifecycle-aware system for native modules. The goal is to address the current gap in handling application lifecycle events, similar to Flutter's
FlutterApplicationLifeCycleDelegate
on iOS andApplication.ActivityLifecycleCallbacks
on Android. The design enables seamless integration of native modules with application lifecycle events across iOS and Android platforms. There is also Expo Modules Core that handles this viaExpoAppDelegateSubscriber
andReactActivityLifecycleListener
, but React Native does not have this by default and it requires Expo to be used in such cases.A rendered version of the proposal can be read here