Created
April 23, 2023 13:10
-
-
Save lrsbt/96da2dbcf2f76a729e70a192106ffaeb to your computer and use it in GitHub Desktop.
React-Native, flatlist onViewableItemsChanged get Index of page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Quicker bi-directional onViewableItemsChanged | |
const [activeIndex, setActiveIndex] = useState(0); | |
const onViewableItemsChanged = useRef(({ viewableItems, changed }) => { | |
if (viewableItems?.length >= 2 && changed?.[0]?.isViewable) { | |
setActiveIndex(changed?.[0].index); | |
} else { | |
if (viewableItems?.[0]) setActiveIndex(viewableItems[0].index); | |
} | |
}).current; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment