【发布时间】:2020-12-15 04:48:03
【问题描述】:
我正在尝试使用 FlatList 在 React Native 上构建新闻提要。我希望它类似于Tik Tok的提要,FlatList中的每个项目都占据整个屏幕。
现在它具有我想要的正确布局,但问题是提要不可滚动。
由于某种原因,如果我将孩子设置为 height: '100%',FlatList 将无法滚动。当我将其更改为height: 1000 时,它是可滚动的,但我不想硬编码高度。
如果您能提供任何帮助,我们将不胜感激!
这是提要组件:
const Feed = () => {
const renderItem = ({ item, index }) => {
return (
<FeedItem
id={item.id.toString()}
videoUrl={item.videoUrl}
index={index}
/>
)
}
return (
<FlatList
style={styles.container}
contentContainerStyle={styles.children}
data={someData}
renderItem={renderItem}
keyExtractor={(item, index) => item.id.toString()}
/>
);
}
// styles
const styles = StyleSheet.create({
container: {
display: 'flex',
flexDirection: 'column',
height: '100%'
},
children: {
flexGrow: 1,
}
})
这是提要中的每个项目:
import { Video } from 'expo-av';
const FeedItem = ({ id, videoUrl, index }) => {
return (
<Video
source={{ uri: videoUrl }}
style={styles.backgroundVideo}
/>
)
}
const styles = StyleSheet.create({
backgroundVideo: {
height: '100%' // FIXME: problematic
},
});
【问题讨论】:
-
你试过
Dimensions.get('window').height;吗? -
是的,我试过了。但这并没有考虑到底部导航。我希望它占据屏幕而不与导航栏重叠。
-
嗨,正面临这个确切的问题。你有没有找到解决这个问题的方法?
-
嘿 Chogo,我最终使用了来自 @react-native-community/viewpager 的 ViewPager。类似于
标签: css reactjs react-native react-native-ios