add haptics to segmented control (#9398)
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
import {type StyleProp, View, type ViewStyle} from 'react-native'
|
import {type StyleProp, View, type ViewStyle} from 'react-native'
|
||||||
import Animated, {Easing, LinearTransition} from 'react-native-reanimated'
|
import Animated, {Easing, LinearTransition} from 'react-native-reanimated'
|
||||||
|
|
||||||
|
import {useHaptics} from '#/lib/haptics'
|
||||||
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
||||||
import {atoms as a, native, platform, useTheme} from '#/alf'
|
import {atoms as a, native, platform, useTheme} from '#/alf'
|
||||||
import {
|
import {
|
||||||
@@ -142,6 +143,7 @@ export function Item({
|
|||||||
onPress: onPressProp,
|
onPress: onPressProp,
|
||||||
...props
|
...props
|
||||||
}: {value: string; children: React.ReactNode} & Omit<ButtonProps, 'children'>) {
|
}: {value: string; children: React.ReactNode} & Omit<ButtonProps, 'children'>) {
|
||||||
|
const playHaptic = useHaptics()
|
||||||
const [position, setPosition] = useState<{x: number; width: number} | null>(
|
const [position, setPosition] = useState<{x: number; width: number} | null>(
|
||||||
null,
|
null,
|
||||||
)
|
)
|
||||||
@@ -174,10 +176,11 @@ export function Item({
|
|||||||
|
|
||||||
const onPress = useCallback(
|
const onPress = useCallback(
|
||||||
(evt: any) => {
|
(evt: any) => {
|
||||||
|
playHaptic('Light')
|
||||||
ctx.onSelectValue(value, position)
|
ctx.onSelectValue(value, position)
|
||||||
onPressProp?.(evt)
|
onPressProp?.(evt)
|
||||||
},
|
},
|
||||||
[ctx, value, position, onPressProp],
|
[ctx, value, position, onPressProp, playHaptic],
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user