0

I created top tabs with scroll view(image below). I want when user click to week 4 or next week which is hidden currently it will scroll to that week. I tried it but it's not working properly Can anyone tell me how to do that or there is any package for that?

Here is My code

  const scrollViewRef = useRef(null);

  const toNextPage = (index: number) => {
    scrollViewRef.current?.scrollTo({
      x: (Dimensions.get('window').width / 2) * index,
      animated: true,
    });
  };
.......
      <ScrollView
        ref={scrollViewRef}
        showsHorizontalScrollIndicator={false}
        horizontal={true}
        style={styles.scrollView}>
        {tabsData.map((item, index) => (
          <TopTabsCont
            item={item}
            index={index}
            key={index}
            selectedIndex={selectedIndex}
            containerStyle={containerStyle}
            onPress={(index: number) => {
              setSelectedIndex(index);
              toNextPage(index);
            }}
          />
        ))}
      </ScrollView>

enter image description here

Kanwarjeet Singh
  • 144
  • 1
  • 12

0 Answers0