From 3656ef0e001f2a4eb708b6bc04213227cdb172bd Mon Sep 17 00:00:00 2001 From: Danil Valov Date: Mon, 23 Dec 2024 22:36:29 +0300 Subject: [PATCH] Add `focusOnInputWhenKeyboardOpens` prop to disable focus on `` when opening the keyboard --- README.md | 1 + src/GiftedChat.tsx | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d9d9ba4ff..a7e236e61 100644 --- a/README.md +++ b/README.md @@ -400,6 +400,7 @@ interface QuickReplies { - **`renderAccessory`** _(Function)_ - Custom second line of actions below the message composer - **`onPressActionButton`** _(Function)_ - Callback when the Action button is pressed (if set, the default `actionSheet` will not be used) - **`bottomOffset`** _(Integer)_ - Distance of the chat from the bottom of the screen (e.g. useful if you display a tab bar) +- **`focusOnInputWhenKeyboardOpens`** _(Bool)_ - Focus on automatically when keyboard opens; default `true` - **`minInputToolbarHeight`** _(Integer)_ - Minimum height of the input toolbar; default is `44` - **`listViewProps`** _(Object)_ - Extra props to be passed to the messages [``](https://facebook.github.io/react-native/docs/listview.html); some props can't be overridden, see the code in `MessageContainer.render()` for details - **`textInputProps`** _(Object)_ - Extra props to be passed to the [``](https://facebook.github.io/react-native/docs/textinput.html) diff --git a/src/GiftedChat.tsx b/src/GiftedChat.tsx index 7739d462b..1387fe738 100644 --- a/src/GiftedChat.tsx +++ b/src/GiftedChat.tsx @@ -117,6 +117,8 @@ export interface GiftedChatProps { lightboxProps?: LightboxProps /* Distance of the chat from the bottom of the screen (e.g. useful if you display a tab bar); default is 0 */ bottomOffset?: number + /* Focus on automatically when keyboard opens; default is true */ + focusOnInputWhenKeyboardOpens?: boolean /* Minimum height of the input toolbar; default is 44 */ minInputToolbarHeight?: number /* Extra props to be passed to the messages ; some props can't be overridden, see the code in MessageContainer.render() for details */ @@ -251,6 +253,7 @@ function GiftedChat ( renderChatFooter = null, renderInputToolbar = null, bottomOffset = 0, + focusOnInputWhenKeyboardOpens = true, keyboardShouldPersistTaps = Platform.select({ ios: 'never', android: 'always', @@ -571,10 +574,11 @@ function GiftedChat ( } ) - if (isKeyboardMovingUp) - runOnJS(handleTextInputFocusWhenKeyboardShow)() - else - runOnJS(handleTextInputFocusWhenKeyboardHide)() + if (focusOnInputWhenKeyboardOpens) + if (isKeyboardMovingUp) + runOnJS(handleTextInputFocusWhenKeyboardShow)() + else + runOnJS(handleTextInputFocusWhenKeyboardHide)() if (value === 0) { runOnJS(enableTyping)() @@ -588,6 +592,7 @@ function GiftedChat ( [ keyboard, trackingKeyboardMovement, + focusOnInputWhenKeyboardOpens, insets, handleTextInputFocusWhenKeyboardHide, handleTextInputFocusWhenKeyboardShow,