Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

matinzd
Copy link

@matinzd matinzd commented Jan 6, 2025

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 and Application.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 via ExpoAppDelegateSubscriber and ReactActivityLifecycleListener, 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

Comment on lines +76 to +81
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[RNLifecycleManager sharedInstance] notifyModulesWithSelector:@selector(applicationDidFinishLaunching:) application:application];
return YES;
}
@end

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

Copy link
Author

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.

Comment on lines +117 to +127
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
LifecycleManager.notify { it.onCreate(this) }
}

override fun onTerminate() {
super.onTerminate()
LifecycleManager.notify { it.onDestroy() }
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@matinzd matinzd marked this pull request as ready for review January 6, 2025 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants