gpt4 book ai didi

react-native - 如何让 FlatList 填充高度?

转载 作者:行者123 更新时间:2023-12-04 04:37:45 27 4
gpt4 key购买 nike

import React from 'react';
import {SafeAreaView, KeyboardAvoidingView, FlatList, View, Text, TextInput, Button, StyleSheet } from 'react-native';


export default class Guest extends React.Component {
state={
command: '',
}
constructor(props) {
super(props)
this.onChangeText = this.onChangeText.bind(this)
this.onKeyPress = this.onKeyPress.bind(this)
this.onSubmit = this.onSubmit.bind(this)
}
onChangeText(text){
const command = text.replace('\n', '');
this.setState({
command: command
})
}
onKeyPress(e){
}
onSubmit(){
}
render() {
return(
<SafeAreaView style={styles.safeAreaView}>
<KeyboardAvoidingView style={styles.keyboardAvoidingView} keyboardVerticalOffset={88} behavior="padding" enabled>
<FlatList
inverted={true}
keyboardShouldPersistTaps='always'
keyboardDismissMode='interactive'
ref='list'
style={styles.flatList}
data={[1, 2, 3]}
renderItem={(props) => {
return(<View><Text>{props.item}</Text></View>)
}}
/>
<TextInput
command={this.state.command}
onChangeText={this.onChangeText}
onKeyPress={this.onKeyPress}
onSubmit={this.onSubmit}
style={styles.textInput}
/>
</KeyboardAvoidingView>
</SafeAreaView>
)
}
}


const styles = StyleSheet.create({
safeAreaView:{
backgroundColor:"#ffffff",
},
keyboardAvoidingView:{
},
flatList:{
backgroundColor: 'red',
},
textInput:{
backgroundColor: 'yellow'
}
})

enter image description here

我希望红色 flatList 填充屏幕(但保持黄色文本框的高度)。

我试过 flex:1在 flatList 上,但它只是让它消失了。

最佳答案

FlatList 继承了 ScrollView 的 props,所以 ScrollView 的解决方案将起作用:

<FlatList
contentContainerStyle={{ flexGrow: 1 }}
{...otherProps}
/>

Here是上述解决方案的原始 Github 问题。

编辑:FlatList 的 parent View 应该有 flex: 1以他们的风格。
safeAreaView:{
backgroundColor:"#ffffff",
flex: 1
},
keyboardAvoidingView:{
flex: 1
},

关于react-native - 如何让 FlatList 填充高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52286459/

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