gpt4 book ai didi

react-native - React Native – FlatList 滚动到底部,键盘向上

转载 作者:行者123 更新时间:2023-12-04 09:33:57 32 4
gpt4 key购买 nike

<KeyboardAvoidingView style={{ flex: 1 }}>
<FlatList
// This keeps the keyboard up and disables the user's ability to hide it.
keyboardShouldPersistTaps="handled"
data={this.state.examples}
keyExtractor={(item, index) => index.toString()}
renderItem={this._renderItem}
contentContainerStyle={{ flex: 1}}
/>
</KeyboardAvoidingView>
到目前为止一切顺利,我已经实现了我想要的。然而,当键盘打开时——它隐藏了由 FlatList 呈现的项目的底部。用户无法向上滚动并查看最后一个项目,因为他们留在键盘后面。
如何在能够查看和滚动 FlatList 的整个内容的同时保持打开的键盘(并禁用被解雇的能力)?

最佳答案

我相信您在 ios 中遇到了这个问题。对于平面列表的键盘处理,您可以尝试 react-native-keyboard-aware-scroll-view .
您可以通过使用键盘感知 ScrollView 添加此属性来防止键盘关闭。

keyboardShouldPersistTaps={"handled"}
使用 KeyboardAwareScrollView 试试这个属性
引用下面的片段
 <KeyboardAwareScrollView
keyboardShouldPersistTaps={"handled"}
extraScrollHeight={Platform.OS == "ios" ? hp("4%") : hp("0%")}
extraHeight={Platform.OS == "ios" ? hp("9%") : 0}
style={{ flex: 1, backgroundColor: "white" }}
behavior={Platform.OS == "ios" ? "position" : null}
resetScrollToCoords={{ x: 0, y: 0 }}
scrollEnabled={false}
showsVerticalScrollIndicator={false}
showsHorizontalScrollIndicator={false}
keyboardOpeningTime={1}
enableOnAndroid={true}
contentContainerStyle={{ flex: 1 }}
>
<View style = {{
flex: 1,
height: .. }}>
<FlatList
... />
</View >

</KeyboardAwareScrollView>
仍然面临问题,请不要犹豫,回复我。

关于react-native - React Native – FlatList 滚动到底部,键盘向上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62684039/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com