diff --git a/src/view/com/util/ViewSelector.tsx b/src/view/com/util/ViewSelector.tsx index a9252035..9ea7bc74 100644 --- a/src/view/com/util/ViewSelector.tsx +++ b/src/view/com/util/ViewSelector.tsx @@ -4,6 +4,7 @@ import {Selector} from './Selector' import {HorzSwipe} from './gestures/HorzSwipe' import {useAnimatedValue} from '../../lib/hooks/useAnimatedValue' import {OnScrollCb} from '../../lib/hooks/useOnMainScroll' +import {clamp} from '../../../lib/numbers' const HEADER_ITEM = {_reactKey: '__header__'} const SELECTOR_ITEM = {_reactKey: '__selector__'} @@ -46,10 +47,11 @@ export function ViewSelector({ const onSwipeEnd = (dx: number) => { 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(() => { onSelectView?.(selectedIndex) }, [selectedIndex])