PedroBern / react-native-collapsible-tab-view

A cross-platform Collapsible Tab View component for React Native
MIT License
834 stars 162 forks source link

Force a tab to start at a certain scroll position #98

Closed tcorreiaubi closed 3 years ago

tcorreiaubi commented 3 years ago

Hey(once again), I was trying to force a tab to always start at a certain scroll position, this is a really specific behavior, what I tried to do was on the indexChange call the scrollTo on that tab to place it on the position where I need, example

      onIndexChange={(onChangeData) => {
            const {tabName} = onChangeData;
            if (tabName === TabKey.MAP) {
              (mapRef.current as ScrollView).scrollTo({
                y: IMAGE_SLIDER_HEIGHT - HEADER_BAR_HEIGHT,
                animated: true,
              });
            }
          }}

This works great for the current tab but the others tab don't sync their position properly, should I call another function or just update some value from the context? Thanks once again

andreialecu commented 3 years ago

This will probably be fixed by #93, and #99 also makes it simpler.

tcorreiaubi commented 3 years ago

@andreialecu Hey, nice to know, while trying to debug it I noticed that this only occurs if snap is enabled.

After some more debugging I believe that the root cause is .scrollTo who doesn't trigger the onMomentumEnd(https://github.com/facebook/react-native/issues/21718) handler which is where the snappingTo.value is updated