Skip to content

Commit

Permalink
docs: add a note about useResizeMode hook
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Nov 20, 2023
1 parent f251c51 commit 76d28bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion docs/docs/guides/building-own-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ keywords: [react-native-keyboard-controller, react-native keyboard, react hook]

# Building own hook

Default hooks may not perfectly fit in your app, because it changes/restores `softInputMode` on mount/unmount of the component where it's used. Though in deep stacks sometimes it may be important to have different `softInputMode` per screen, but by default `react-navigation` keeps previous screens mounted, so if you are using default `useKeyboardAnimation` hook, then all following screens will have `softInputMode=adjustResize`.
Default hooks may not perfectly fit in your app, because it changes/restores `softInputMode` on mount/unmount of the component where it's used.

:::info
This is `useResizeMode` hook behavior - it changes `softInputMode` on mount to `adjustResize` and to default `softInput` on unmount. You may want to [read](../recipes/platform-differences.md#android) why it's crucial to change `softInputMode` to `adjustResize` before using this library.

If you have `android:windowSoftInputMode="adjustResize"` declared in `AndroidManifest.xml` - then you can skip this step at all and forget about changing `softInputMode` in runtime (however you still may want to create your own version of hook without calls to `KeyboardController.*`) 😎.
:::

Sometimes in deep stacks it may be important to have different `softInputMode` per screen, but by default `react-navigation` keeps previous screens mounted, so if you are using default `useKeyboardAnimation` hook, then all following screens will have `softInputMode=adjustResize`.

To prevent such behavior you can write own hook based on primitives from this library. The implementation may look like:

Expand Down
10 changes: 9 additions & 1 deletion docs/versioned_docs/version-1.9.0/guides/building-own-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ keywords: [react-native-keyboard-controller, react-native keyboard, react hook]

# Building own hook

Default hooks may not perfectly fit in your app, because it changes/restores `softInputMode` on mount/unmount of the component where it's used. Though in deep stacks sometimes it may be important to have different `softInputMode` per screen, but by default `react-navigation` keeps previous screens mounted, so if you are using default `useKeyboardAnimation` hook, then all following screens will have `softInputMode=adjustResize`.
Default hooks may not perfectly fit in your app, because it changes/restores `softInputMode` on mount/unmount of the component where it's used.

:::info
This is `useResizeMode` hook behavior - it changes `softInputMode` on mount to `adjustResize` and to default `softInput` on unmount. You may want to [read](../recipes/platform-differences.md#android) why it's crucial to change `softInputMode` to `adjustResize` before using this library.

If you have `android:windowSoftInputMode="adjustResize"` declared in `AndroidManifest.xml` - then you can skip this step at all and forget about changing `softInputMode` in runtime (however you still may want to create your own version of hook without calls to `KeyboardController.*`) 😎.
:::

Sometimes in deep stacks it may be important to have different `softInputMode` per screen, but by default `react-navigation` keeps previous screens mounted, so if you are using default `useKeyboardAnimation` hook, then all following screens will have `softInputMode=adjustResize`.

To prevent such behavior you can write own hook based on primitives from this library. The implementation may look like:

Expand Down

0 comments on commit 76d28bd

Please sign in to comment.