Skip to content

Commit

Permalink
Add focusOnInputWhenKeyboardOpens prop to disable focus on `<TextIn…
Browse files Browse the repository at this point in the history
…put />` when opening the keyboard
  • Loading branch information
danilvalov committed Dec 23, 2024
1 parent ca4466e commit 3656ef0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <TextInput> 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 [`<ListView>`](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 [`<TextInput>`](https://facebook.github.io/react-native/docs/textinput.html)
Expand Down
13 changes: 9 additions & 4 deletions src/GiftedChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export interface GiftedChatProps<TMessage extends IMessage = IMessage> {
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 <TextInput> 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 <ListView>; some props can't be overridden, see the code in MessageContainer.render() for details */
Expand Down Expand Up @@ -251,6 +253,7 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
renderChatFooter = null,
renderInputToolbar = null,
bottomOffset = 0,
focusOnInputWhenKeyboardOpens = true,
keyboardShouldPersistTaps = Platform.select({
ios: 'never',
android: 'always',
Expand Down Expand Up @@ -571,10 +574,11 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
}
)

if (isKeyboardMovingUp)
runOnJS(handleTextInputFocusWhenKeyboardShow)()
else
runOnJS(handleTextInputFocusWhenKeyboardHide)()
if (focusOnInputWhenKeyboardOpens)
if (isKeyboardMovingUp)
runOnJS(handleTextInputFocusWhenKeyboardShow)()
else
runOnJS(handleTextInputFocusWhenKeyboardHide)()

if (value === 0) {
runOnJS(enableTyping)()
Expand All @@ -588,6 +592,7 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
[
keyboard,
trackingKeyboardMovement,
focusOnInputWhenKeyboardOpens,
insets,
handleTextInputFocusWhenKeyboardHide,
handleTextInputFocusWhenKeyboardShow,
Expand Down

0 comments on commit 3656ef0

Please sign in to comment.