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

Keyboard issue #435

Closed
vidhyalakshmirbt opened this issue Apr 24, 2017 · 30 comments
Closed

Keyboard issue #435

vidhyalakshmirbt opened this issue Apr 24, 2017 · 30 comments

Comments

@vidhyalakshmirbt
Copy link

When the user opens the app first time or when app is no longer in background or running, keyboard handling is fine but When user opens the application from background, keyboard hides the text input.
both in android and iOS , how can this be handled?
@kfiroo any idea?

@brunocascio
Copy link
Collaborator

Please, complete the issue guideline in order to help you.

Thanks!

@pulpdood
Copy link

I get the same thing on Android - the keyboard hides the text input when the text input is clicked

image

@6axter82
Copy link

If someone solved this? Please, post your solution

@pulpdood
Copy link

Try davista123's solution here: #578

Worked for me although my problem was a little different

@6axter82
Copy link

@pulpdood neither #578 or #680 helped me. no changes for iOS

@xcarpentier
Copy link
Collaborator

Hello @6axter82,

To be able to reproduce, can you please fill those informations?
And the share your code too?

Thanks

Nodejs version: [FILL THIS OUT]
React version: [FILL THIS OUT]
React Native version: [FILL THIS OUT]
react-native-gifted-chat version: [FILL THIS OUT]
Platform(s) (iOS, Android, or both?): [FILL THIS OUT]

@6axter82
Copy link

@xcarpentier

Nodejs version: v6.9.0
React version: 16.2.0
React Native version: 0.52.0
react-native-gifted-chat version: ^0.3.0
Platform(s) (iOS, Android, or both?): using both, but only iOS is broken

The behaviour: tapping input area toggles the keyboard on iOS and the text area swipes together with the keyboard. At the end of swipe, the text area and the whole chat view behind the keyboard jumps to the initial position at the bottom, the keyboard remains shown on the screen. now, typing any character but 'space' brings the textinput to the top of the keyboard. and sending works as expected. look the gif i attached:

example

@xcarpentier
Copy link
Collaborator

Which kind of customizations did you have?

@6axter82
Copy link

6axter82 commented Jan 29, 2018

@xcarpentier, why do you think it is smth with customisation? The android version works just as expected with this customisation,..

<GiftedChat
	text={this.state.text}
	style={{flex: 1}}
	messages={this.state.sortedEvents}
	onSend={(messages) => this._onMessageSend(messages)}
	onInputTextChanged={(text) => this._checkForMentions(text)}
	textInputProps={{}}
	dateFormat={strings.dateFormat}
	timeFormat={strings.timeFormat}
	placeholder={strings.placeholder}
	locale={strings.getLanguage()}
	showUserAvatar={true}
	renderAvatarOnTop={false}
	renderBubble={this.renderBubble}
	renderSystemMessage={this.renderSystemMessage}
	renderChatFooter={this.renderChatFooter}
	keyboardShouldPersistTaps='never'
	user={{
		_id: user.id,
		name: user.firstName,
		avatar: user.hasProfilePicture ? user.avatarUrl : null
	}}
/>

@xcarpentier
Copy link
Collaborator

Just to be able to reproduce...

@6axter82
Copy link

@xcarpentier if you need more info for reproducing the bug, please let me know

@6axter82
Copy link

@davista123 thanks for your input but your proposal doesn't fix it, on Android it got even worse. Also I need a fix for an iOS

@6axter82
Copy link

@xcarpentier and @davista123 I have done my own fix, check it and give me some response if it is a candidate for the release. This fixes for me the iOS version, as my Android did work properly without any change.
The magic number 45 I have taken from scanning some tickets in the web. I can't find the source but someone suggested to use this value for the inputtext bar height.

Added the following to the code:

componentWillMount() {
	if (Platform.OS === 'ios') {
		this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow',
                      this._keyboardDidShow);
		this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide',
                      this._keyboardDidHide);
	}
}

_keyboardDidShow = (e) => {
	let keyboardHeight = e.endCoordinates.height;
	this.setState({
		minInputToolbarHeight: keyboardHeight + 45,
	});
}

_keyboardDidHide = () => {
	this.setState({
		minInputToolbarHeight: 45,
	});
}

componentWillUnmount() {
	if (Platform.OS === 'ios') {
		this.keyboardDidShowListener.remove();
		this.keyboardDidHideListener.remove();
	}
}

render() {
	let platformConf = Platform.OS === 'ios' ? {
		minInputToolbarHeight: this.state.minInputToolbarHeight,
		bottomOffset: 0,
	} : {};
	return (
		<GiftedChat
			text={this.state.text}
			style={{flex: 1}}
			messages={this.state.sortedEvents}
			onSend={(messages) => this._onMessageSend(messages)}
			onInputTextChanged={(text) => this._checkForMentions(text)}
			textInputProps={{}}
			dateFormat={strings.dateFormat}
			timeFormat={strings.timeFormat}
			placeholder={strings.placeholder}
			locale={strings.getLanguage()}
			showUserAvatar={true}
			renderAvatarOnTop={false}
			renderBubble={this.renderBubble}
			renderSystemMessage={this.renderSystemMessage}
			renderChatFooter={this.renderChatFooter}
			keyboardShouldPersistTaps='never'
			{...platformConf}
			user={{
				_id: user.id,
				name: user.firstName,
				avatar: user.hasProfilePicture ? user.avatarUrl : null
			}}/>
	);
}

