> For the complete documentation index, see [llms.txt](https://the-sheet.gitbook.io/the-sheet-v2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://the-sheet.gitbook.io/the-sheet-v2/docs/core/embedded-stack-navigator.md).

# Embedded Stack Navigator

React Navigation is not designed specifically for bottom sheets navigation

Traditionally, you would use `NavigationIndependentTree` to create an independent navigation tree inside the bottom sheet

But it has limitations and is tricky to work with if you want to navigate outside from inside the bottom sheet

Read more here: <https://reactnavigation.org/docs/8.x/navigation-container#independent-navigation-containers>

## Solution

To solve this problem, I've created a really simple standalone stack navigator that can be used inside anything, including bottom sheets

## Usage

```tsx
type RouteParamList = {
  ScreenA: undefined
  ScreenB: undefined
}

// ...

function ScreenA() {
  const navigation = useEmbeddedStackNavigation<RouteParamList>()

  return (
    <View style={styles.root}>
      <Text>Screen A</Text>

      <Button
        title="Go to Screen B"
        onPress={() =>
          navigation.navigate({ name: 'ScreenB', params: undefined })
        }
      />
    </View>
  )
}

// ...

const renderScreenA = useCallback(() => <ScreenA />, [])

const renderScreenB = useCallback(() => <ScreenB />, [])

const screens = useMemo(() => {
return {
    ScreenA: renderScreenA,
    ScreenB: renderScreenB,
} satisfies Record<keyof RouteParamList, ScreenRenderer>
}, [renderScreenA, renderScreenB])

// ...

<Portal hostName="root">
  <SheetStackItem
    isOpen={isOpenA}
    close={() => setIsOpenA(false)}
    waitForFullyExit
    testID="sheetA"
  >
    <Backdrop />

    <BottomSheetPresenter>
      <BottomSheetProvider>
        <BottomSheet fill styles={{ root: { maxHeight: '75%' } }}>
          <BottomSheetHandle />

          <BottomSheetView fill>
            <Text>Sheet A</Text>
            <Button
              title="Close Sheet A"
              onPress={() => setIsOpenA(false)}
            />

            <EmbeddedStackNavigator<
              typeof screens,
              RouteParamList,
              'ScreenA'
            >
              initialRouteName={'ScreenA'}
              initialParams={undefined}
              screens={screens}
              transitionType="fade"
              fill
            />
          </BottomSheetView>
        </BottomSheet>
      </BottomSheetProvider>
    </BottomSheetPresenter>
  </SheetStackItem>
</Portal>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://the-sheet.gitbook.io/the-sheet-v2/docs/core/embedded-stack-navigator.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
