mirror of
https://github.com/Boof2015/astra-mobile.git
synced 2026-08-19 20:20:18 +02:00
custom linear haptics
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { Switch, type SwitchProps } from 'react-native';
|
||||
import { hapticForToggle } from '@/lib/hapticCatalog';
|
||||
import { playHaptic } from '@/lib/haptics';
|
||||
|
||||
export interface HapticSwitchProps
|
||||
extends Omit<SwitchProps, 'value' | 'onValueChange'> {
|
||||
value: boolean;
|
||||
onValueChange: (value: boolean) => void;
|
||||
}
|
||||
|
||||
/** Switch feedback fires only for a user-requested value transition. */
|
||||
export function HapticSwitch({
|
||||
value,
|
||||
onValueChange,
|
||||
...props
|
||||
}: HapticSwitchProps) {
|
||||
const handleValueChange = (nextValue: boolean) => {
|
||||
if (nextValue !== value) playHaptic(hapticForToggle(nextValue));
|
||||
onValueChange(nextValue);
|
||||
};
|
||||
|
||||
return (
|
||||
<Switch
|
||||
{...props}
|
||||
value={value}
|
||||
onValueChange={handleValueChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default HapticSwitch;
|
||||
Reference in New Issue
Block a user