简体   繁体   English

平面列表不滚动

[英]Flatlist is not scrolling

i have a flatlist but it is not scrollable, first i set the height of it's parent container to screen height then i learned that it was a mistake to do so and also i didn't use flex:1 on any container still i can't scroll down.我有一个平面列表但它不可滚动,首先我将它的父容器的高度设置为屏幕高度然后我了解到这样做是错误的而且我没有在任何容器上使用 flex:1 我仍然可以'向下滚动。

so how to set the height of the flatlist to cover the entire screen and still be scrollable那么如何设置平面列表的高度以覆盖整个屏幕并且仍然可以滚动

 return( <LinearGradient style={DocumentStyle.box} colors={['#053f5c','#00b1b2',"#429ebd"]}> <DrawerIcon/> {isEmpty? <View style={{flex:1}}> <View style={DocumentStyle.conditions}> <Icon style={{flex:.3,opacity:.3,fontSize:125,fontWeight:'bold'}} name="file-pdf-o" color="#666"/> </View> </View>: <View> <DrawerIcon/> <SafeAreaView> <View style={DocumentStyle.searchBar}> <Icon style={DocumentStyle.searchIconStyle} name="search" color="#666"/> <TextInput style={DocumentStyle.searchText} value={search} placeholder="Rechercher un fichier" underlineColorAndroid='transparent' onChangeText={(text)=>searchFile(text)} /> </View> <View style={DocumentStyle.secondContainer}> <FlatList style={DocumentStyle.flatstyle} keyExtractor={(item)=>item['id']} data={filteredfile} renderItem={renderItem} onRefresh={()=>onRefresh()} refreshing={refresh} /> </View> </SafeAreaView> </View> } </LinearGradient> );

 import {StyleSheet,Dimensions} from 'react-native'; const width=Dimensions.get('window').width const height=Dimensions.get('window').height const DocumentStyle=StyleSheet.create({ box: { width:width, height: height, }, secondContainer:{ backgroundColor:'white', }, flatitem:{ backgroundColor:"white", shadowColor:'#000', shadowOffset:{ width:0, height:2, }, shadowOpacity:0.25, elevation: 5, color:'#666', padding:10, flexDirection:'row', justifyContent:'space-between' }, itemtext:{ flex:1, fontSize:18, color:'#666', padding:10, textAlign:'left' }, pdf:{ fontSize:25, padding:10, }, ellipsis:{ fontSize:20, paddingTop:15, color:'#17224d' }, searchBar:{ marginTop:60, borderWidth:0.5, alignSelf:'stretch', borderColor:'#17224d', borderRadius:15, padding:2, margin:10, flexDirection:'row', alignItems:'center', backgroundColor:"#fff" }, searchText:{ }, searchIconStyle:{ alignSelf:'flex-start', fontSize:18, alignSelf:'auto', marginRight:10, marginLeft:10, opacity:0.5, }, conditions:{ flex:1, justifyContent:'center', alignItems:'center', alignContent:'center', }, conditionText:{ color:'#666', fontSize:18 } }) export default DocumentStyle

Set flex:1 style to all parents of FlatList and also set contentContainerStyle to FlatList like below:将 flex:1 样式设置为 FlatList 的所有父级,并将 contentContainerStyle 设置为 FlatList,如下所示:

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

I think your problem might be related to view hierarchy, your list is children of a LinearGradient component (to have a gradient background I suppose) and LinearGradient is blocking touch events to children views.我认为您的问题可能与视图层次结构有关,您的列表是LinearGradient组件的子项(我想具有渐变背景)并且LinearGradient正在阻止对子视图的触摸事件。

To prevent that, add pointerEvents={"none"} prop to LinearGradient .为防止这种情况,请将pointerEvents={"none"}添加到LinearGradient

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM