Firstly I am not talking about the old architecture and I have already gone through this
This method does not really works for new architecture given how the files are structured
registerForActivityResult
can only be used in MainActivity
. I need registerForActivityResult
for my intent to pick images.
Here is the complete code sample
The issue is I can’t call my MainActivity in my Module as the Module file is not part of the main android folder but a separate folder called RTNImagePicker in my case
I get below error if I try to refer MainActivity in my module
I cannot add it as dependency on module as well as it results in circular dependency
3
Answers
You will need to have a gateway module.
A gateway module would act as a buffer between the two modules and take care of any dependency related issue
eg
Now use this interface as means to pass the data from one activity to another using registerForActivityResult after adding this gateway module as a dependency in your project.
Hope this helps you:
MainActivity:
RTNImagePicker:
you can try this code as well,
basically, with the PermissionAwareActivity interface it allows the activity to handle runtime permissions in a React Native application.I think its work for your scenario
onActivityResult is deprecated,in place that you can use this as well registerForActivityResult
#edited 2- this code example for how we call this with our turbo module,