How do I center an item within a React Native ListView?

后端 未结 2 1331
南方客
南方客 2021-02-10 08:12

I\'m trying to center an item within a horizontal listView when selected. My current strategy is to first measure the item and scroll to the x coordinates of the referenced item

2条回答
  •  你的背包
    2021-02-10 09:10

    flatlistRef.current.scrollToIndex({
                        animated: true,
                        index,
                        viewOffset: Dimensions.get('window').width / 2.5,
                      });
    

    You can try to put viewOffset inside the scrollToIndex property, it will handle your component offset, I use 2.5 to make it in middle of screen , because I show 5 item each section and one of focused item will be in middle of screen

提交回复
热议问题