reactjs - 在本机反应中,文本隐藏在键盘下
问题描述
嗨,我正在应用程序中创建一个聊天部分,但是当键盘打开时,我的消息显示在键盘下方,它不会将消息推送到键盘上方。我尝试了keyBoardAvoidingView但它对我不起作用。我也尝试在清单活动中使用android:windowSoftInputMode="adjustResize"但没有任何反应..
<View style={styles.container}>
{loading == true ? (
<View style={{marginVertical: hp('45%')}}>
<ActivityIndicator size="large" color={colors.primary} />
</View>
) : (
<View
style={{flex:1}}
>
<SafeAreaView>
<View style={styles.arrowBack}>
<TouchableOpacity
onPress={() => navigation.goBack()}
style={styles.backIcon}>
<Image source={require('../../images/back.png')} />
</TouchableOpacity>
<View style={styles.profileWrapper}>
<View style={styles.profileContent}>
<Text style={styles.profiletitle}>{item.name}</Text>
<Text style={styles.profileaddress}>{item.address}</Text>
</View>
</View>
</View>
</SafeAreaView>
<View
style={{
backgroundColor: '#fff',
height: hp('90%'),
borderTopLeftRadius: 40,
borderTopRightRadius: 40,
flex:1,justifyContent:'flex-end'
}}>
<View>
<ScrollView style={{width:'100%', flexGrow:1}}
ref={scrollRef}
>
<KeyboardAvoidingView
behavior={Platform.OS === 'ios'? 'padding':null}
>
<View style={{paddingTop:20, paddingHorizontal:20, paddingBottom:20, }} >
{
dataPrev()
}
</View>
<View>
{newMsgs()}
</View>
</KeyboardAvoidingView>
</ScrollView>
</View>
</View>
</View>
)}
<View style={{
flexDirection:'row',
borderBottomWidth:1, borderColor:colors.primary,
backgroundColor:'white'
}} >
<TouchableOpacity style={{width:'90%', }} >
<TextInput
placeholder="Type a message"
defaultValue={buyerMsg}
onChangeText={buyerMsg => setBuyerMsg(buyerMsg)}
/>
</TouchableOpacity>
<View style={{width:'20%', alignContent:'center', alignSelf:'center'}} >
<SendSvg onPress={()=>{sendmessage()}} />
</View>
</View>
</View>
我该怎么做才能将消息推送到键盘上方?我尝试使用keyboardavoidingView,但对我不起作用。
解决方案
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
<KeyboardAwareScrollView>
<View>
<TextInput />
</View>
</KeyboardAwareScrollView>
推荐阅读
- swift - Swift Combine:如何合并来自多个嵌套发布者的结果?
- javascript - 匹配 URL 中的数字
- javascript - 我们可以通过 react-router-dom 的链接中的“在新选项卡中打开”更改要打开的 URL 的值吗
- arrays - 如何访问对象内的共享首选项
- javascript - SecurityError:无法从“CSSStyleSheet”读取“cssRules”属性
- ios - 如何在数组数组中找到元素的第一个索引
- python - 无法安装 Spyder
- javascript - 如何更改数组内对象的值
- java - 无法从外部存储和其他文件夹(下载除外)上传/选择 Android 11 设备中的图像和文件附件
- python - 带有空字符串(默认语言环境)的 Python setlocale 给出“不支持的语言环境设置”