Disable swipe gestures in view selector for now

zio/stable
Paul Frazee 2022-09-09 12:10:18 -05:00
parent acaa8c5c11
commit 639c25821e
1 changed files with 59 additions and 56 deletions

View File

@ -15,6 +15,7 @@ export function ViewSelector({
sections,
items,
refreshing,
swipeEnabled,
renderHeader,
renderItem,
onSelectView,
@ -24,6 +25,7 @@ export function ViewSelector({
sections: string[]
items: any[]
refreshing?: boolean
swipeEnabled?: boolean
renderHeader?: () => JSX.Element
renderItem: (item: any) => JSX.Element
onSelectView?: (viewIndex: number) => void
@ -44,9 +46,9 @@ export function ViewSelector({
// gestures
// =
const swipeGesture = useMemo(
() =>
Gesture.Pan()
const swipeGesture = useMemo(() => {
if (!swipeEnabled) return undefined
return Gesture.Pan()
.hitSlop(SWIPE_GESTURE_HIT_SLOP)
.onUpdate(e => {
// calculate [-1, 1] range for the gesture
@ -88,9 +90,8 @@ export function ViewSelector({
} else {
swipeGestureInterp.value = withTiming(0, {duration: 100})
}
}),
[swipeGestureInterp, selectedIndex, sections.length],
)
})
}, [swipeEnabled, swipeGestureInterp, selectedIndex, sections.length])
useEffect(() => {
// [1] completes the swipe gesture animation by resetting the interp value
// this has to be done as an effect so that it occurs *after* the selectedIndex has been updated
@ -121,8 +122,7 @@ export function ViewSelector({
}
const data = [HEADER_ITEM, SELECTOR_ITEM, ...items]
return (
<GestureDetector gesture={swipeGesture}>
const listEl = (
<FlatList
data={data}
keyExtractor={item => item._reactKey}
@ -132,8 +132,11 @@ export function ViewSelector({
onRefresh={onRefresh}
onEndReached={onEndReached}
/>
</GestureDetector>
)
if (swipeEnabled) {
return <GestureDetector gesture={swipeGesture}>{listEl}</GestureDetector>
}
return listEl
}
const styles = StyleSheet.create({})