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: iOS issues when header height is undefined #126

Merged
merged 2 commits into from
Feb 13, 2021
Merged
Show file tree
Hide file tree
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
36 changes: 19 additions & 17 deletions src/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -504,23 +504,25 @@ const Container = React.forwardRef<CollapsibleRef, CollapsibleProps>(
)}
</View>
</Animated.View>
<AnimatedFlatList
// @ts-expect-error problem with reanimated types, they're missing `ref`
ref={containerRef}
initialScrollIndex={index.value}
data={data}
keyExtractor={keyExtractor}
renderItem={renderItem}
horizontal
pagingEnabled
onScroll={scrollHandlerX}
showsHorizontalScrollIndicator={false}
getItemLayout={getItemLayout}
scrollEventThrottle={16}
bounces={false}
{...pagerProps}
style={[pagerStylez, pagerProps?.style]}
/>
{headerHeight !== undefined && (
<AnimatedFlatList
// @ts-expect-error problem with reanimated types, they're missing `ref`
ref={containerRef}
initialScrollIndex={index.value}
data={data}
keyExtractor={keyExtractor}
renderItem={renderItem}
horizontal
pagingEnabled
onScroll={scrollHandlerX}
showsHorizontalScrollIndicator={false}
getItemLayout={getItemLayout}
scrollEventThrottle={16}
bounces={false}
{...pagerProps}
style={[pagerStylez, pagerProps?.style]}
/>
)}
</Animated.View>
</Context.Provider>
)
Expand Down
14 changes: 3 additions & 11 deletions src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ export const useScrollHandlerY = (
contentHeights,
} = useTabsContext()

const isDragging = useSharedValue(false)

/**
* Helper value to track if user is dragging on iOS, because iOS calls
* onMomentumEnd only after a vigorous swipe. If the user has finished the
Expand All @@ -258,8 +256,6 @@ export const useScrollHandlerY = (
'worklet'
if (!enabled) return

if (isDragging.value) return

if (typeof snapThreshold === 'number') {
if (revealHeaderOnScroll) {
if (accDiffClamp.value > 0) {
Expand Down Expand Up @@ -402,15 +398,15 @@ export const useScrollHandlerY = (
cancelAnimation(accDiffClamp)

isSnapping.value = false
isDragging.value = true
isScrolling.value = 0
isGliding.value = false

if (IS_IOS) cancelAnimation(afterDrag)
},
onEndDrag: () => {
if (!enabled) return

isGliding.value = true
isDragging.value = false

if (IS_IOS) {
// we delay this by one frame so that onMomentumBegin may fire on iOS
Expand Down Expand Up @@ -454,11 +450,7 @@ export const useScrollHandlerY = (
useAnimatedReaction(
() => {
return (
!isSnapping.value &&
!isScrolling.value &&
!isDragging.value &&
!isGliding.value &&
enabled
!isSnapping.value && !isScrolling.value && !isGliding.value && enabled
)
},
(sync) => {
Expand Down