From 9dd7dd3476e8a9c3b1e149bb0eb8212ad5139eed 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..1f028af2b 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) +- **`focusOnInputWhenOpeningKeyboard`** _(Bool)_ - Focus on automatically when opening the keyboard; 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..c3c675bf1 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 opening the keyboard; default is true */ + focusOnInputWhenOpeningKeyboard?: 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, + focusOnInputWhenOpeningKeyboard = true, keyboardShouldPersistTaps = Platform.select({ ios: 'never', android: 'always', @@ -571,10 +574,11 @@ function GiftedChat ( } ) - if (isKeyboardMovingUp) - runOnJS(handleTextInputFocusWhenKeyboardShow)() - else - runOnJS(handleTextInputFocusWhenKeyboardHide)() + if (focusOnInputWhenOpeningKeyboard) + if (isKeyboardMovingUp) + runOnJS(handleTextInputFocusWhenKeyboardShow)() + else + runOnJS(handleTextInputFocusWhenKeyboardHide)() if (value === 0) { runOnJS(enableTyping)() @@ -588,6 +592,7 @@ function GiftedChat ( [ keyboard, trackingKeyboardMovement, + focusOnInputWhenOpeningKeyboard, insets, handleTextInputFocusWhenKeyboardHide, handleTextInputFocusWhenKeyboardShow,