Last active
March 24, 2021 15:24
-
-
Save Saad-Bashar/9d3fd2c484c452b760eadf8445b6a3b5 to your computer and use it in GitHub Desktop.
tab-carousel-init
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
| //DUMMY DATA | |
| const DATA = [ | |
| { | |
| category: "Home & Living", | |
| image: require('./assets/f1.jpg') | |
| }, | |
| { | |
| category: "Home & Living", | |
| image: require('./assets/f2.jpg') | |
| }, | |
| { | |
| category: "Home & Living", | |
| image: require('./assets/f4.jpg') | |
| }, | |
| ...... | |
| ]; | |
| const TABS = ["Home & Living", "Electronics & Gadgets", "Sports & Outdoors", "Appliances", "Books"] | |
| const [index, setIndex] = React.useState(0) | |
| const [activeTab, setActiveTab] = React.useState(TABS[0]); | |
| const ref = React.useRef(); | |
| const listRef = React.useRef(); | |
| const renderTabButtons = () => { | |
| return ( | |
| <View> | |
| <FlatList | |
| ref={listRef} | |
| horizontal={true} | |
| data={TABS} | |
| contentContainerStyle={{ paddingHorizontal: 16, marginBottom: 16 }} | |
| showsHorizontalScrollIndicator={false} | |
| keyExtractor={(item, index) => index.toString()} | |
| renderItem={({ item, index }) => { | |
| return ( | |
| <TouchableOpacity | |
| onPress={() => {}} | |
| style={{ padding: 6, paddingVertical: 20 }} | |
| > | |
| <Text> | |
| {item} | |
| </Text> | |
| </TouchableOpacity> | |
| ); | |
| }} | |
| /> | |
| </View> | |
| ); | |
| }; | |
| return ( | |
| <SafeAreaView style={styles.container}> | |
| <View>{renderTabButtons()}</View> | |
| <Carousel | |
| index={index} | |
| inactiveSlideOpacity={0.4} | |
| itemWidth={width * 0.85} | |
| onBeforeSnapToItem={onChangeIndex} | |
| sliderWidth={width} | |
| activeAnimationType="spring" | |
| data={DATA} | |
| renderItem={renderItem} | |
| ref={ref} | |
| /> | |
| <StatusBar style="auto" /> | |
| </SafeAreaView> | |
| ); | |
| const styles = StyleSheet.create({ | |
| container: { | |
| flex: 1, | |
| backgroundColor: "#fff", | |
| marginTop: 40, | |
| }, | |
| item: { | |
| height: height * 0.6, | |
| borderRadius: 12, | |
| overflow: 'hidden', | |
| }, | |
| itemImage: { | |
| height: '100%', | |
| width: '100%', | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment