Migration

Migrate a screen

Ship a Compose screen through an existing React Native route and keep a rollback path during rollout.

On this page

Start with the behavior checklist. The existing route keeps its params, deep links, back behavior and analytics identity. Navigation and Fabric

Ship the slice#

  1. Annotate the composable with @ReactNativeComponent, and its callbacks become events.
  2. Run ./gradlew :shared:generateReactNativeBindings and install the generated package. This is described in the installation guide.
  3. Render the generated component from the route that used to render the React Native screen.
  4. Test on both platforms with the inventory above, then release.

Releasing a slice goes through your usual release process, with two differences. The new screen is native code, so it ships in a new app binary (a store release), not in an over-the-air JavaScript update. And the build now compiles Kotlin: the Android build publishes the Kotlin module for you, and the iOS build compiles the Kotlin framework through the module's podspec, so your CI needs the Kotlin toolchain next to the React Native one.

Plan the way back#

A migration you can undo is a migration you can ship on a Friday. Keep the old screen next to the new one for as long as the new one is unproven, and let the route stay the same:

tsx
import { useFlag } from '../flags'; // your own feature flag layer
import { ProfileScreen } from '../screens/ProfileScreen'; // the React Native version
import { ProfileView } from 'react-native-kmp'; // the generated Compose component

export default function Profile() {
  const useCompose = useFlag('profile-compose');
  return useCompose ? <ProfileView style={{ flex: 1 }} /> : <ProfileScreen />;
}

The URL, the deep links and the analytics screen name do not change when the flag flips. Rolling back is then a configuration change, if these conditions hold:

  • Both versions are in the binary. The flag can only switch between screens that are already shipped. The release that introduces the Compose screen cannot be rolled back by a flag alone: it needs the flag to default to the React Native screen, or a new release.
  • The flag can be changed without a release, for example from a remote configuration service, and it reaches users who are offline or on an old cached value. Decide what the default is when the flag cannot be read.
  • Both versions read and write the same data. If the Compose screen saves something the React Native one does not understand, flipping back loses it or breaks it.

The flag layer here is whatever you already use: RN2KMP does not provide one.

Delete the React Native version once the Compose one has been on for a full release cycle without a regression. From then on, rolling back means releasing a new binary again.