Noob question - what's the best workflow for using primarily React with some custom iOS / Android code?

Sorry if this is stupid but I’m having a hard time understanding which workflow I need exactly. I want to write nearly everything I can in react, but there’s some custom code in the native language I need to write. I think I need the bare workflow and to do prebuilds? But I’m not sure how it works if I make a change to React, prebuild, make a change to android and then want to update the react code, do I need to prebuild again and copy paste and custom android code into the new prebuild? Also I’m not sure how to reference the custom code from react.

Any help much appreciated, I’ve tried to get this from the docs but I’ve just ended up going around in circles

Hi @ollyrennard

The simple answer is “you need the ‘bare’ workflow”.

But there are actually various options. (Also, I’ve never written native code for a React Native app, so I can’t talk from experience about that part of it.)

Ideally (in my opinion), you would write the native code as a dependency that you can install in your app. Then your app could stay a managed app (no native ios/android directories in your app). You would need to build your app with eas build instead of the classic npx expo build:android (or build:ios) in order to be able to access the native code from this dependency, though. Also, because Expo Go would not include your native code, you would not be able to use that for development. Fortunately you can build a development client which is basically a custom version of Expo Go that has all of your dependencies built in.

If installation of your native dependency can be handled by React Native autolinking then you will not need to write a config plugin in order for the app to install it. If you need to do extra things (e.g. modifying AndroidManifest.xml or build.gradle etc., etc.) then you will need to write a config plugin so that these modifications can be done during the EAS Build build process.

Alternatively you could run npx expo prebuild to generate the native projects and modify the code as you see fit. (This is what was called the bare workflow before. I think they’re now calling it the “prebuild” workflow or something like that.)

Developing the native code as a separate dependency that you just install in your app would make it much simpler to upgrade to later versions of the Expo SDK/React Native and I think it would be cleaner to separate the native code from the rest of the app.

Info about writing native modules:

There’s also a page in that section about creating an npm package for your native code.

There’s also the “Sweet API”, which as far as I understand it is the Expo team’s preferred way of writing native modules:

Sweet API

The Swift and Kotlin API for writing React Native modules. This API is provided by the library expo-modules-core which is shipped with the expo package. For more information, see Module API.

See also the “creating-expo-modules” channel on Expo’s Discord