Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tcorreiaubi opened this issue Feb 5, 2021 · 2 comments · Fixed by #93
Closed

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

tcorreiaubi opened this issue Feb 5, 2021 · 2 comments · Fixed by #93
Labels
question Further information is requested

Comments

@tcorreiaubi
Copy link
Contributor

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

@tcorreiaubi tcorreiaubi added the question Further information is requested label Feb 5, 2021
@andreialecu
Copy link
Collaborator

andreialecu commented Feb 6, 2021

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

@tcorreiaubi
Copy link
Contributor Author

tcorreiaubi commented Feb 8, 2021

@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(facebook/react-native#21718) handler which is where the snappingTo.value is updated

@PedroBern PedroBern linked a pull request Feb 9, 2021 that will close this issue
PedroBern added a commit that referenced this issue Feb 9, 2021
Version 4.0 with api refactoring and dynamic tabs.

BREAKING CHANGES:

createCollapsibleTabs() no longer exists. Instead the library exports different components (Container, Tab, ScrollView, ListView) which can be nested like normal react components.
refMap no longer exists, and creating refs is no longer necessary (it's all handled internally)
ScrollView/FlatList now forward their refs, so the caller can just tap into their ref prop
the existing onIndexChange was renamed to onTabChange, and a separate onIndexChange was implemented that just returns the new index (as a number)
diffClampEnabled was changed to revealHeaderOnScroll
redundant prop snapEnabled was removed, instead snapThreshold is number | null | undefined. If not a number, then snap is not enabled. Setting it to 0.5 will result in snapping in the middle, like in the previous version.

Fixes: #100, #98, #94, #88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants