add haptics to segmented control (#9398)

This commit is contained in:
Samuel Newman
2025-11-17 15:23:28 +02:00
committed by GitHub
parent 084f60c88f
commit f53d5b6f27
+4 -1
View File
@@ -9,6 +9,7 @@ import {
import {type StyleProp, View, type ViewStyle} from 'react-native'
import Animated, {Easing, LinearTransition} from 'react-native-reanimated'
import {useHaptics} from '#/lib/haptics'
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
import {atoms as a, native, platform, useTheme} from '#/alf'
import {
@@ -142,6 +143,7 @@ export function Item({
onPress: onPressProp,
...props
}: {value: string; children: React.ReactNode} & Omit<ButtonProps, 'children'>) {
const playHaptic = useHaptics()
const [position, setPosition] = useState<{x: number; width: number} | null>(
null,
)
@@ -174,10 +176,11 @@ export function Item({
const onPress = useCallback(
(evt: any) => {
playHaptic('Light')
ctx.onSelectValue(value, position)
onPressProp?.(evt)
},
[ctx, value, position, onPressProp],
[ctx, value, position, onPressProp, playHaptic],
)
return (