【发布时间】:2019-10-13 13:04:53
【问题描述】:
当我开始输入一些消息时,标题和聊天容器都会向上移动。
我曾尝试在我的视图容器中使用 KeyboardAvoidingView,但是它不起作用,我不确定 KeyboardAvoidingView 是否是在视图中控制键盘的最佳解决方案并且不熟悉它。
下面是我的代码:
render() {
const { myName, user, nome, message } = this.props;
return (
<View style={STYLES.main}>
<Animatable.View
style={STYLES.container}
animation={FADEIN}
easing='ease-in'
duration={1000}
>
<RenderHeader3 press={() => Actions.detalhes()} hcolor={'#298CFF'} color={'#FFF'} text={nome} icon={null} isize={null} />
<ScrollView contentContainerStyle={{ paddingHorizontal: 10, paddingTop: 5 }}>
<KeyboardAvoidingView
style={{ flex: 1 }}
behavior={null}
keyboardVerticalOffset={60}
>
<ListView
enableEmptySections
dataSource={this.dataSource}
renderRow={this.renderRow}
/>
</KeyboardAvoidingView>
</ScrollView>
<View style={{ flexDirection: 'row', backgroundColor: '#1A1C27', padding: 10 }}>
<View style={{ flex: 4 }}>
<TextInput
style={[STYLES.titleTxt, { color: '#000', backgroundColor: '#FFF', borderRadius: 40, paddingLeft: 13, paddingRight: 10 }]}
multiline
value={message}
onChangeText={(texto) => this.props.modificaMensagem(texto)}
/>
</View>
<View style={{ justifyContent: 'center', alignItems: 'center', paddingLeft: 10 }}>
<TouchableOpacity
style={{
height: 40,
width: 40,
borderRadius: 40,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#298CFF',
paddingRight: 2
}}
activeOpacity={0.5}
onPress={() => this.props.createChat(myName, user, nome, message)}
>
<CustomIcon
name='paper-plane'
size={25}
color='#FFF'
/>
</TouchableOpacity>
</View>
</View>
</Animatable.View>
</View>
);
} }
【问题讨论】:
-
KeyboardAvoidingView 有 3 种行为类型 enum('height', 'position', 'padding') 但您将其设置为 null
-
嗨,发现同样的问题。我使用 KeyboardAwareScrollView 对 iOS 进行了整理,但对于 Android,我使用的是 KeyboardAvoidingView 并且无法以某种方式定义键盘和文本输入之间的边距。您是否找到任何解决方案或解决方法?谢谢!
标签: react-native keyboard