When working with React Native, there is a useful feature that allows us to use different component files based on the platform. For example, using component.ios.js
and component.android.js
will generate a component
module with specific behavior for iOS and Android.
Is there a way to create different components based on build variants, flavors, or schemes? For instance, if I have a pro
and a lite
version of my app, can I do something like this:
| some-folder/
| -- component.pro.js
| -- component.lite.js
So when I do
import component from 'some-folder/component'
, the bundler can recognize whether I'm using the pro
or lite
build variant and bundle the correct JavaScript file, similar to how it works with OS suffixes.
I understand that I could check the build variant at runtime and provide the correct component accordingly, but this would mean including unnecessary code for the wrong variant in the app, making it larger than needed.
Relatedly, is there a way to import images conditionally based on the build variant? I know I could place them in separate asset folders for each native platform, but I am curious if there are other methods available.
Any assistance on these matters would be highly appreciated.