Created
March 24, 2021 15:40
-
-
Save Saad-Bashar/1bff1b2c46017b5f5e8a5be32673e723 to your computer and use it in GitHub Desktop.
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
| /* | |
| This is our tab buttons, when the user press on the tab buttons | |
| we first scroll to that index, then we set the tab active | |
| */ | |
| <TouchableOpacity | |
| onPress={() => { | |
| listRef.current.scrollToIndex({ | |
| animated: true, | |
| viewOffset: 50 * index, | |
| index: index, | |
| }); | |
| setActiveTab(item) | |
| }} | |
| style={{ padding: 6, paddingVertical: 20 }}> | |
| <Text style={activeTab === item ? { opacity: 1, fontWeight: "bold" } : { opacity: 0.4 }}> | |
| {item} | |
| </Text> | |
| </TouchableOpacity> | |
| /* | |
| again we track active tab, so when the active tab changes, | |
| we scroll the carousel to the first item of that tab category | |
| */ | |
| React.useEffect(() => { | |
| if(activeTab) { | |
| ref.current.snapToItem(DATA.map(function(e) { return e.category; }).indexOf(activeTab)); | |
| } | |
| }, [activeTab]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment