gpt4 book ai didi

javascript - React Native - FlatList 无法到达底部

转载 作者:行者123 更新时间:2023-11-29 10:27:35 25 4
gpt4 key购买 nike

我有一个键盘始终处于打开状态的面板,因为我不希望用户关闭它。在该面板中,我有一个如下所示的 FlatList:

<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 的全部内容的同时保持键盘打开(并禁用被关闭的能力)?

最佳答案

您可以添加一个键盘监听事件来获取键盘的高度。

this.keyboardWillShowListener = Keyboard.addListener('keyboardWillShow', (e) => {
this.setState({ keyboardHeight: e.endCoordinates.height, keyboardShow: true })
Animated.timing(this.visibleHeight, {
duration: e.duration,
toValue: 1,
easing: Easing.inOut(Easing.ease)
}).start()
})

这样看代码

<Animated.View style={Platform.OS === 'android' ? { flex: 1 } : {
height: this.visibleHeight.interpolate({
inputRange: [0, 1],
outputRange: [height - this.NavHeaderHeight, height - this.state.keyboardHeight - this.NavHeaderHeight]
})
}
} >
/*Your FlatList*/
</Animated.View>

希望对你有用

关于javascript - React Native - FlatList 无法到达底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55013045/

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