I am new to React Native and working on an application which stores local data using Android SharedPreferences. I currently have SharedPreferences setup as ReactContextBaseJavaModule and am able to access all methods through @ReactMethod annotation from a React Native file.
I need to access the value from SharedPreference, defined as ReactContextBaseJavaModule, inside native Android module. Currently I am able to achieve that by updating a constant defined in native Android class(*.kt). Is there a better way to do this, i.e. ability to access methods defined inside ReactContextBaseJavaModule from Android classes or creating a wrapper for SharedPreference access?
I have tried to search for the solution in multiple platforms, and found solutions on how we can access native module from React Native files. I am unable to find the solution on two-way access to a ReactContextBaseJavaModule class.
The challenges I am facing:
- Unable to pass
ReactApplicationContextfrom native Android class for the class instance. - Unable to access methods annotated with
@ReactMethodfrom native Android class. - Injecting native Android class instance inside
ReactContextBaseJavaModule.