react-native
react-native copied to clipboard
Google Play feature (Dynamic Modules) Support for local resources
Topic:
Issue:
Resources can not be loaded from feature module. [res/* folder, assets/* will work]
Scenario:
- Put react native bundle in feature module of Android.
- Load the module. (Using native code, working fine)
- React activity is started and all the text is shown. (Taking example of react-native starter project screen)
- Images are not shown. (Or in-fact any resource which you put it res/ folder)
Anything in assets/ folder will work properly. Network images are also loaded properly.
Reason:
This is because according to Feature Resources Section in Android docs, you can see that any resources in dynamic feature module will have package with feature module name. Like this,
App package name: com.example.my_app_package Feature's resources package name: com.example.my_app_package.my_dynamic_feature
Now at most for the places we get resource from string identifier which takes a package. This context.getPackage()
will return application package. This causes the id to be returned as 0. (For a fact, If I change the package with context.getPackage() + ".featureModule"
, it is able to find the resource. (This is the file below while debugging)
https://github.com/facebook/react-native/blob/dc80b2dcb52fadec6a573a9dd1824393f8c29fdc/ReactAndroid/src/main/java/com/facebook/react/views/imagehelper/ResourceDrawableIdHelper.java#L63
If we can find some way to actually pass the correct package name which we can append here (maybe from some prop in image) or some better solution, it will be great.
There is method resources.getResourcePackageName(resId)
which takes an ID and gives correct package name but this is of no use here.
These are few places I found similar calls: getIdentifier Search on Rn
Hi, Any help regarding this?
@amank22 Cann you add an example of using Play Feature Delivery with React Native? I can't find a library / documentation to do that.
@amank22 Cann you add an example of using Play Feature Delivery with React Native? I can't find a library / documentation to do that.
Hi, I currently don't have any sample project. But we did a POC.
Hoping you know how dynamic feature works and you have done the code to load a simple dynamic feature. Following recommendations you can follow:
- You should put your index bundle file in assets of dynamic feature module.
- resources will go in main app module (better if you just fetch images from backend/api service for app size savings)
- You can initiate react host and packages from dynamic module (you can use anything from main module)
What we were trying to achieve was to split react bundle with different hosts but that was also achieved through some hacks (I don't remember as rn part was done by some other dev). Also we never took this live because of business priorities but it is doable.
Hope I can help a little bit and do ask any specific question if you have in mind and I'll try to help.
@ChocolateLoverRaj These might help you-
https://github.com/varunon9/dynamic-feature-delivery-react-native https://github.com/varunon9/react-native-multiple-bundle
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.