feat(Android): get TurboModules implementing given interface #53252
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Currently it's impossible to discover TurboModules that implement a given interface. This is handy when we need to initialize modules based on the fact if they implement a given interface or not. Currently it's impossible to do so without initializing the modules that don't implement the given interface too.
This pull request implements this functionality on Android. Implementation for iOS is in another pull request:
I implemented it by adding an overload for
ReactModuleInfoclass that takes the Class of the TurboModule as a parameter. Unfortunately I can't obtain the class via it's name, because the docs are suggesting to replace the name of the (java) Class with a custom name:Changelog:
[Android] [ADDED] - Allow to get from TurboModuleManager TurboModules that implement a given interface at any point in time.
Test Plan:
Example use to get all modules implementing
LifecycleEventListenerclass.