> 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/keyboard-handling.md).

# Keyboard Handling

## KeyboardProvider

KeyboardProvider is highly recommended. It helps preventing bottom sheet jumping/flashing due to the root screen resizing, when the keyboard opens

Even though KeyboardProvider's docs say that you will enter `edge-to-edge` mode when wrapping your app with `KeyboardProvider`. Visually, I found that the app could still be in `non-edge-to-edge` mode if you opt out of `edge-to-edge` mode in Android config

### Expo Router in non-edge-to-edge mode

* When you use `KeyboardProvider` with Expo Router in **non-edge-to-edge** mode, you would notice double safe area insets on the default router header
* You can introduce something similar to `apps/example-expo/features/root-layout/custom-header-for-keyboard-provider.tsx` to remove the inset for the header

## Sample code

```tsx
const ManagedTextInput = forwardRef<TextInput, TextInputProps>(
  ({ onFocus: propOnFocus, onBlur: propOnBlur, ...rest }, ref) => {
    const { onFocus, onBlur } = useInputFocus()

    return (
      <TextInput
        ref={ref}
        {...rest}
        onFocus={(e) => {
          onFocus()
          propOnFocus?.(e)
        }}
        onBlur={(e) => {
          onBlur()
          propOnBlur?.(e)
        }}
      />
    )
  },
)

// ...

<Portal hostName="root">
  <SheetStackItem
    isOpen={isOpenA}
    close={() => setIsOpenA(false)}
    waitForFullyExit
    testID="sheetA"
  >
    <BottomSheetPresenter>
      <BottomSheetProvider snapPoints={[400, 800]}>
        <InputFocusProvider>
          <BottomSheet>
            <BottomSheetHandle />

            <BottomSheetScrollView>
              <Text>Sheet A</Text>

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

              <ManagedTextInput
                style={styles.input}
                placeholder="Type something..."
                placeholderTextColor="#999"
              />

              {renderContent()}
            </BottomSheetScrollView>
          </BottomSheet>

          <BottomSheetKeyboardExpander keyboardOffset={20} />
        </InputFocusProvider>
      </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/keyboard-handling.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.
