Skip to content

Commit

Permalink
fix: edge case with tabs still scrolling to top (#230)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrei Alecu <andreialecu@users.noreply.github.com>
  • Loading branch information
andreialecu and andreialecu authored Jan 15, 2022
1 parent 8d7d3ef commit dd13cbc
Showing 1 changed file with 12 additions and 4 deletions.
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

0 comments on commit dd13cbc

Please sign in to comment.