[英]Disable only horizontal scrolling in FlatList
How can I disable only horizontal scrolling on my FlatList?如何在我的 FlatList 上仅禁用水平滚动? Putting it to false doesnt work.
将其设置为 false 不起作用。 I want to be able to scroll it vertically but not horizontally.
我希望能够垂直滚动而不是水平滚动。
<FlatList
data={data.me.friends.nodes}
//horizontal={false}
//scrollEnabled={false}
renderItem={({ item }) => (
<FriendItem friend={item} originatorId={data.me.id}/>
)}
keyExtractor={(item) => item.id.toString()}
ListEmptyComponent={NoFriendsContainer}
/>
FriendItem's return. FriendItem 的回归。 FriendItem is the renderItem which is being used in the FlatList:
FriendItem 是在 FlatList 中使用的 renderItem:
return (
<View style={styles.item}>
<TouchableOpacity
onPress={() =>
navigation.navigate('FriendDetails')
}>
<Thumbnail
style={styles.thumbnail}
source={{
uri:
'https://cdn4.iconfinder.com/person-512.png',
}}></Thumbnail>
</TouchableOpacity>
<View style={styles.nameContainer}>
<Text style={styles.userName}>{userName}</Text>
</View>
<View style={styles.deleteButtonContainer}>
<Button
rounded
style={styles.deleteButton}
onPress={() => onDeleteFriend(originatorId, friend.id)}>
<Icon name="trash-o" size={moderateScale(20)} color="black" />
</Button>
</View>
</View>
);
};
Styles: Styles:
export const styles = StyleSheet.create({
item: {
backgroundColor: 'white',
borderRadius: moderateScale(20),
padding: moderateScale(20),
marginVertical: moderateScale(8),
marginHorizontal: 16,
height: moderateScale(110),
width: moderateScale(360),
justifyContent: 'space-between',
flexDirection: 'row',
},
userName: {
paddingRight: 55,
paddingLeft: 10,
paddingTop: 20,
},
deleteButton: {
backgroundColor: '#31C283',
width: moderateScale(45),
justifyContent: 'center',
},
deleteButtonContainer: {
paddingTop: 12,
marginRight: 2,
},
thumbnail: {
height: 85,
width: 85,
marginLeft: 2,
paddingRight: 0,
position: 'relative',
},
nameContainer: {
flexDirection: 'row',
},
});
Edit:编辑:
When there are 4 items, it seems to be okay but as soon as another item is added to the list, the last item is disturbed and is overlapped with the footer?当有 4 个项目时,似乎还可以,但是一旦将另一个项目添加到列表中,最后一个项目就会受到干扰并与页脚重叠? of the app.
的应用程序。
It should actually be behind it so that we can scroll down and see the next items.它实际上应该在它后面,以便我们可以向下滚动并查看下一个项目。
horizontal
parameter is not related to horizontal scroll. horizontal
参数与水平滚动无关。
https://reactnative.dev/docs/flatlist#horizontal https://reactnative.dev/docs/flatlist#horizontal
If true, renders items next to each other horizontally instead of stacked vertically.
Your 'scroll issue' is your FriendItem
, the issue is the width: moderateScale(360)
.您的“滚动问题”是您的
FriendItem
,问题是width: moderateScale(360)
。
If you want your item be full width, with margin, you can just remove it.如果您希望您的项目是全宽的,带有边距,您可以将其删除。
Example with moderateScale(360)
moderateScale(360)
的示例
Example removing width
示例移除
width
item: {
backgroundColor: "white",
borderRadius: moderateScale(20),
padding: moderateScale(20),
marginVertical: moderateScale(8),
marginHorizontal: 16,
height: moderateScale(110),
justifyContent: "space-between",
flexDirection: "row",
}
Hope it helps you.希望它可以帮助你。 Regards,
问候,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.