React Nitro

Navigating between screens

Give each screen a route and present it on a native stack.

react-nitro-navigation uses React Navigation's router and presents screens with UIKit navigation controllers on iOS and AndroidX Fragments on Android. Add it as a direct app dependency matching your renderer version. For the starter used in the installation guide, run bun add --exact react-nitro-navigation@0.0.1-alpha.16.

Start with a route map. A route with no parameters has the value undefined. For a detail screen, describe the data it needs when opened.

src/App.tsx
import { useCallback } from 'react'
import {
  createStackNavigator, NavigationContainer, useNavigation,
  type StackNavigationProp,
} from 'react-nitro-navigation'
import { TapGestureRecognizer, Text } from 'react-nitro-renderer'

type Routes = {
  Notebook: undefined
  Note: { title: string }
}

const Stack = createStackNavigator<Routes>()

function Notebook() {
  const navigation = useNavigation<StackNavigationProp<Routes>>()
  const attachTap = useCallback(() => {
    const tap = new TapGestureRecognizer()
    tap.onTap = () => navigation.push('Note', { title: 'River walk' })
    return [tap]
  }, [navigation])
  return <Text layout={{ padding: 20 }} gestureRecognizers={attachTap}>Open River walk</Text>
}

function Note({ route }: { route: { params: Routes['Note'] } }) {
  return <Text layout={{ padding: 20 }}>{route.params.title}</Text>
}

export function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator initialRouteName="Notebook">
        <Stack.Screen name="Notebook" component={Notebook} />
        <Stack.Screen name="Note" component={Note} options={{ title: 'Field note' }} />
      </Stack.Navigator>
    </NavigationContainer>
  )
}

Tap Open River walk to push the detail screen. The native back action returns to the notebook. Use navigation.goBack() to do the same from your own control. A cancelled back gesture leaves the detail route active.

Connect a thumbnail to its detail view

Animate the selected thumbnail into the detail screen and back by matching a native view on each screen. Shared element transitions

Bottom tabs

Use createBottomTabNavigator to switch between top-level destinations. Declare a Tab.Screen for each destination inside Tab.Navigator, under the same NavigationContainer. Each tab can contain its own stack. By default a screen first renders when its tab opens. Set lazy: false in its options to mount it earlier. The title, tabBarIcon, and tabBarBadge options configure the native tab bar.

Browse the navigation components.

On this page