Sanity check selector swipes

zio/stable
Paul Frazee 2023-01-20 10:15:59 -06:00
parent 56747263df
commit c4cca8cf6c
1 changed files with 4 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import {Selector} from './Selector'
import {HorzSwipe} from './gestures/HorzSwipe' import {HorzSwipe} from './gestures/HorzSwipe'
import {useAnimatedValue} from '../../lib/hooks/useAnimatedValue' import {useAnimatedValue} from '../../lib/hooks/useAnimatedValue'
import {OnScrollCb} from '../../lib/hooks/useOnMainScroll' import {OnScrollCb} from '../../lib/hooks/useOnMainScroll'
import {clamp} from '../../../lib/numbers'
const HEADER_ITEM = {_reactKey: '__header__'} const HEADER_ITEM = {_reactKey: '__header__'}
const SELECTOR_ITEM = {_reactKey: '__selector__'} const SELECTOR_ITEM = {_reactKey: '__selector__'}
@ -46,10 +47,11 @@ export function ViewSelector({
const onSwipeEnd = (dx: number) => { const onSwipeEnd = (dx: number) => {
if (dx !== 0) { if (dx !== 0) {
setSelectedIndex(selectedIndex + dx) setSelectedIndex(clamp(selectedIndex + dx, 0, sections.length))
} }
} }
const onPressSelection = (index: number) => setSelectedIndex(index) const onPressSelection = (index: number) =>
setSelectedIndex(clamp(index, 0, sections.length))
useEffect(() => { useEffect(() => {
onSelectView?.(selectedIndex) onSelectView?.(selectedIndex)
}, [selectedIndex]) }, [selectedIndex])