diff --git a/src/components/Switch.tsx b/src/components/Switch.tsx index 30616e64755d..e6ab9a9f1c1c 100644 --- a/src/components/Switch.tsx +++ b/src/components/Switch.tsx @@ -32,6 +32,12 @@ function Switch({isOn, onToggle, accessibilityLabel, disabled}: SwitchProps) { const offsetX = useRef(new Animated.Value(isOn ? OFFSET_X.ON : OFFSET_X.OFF)); const theme = useTheme(); + const handleSwitchPress = () => { + InteractionManager.runAfterInteractions(() => { + onToggle(!isOn); + }); + }; + useEffect(() => { Animated.timing(offsetX.current, { toValue: isOn ? OFFSET_X.ON : OFFSET_X.OFF, @@ -44,16 +50,8 @@ function Switch({isOn, onToggle, accessibilityLabel, disabled}: SwitchProps) { { - InteractionManager.runAfterInteractions(() => { - onToggle(!isOn); - }); - }} - onLongPress={() => { - InteractionManager.runAfterInteractions(() => { - onToggle(!isOn); - }); - }} + onPress={handleSwitchPress} + onLongPress={handleSwitchPress} role={CONST.ROLE.SWITCH} aria-checked={isOn} accessibilityLabel={accessibilityLabel}