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

fix: edge case with tabs still scrolling to top #230

Merged
merged 1 commit into from
Jan 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
MutableRefObject,
useEffect,
} from 'react'
import { StyleSheet } from 'react-native'
import { ContainerRef, RefComponent } from 'react-native-collapsible-tab-view'
import Animated, {
cancelAnimation,
Expand Down Expand Up @@ -220,6 +221,7 @@ export function useScroller<T extends RefComponent>() {
) => {
'worklet'
if (!ref) return
//! this is left here on purpose to ease troubleshooting (uncomment when necessary)
// console.log(
// `${_debugKey}, y: ${y}, y adjusted: ${y - contentInset.value}`
// )
Expand Down Expand Up @@ -485,17 +487,23 @@ export const useScrollHandlerY = (name: TabName) => {

return isChangingPane
},
(result, previous) => {
if (result && result !== previous && focusedTab.value !== name) {
(isSyncNeeded, wasSyncNeeded) => {
if (
isSyncNeeded &&
isSyncNeeded !== wasSyncNeeded &&
focusedTab.value !== name
) {
let nextPosition = null
const focusedScrollY = scrollY.value[Math.round(indexDecimal.value)]
const tabScrollY = scrollY.value[tabIndex]
const areEqual = focusedScrollY === tabScrollY

if (!areEqual) {
const currIsOnTop = tabScrollY <= headerScrollDistance.value + 1
const currIsOnTop =
tabScrollY + StyleSheet.hairlineWidth <= headerScrollDistance.value
const focusedIsOnTop =
focusedScrollY <= headerScrollDistance.value + 1
focusedScrollY + StyleSheet.hairlineWidth <=
headerScrollDistance.value

if (revealHeaderOnScroll) {
const hasGap = accDiffClamp.value > tabScrollY
Expand Down