-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
feat: make reactHost accessible #48338
base: main
Are you sure you want to change the base?
feat: make reactHost accessible #48338
Conversation
/rebase |
Thanks for sending this over @WoLewicki This sounds like a reasonable approach, but I'd like to have @mdvacca 's opinion on this as well |
IIRC for internal apps use-case we were able to make use of cc: @shwanton |
/** Cleanup function for brownfield scenarios. */ | ||
public abstract void invalidate(); |
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.
I see that ReactNativeHost
already has a clear()
method.
Could we instead do the invalidation in the DefaultReactHost.clear()
method instead of having to create a brand new invalidate()
abstract method?
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.
Ok so clear
is a public API for cleaning all of those instances? If so, I think it will be the correct place to put it there then.
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.
I changed it but I am not sure if the INSTANCE
is the proper way of getting the instance of kotlin object.
public fun invalidate() { | ||
reactHost = null | ||
} |
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.
can you instead override fun clear()
, call super.clear()
and set the reactHost to null here?
@@ -78,6 +78,7 @@ public synchronized void clear() { | |||
mReactInstanceManager.invalidate(); | |||
mReactInstanceManager = null; | |||
} | |||
DefaultReactHost.INSTANCE.invalidate(); |
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.
this is probably not needed
Summary:
On bridgeless mode,
reactHost
is kept in memory even after destroying theDefaultReactNativeHost
in brownfield scenario. Since it keeps references to the modules, they are not deallocated, and theirinitialize
methods are not fired again when creating new instance ofreact-native
later. It breaks the behavior of e.g.react-native-screens
, which wants to listen for mutations and should get newFabricUIManager
: https://github.com/software-mansion/react-native-screens/blob/20b7e83782cd5f79ddd0d61dadc13eeb4db4b258/android/src/main/java/com/swmansion/rnscreens/ScreensModule.kt#L45.By adding
invalidate
method, which cleans up thereactHost
instance, we can achieve it.Changelog:
[ANDROID] [FIXED] - add
invalidate
method for destroyingreactHost
instance.Test Plan:
In brownfield scenario, destroy the instance of RN and see that modules are also destroyed.