[英]React Native Gifted Chat on Expo on Android input is covered by keyboard
I'm using a react-native gifted chat for my application chat.我正在为我的应用程序聊天使用 react-native 天才聊天。 But the text input is covered by the keyboard so I can't see what I'm typing.
但是文本输入被键盘覆盖,所以我看不到我在输入什么。
I'm using react-native version 0.60.10.我正在使用本机版本 0.60.10。 Expo version 32.0.13.
世博会版本 32.0.13。 Android-based phone for testing.
用于测试的基于 Android 的手机。 I tried solutions with keyboardAvoidingView and KeyboardSpacer but it still not working.
我尝试了使用 keyboardAvoidingView 和 KeyboardSpacer 的解决方案,但它仍然无法正常工作。
Looking forward hearing any advice.期待听到任何建议。 Any advice would be very great.
任何建议都会非常好。 This is screenshot
这是截图
Source Code源代码
render() {
const {navigation} = this.props;
return (
<>
<HeaderBack headerWrapper={{height: 80}} headerSubWrapper={{marginTop: 30}} navigation={navigation}/>
<GiftedChat
style={{paddingHorizontal: 20}}
isTyping={true}
messages={this.state.messages}
onSend={messages => this.onSend(messages)}
user={{
_id: 1,
}}
/>
</>
);
}
Try this updated code试试这个更新的代码
componentWillMount() {
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() {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}
render() {
const {navigation} = this.props;
let platformConf = Platform.OS === 'android' ? {
minInputToolbarHeight: this.state.minInputToolbarHeight,
bottomOffset: 0,
} : {};
return (
<GiftedChat
style={{flex: 1}}
messages={this.state.messages}
onSend={messages => this.onSend(messages)}
onInputTextChanged={(text) => this._checkForMentions(text)}
keyboardShouldPersistTaps='never'
{...platformConf}
user={{
_id: 1,
}}/>
);
}
If the above method does not working you can easily fix using react-native-keyboard-spacer
Link如果上述方法不起作用,您可以使用
react-native-keyboard-spacer
Link轻松修复
Also some users fix this by removing forceGetKeyboardHeight还有一些用户通过删除forceGetKeyboardHeight 来解决这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.