我在 Android 上遇到 KeyboardAvoidingView 问题。它适用于 iOS。我的屏幕在屏幕的上半部分有一个 View 组件,可能会或可能不会影响它。我已经尝试删除这些组件中的每一个,但 KeyboardAvoidingView 仅在我删除占据屏幕 60% 的组件时才有效。此组件是来自“react-native-youtube”的 YouTube 播放器,它具有 flex: 1
样式。
我的代码看起来像这样..
<KeyboardAvoidingView
behavior="padding"
keyboardVerticalOffset={200}
>
<View style={styles.first}>
<View style={styles.second}>
<TouchableHighlight />
<View style={styles.third}>
<TextInput
style={styles.textInput}
maxLength={80}
autoGrow={true}
maxHeight={130}
multiline={true}
editable={true}
onChangeText={onChange}
value={descriptionText}
autoFocus={true}
keyboardType={'default'}
autoCorrect={false}
placeholder={'Send a word'}
underlineColorAndroid={white}
selectionColor={purple}
returnKeyType={'send'}
onSubmitEditing={handleSubmit}
/>
</View>
</View>
</View>
<KeyboardAvoidingView/>
first: {
flexDirection: 'column',
justifyContent: 'flex-start',
position: 'relative',
marginTop: 0,
},
second: {
width: screenWidth,
flexDirection: 'row',
alignItems: 'center',
paddingTop: 5,
paddingBottom: 9,
},
third: {
flexDirection: 'row',
borderTopLeftRadius: 10,
borderBottomLeftRadius: 10,
paddingBottom: 5,
paddingLeft: 10,
paddingRight: 10,
width: screenWidth - 102,
minHeight: 36,
alignItems: 'center',
},
textInput: {
textAlign: 'left',
fontSize: 14,
fontWeight: '400',
flex: 1,
padding: 0,
margin: 0,
}
这里有什么可能会影响 KeyboardAvoidingView
的功能吗?我已经尝试删除 behavior="padding"
了,因为 React Native 文档提到当删除该 Prop 时它在 android 上运行得更好。
谢谢!
最佳答案
尝试向所有样式添加 flex 可能会有所帮助,也许在 KeyboardAvoidingView 中也是如此。
<KeyboardAvoidingView
style={{flex: 1}}
keyboardVerticalOffset={0}
behavior={'padding'}
>
关于android - 即使删除了行为,KeyboardAvoidingView 也无法在 Android 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49985076/