@Osama92
Copy link

Osama92 commented Jan 7, 2019

use yarn add react-native-keyboard-spacer or npm install react-native-keyboard-spacer.

@tapz
Copy link

tapz commented Jan 16, 2019

@Osama92 For me react-native-keyboard-spacer just adds a keyboard size gap between the chat and the keyboard.

@14bscsskazmi
Copy link

I am facing the same issue but only in android, I think IOS issue has been resolved with the latest react updates. I never faced this issue in IOS. Facing only in android so any one having the solution in android? please help!

@stale
Copy link

stale bot commented May 4, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 4, 2019
@stale stale bot closed this as completed May 11, 2019
@siddh1004
Copy link

siddh1004 commented Jun 4, 2019

` render() {
return

<GiftedChat

        messages={this.state.messages}
        onSend={messages => this.onSend(messages)}
        user={{
          _id: 1,
        }}
          ></GiftedChat>

        <KeyboardAvoidingView behavior={'padding'}/>
    </View>

}`

Add KeyboardAvoidingView after GiftedChat

@adamsolomon1986
Copy link

any updates on this?

@mkhoussid
Copy link

mkhoussid commented Oct 29, 2019

Seems to be an issue for Expo and Android. Issue described here: https://stackoverflow.com/questions/58606815/issue-with-gifted-chat-the-messages-jump-up-the-screen-on-text-input

I haven't been able to come up with a fix thus far.

Edit: Fixed it by removing forceGetKeyboardHeight

@zholmes1
Copy link

zholmes1 commented Jul 29, 2020

I would like to leave the solution that I created since this issue was a real pain for me. I tried all combinations of KeyboardAvoidingView with all different kinds of props, the forceGetKeyboardHeight and anything else I could find on the internet. Nothing worked.

Here was my solution:

const [paddingBottom, setPaddingBottom] = useState(0)

useEffect(() => {
  if (Platform.OS !== 'android' || __DEV__) {
    return
  }

  const keyboardShowListener = Keyboard.addListener(keyboardDidShow', event => {
    setPaddingBottom(event.endCoordinates.height + Constants.statusBarHeight)
  })
  
  const keyboardHideListener = Keyboard.addListener('keyboardDidHide', () => {
    setPaddingBottom(0)
  })

  return () => {
    keyboardShowListener.remove()
    keyboardHideListener.remove()
  }
}, [])

Then wrap up your GiftedChat view with the padding

<View style={{flex: 1, paddingBottom}}>
  <GiftedChat ...

This was the only way I could fix my issue.

I'm using Expo, React Navigation, React Native Paper BottomNavigation

@hugoh59
Copy link

hugoh59 commented Oct 28, 2020

Same issue here

@akhilsanker
Copy link

Hi,
Same issue
Any solution?

Thanks

@ilaven
Copy link

ilaven commented Dec 7, 2020

I am facing the same issue but only in android.

@woodcockjosh
Copy link

I had same issue. It turns out I had flexGrow: 1 on the input which was causing the problem for me.

@TriLuong
Copy link

TriLuong commented Apr 1, 2021

I added android:windowSoftInputMode="adjustResize" on AndroidManifest.xml, and it worked for me. There is an instruction Notes for Android in README

@israromar
Copy link

israromar commented Aug 14, 2021

I solved it by simply making use of minInputToolbarHeight property with platformConf as suggested by @6axter82
works like a charm.

render() {
let platformConf = Platform.OS === 'ios' ? {
minInputToolbarHeight: 40,
bottomOffset: 0,
} : {};
return (
<GiftedChat
text={this.state.text}
style={{flex: 1}}
messages={this.state.sortedEvents}
onSend={(messages) => this._onMessageSend(messages)}
onInputTextChanged={(text) => this._checkForMentions(text)}
textInputProps={{}}
dateFormat={strings.dateFormat}
timeFormat={strings.timeFormat}
placeholder={strings.placeholder}
locale={strings.getLanguage()}
showUserAvatar={true}
renderAvatarOnTop={false}
renderBubble={this.renderBubble}
renderSystemMessage={this.renderSystemMessage}
renderChatFooter={this.renderChatFooter}
keyboardShouldPersistTaps='never'
{...platformConf}
user={{
_id: user.id,
name: user.firstName,
avatar: user.hasProfilePicture ? user.avatarUrl : null
}}/>
);
}

@cisplRejjak
Copy link

cisplRejjak commented Jun 8, 2022

load old chat history after gifted chat is fully initialized, by using setTimeout with 2-sec delay at least

its works for me
componentDidMount(){
setTimeout(()=>{
this.getPreviousChat();
},3000)
}

@mudin
Copy link

mudin commented Dec 17, 2022

I fixed by wrapping GiftedChat with KeyboardAvoidingView.

<KeyboardAvoidingView
    flex={1}
    enabled={Platform.OS === 'android'}
    behavior="padding"
  >
    <GiftedChat
      ....  
    />
  </KeyboardAvoidingView>

Note that KeyboardAvoidingView is imported from native-base.
you can import from react-native directly

@kyushuInnovation
Copy link

Has this problem been resolved? I'm still having the same issue on Android.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests