Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add focusOnInputWhenKeyboardOpens prop to disable focus on <TextInput /> when opening the keyboard #2573

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
- **`focusOnInputWhenOpeningKeyboard`** _(Bool)_ - Focus on <TextInput> 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 [`<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 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 <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,
focusOnInputWhenOpeningKeyboard = 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 (focusOnInputWhenOpeningKeyboard)
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,
focusOnInputWhenOpeningKeyboard,
insets,
handleTextInputFocusWhenKeyboardHide,
handleTextInputFocusWhenKeyboardShow,
Expand Down
Loading