How to get currently visible index in RN flat list

前端 未结 5 1074
温柔的废话
温柔的废话 2021-02-01 01:54

I have a horizontal flat list where each item is width:300 All I am trying to do is to get index of currently visible item.



        
5条回答
  •  终归单人心
    2021-02-01 02:41

    With related to @fzyzcjy's and @Roman's answers. In react, 16.8+ you can use uscCallback to handle the changing onViewableItemsChanged on the fly is not supported error.

    function MyComponent(props) {
        const _onViewableItemsChanged = useCallback(({ viewableItems, changed }) => {
            console.log("Visible items are", viewableItems);
            console.log("Changed in this iteration", changed);
        }, []);
    
        const _viewabilityConfig = {
            itemVisiblePercentThreshold: 50
        }
    
        return ;
    }
    

提交回复
热议问题