Skip to content

Commit

Permalink
refactor: move endDrag outside of context
Browse files Browse the repository at this point in the history
  • Loading branch information
andreialecu committed Feb 8, 2021
1 parent fa4fbdb commit ca5d167
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 0 additions & 2 deletions src/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ const Container = React.forwardRef<CollapsibleRef, CollapsibleProps>(
const isSnapping: ContextType['isSnapping'] = useSharedValue(false)
const snappingTo: ContextType['snappingTo'] = useSharedValue(0)
const isGliding: ContextType['isGliding'] = useSharedValue(false)
const endDrag: ContextType['endDrag'] = useSharedValue(0)
const offset: ContextType['offset'] = useSharedValue(0)
const accScrollY: ContextType['accScrollY'] = useSharedValue(0)
const oldAccScrollY: ContextType['oldAccScrollY'] = useSharedValue(0)
Expand Down Expand Up @@ -461,7 +460,6 @@ const Container = React.forwardRef<CollapsibleRef, CollapsibleProps>(
isGliding,
isSnapping,
snappingTo,
endDrag,
contentHeights,
setContentHeights,
}}
Expand Down
10 changes: 9 additions & 1 deletion src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
useAnimatedReaction,
useAnimatedRef,
useAnimatedScrollHandler,
useSharedValue,
withDelay,
withTiming,
} from 'react-native-reanimated'
Expand Down Expand Up @@ -195,10 +196,17 @@ export const useScrollHandlerY = (name: TabName) => {
isGliding,
isSnapping,
snappingTo,
endDrag,
contentHeights,
} = useTabsContext()

/**
* 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
* drag, but the onMomentumEnd has never triggered, we to need to manually
* call it to sync the scenes.
*/
const endDrag = useSharedValue(0)

const [tabIndex] = useState(tabNames.value.findIndex((n) => n === name))

const onMomentumEnd = () => {
Expand Down
8 changes: 1 addition & 7 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,7 @@ export type ContextType<T extends TabName = TabName> = {
* The next snapping value, used only with diffClamp.
*/
snappingTo: Animated.SharedValue<number>
/**
* 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
* drag, but the onMomentumEnd has never triggered, we to need to manually
* call it to sync the scenes.
*/
endDrag: Animated.SharedValue<number>

/**
* Height of the scrollable content of each tab. Helps to allow iOS bouncing.
*/
Expand Down

0 comments on commit ca5d167

Please sign in to comment.