Skip to content

Commit

Permalink
use disable prop
Browse files Browse the repository at this point in the history
  • Loading branch information
dukenv0307 committed Apr 12, 2024
1 parent a78846d commit 3eef305
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ function MoneyRequestView({
accessibilityLabel={translate('common.billable')}
isOn={!!transactionBillable}
onToggle={saveBillable}
interactive={canEdit}
disabled={!canEdit}
/>
</View>
)}
Expand Down
19 changes: 4 additions & 15 deletions src/components/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ type SwitchProps = {
/** Accessibility label for the switch */
accessibilityLabel: string;

/** Whether the menu item should be interactive at all */
interactive?: boolean;

/** Whether the switch is disabled */
disabled?: boolean;
};
Expand All @@ -30,7 +27,7 @@ const OFFSET_X = {
ON: 20,
};

function Switch({isOn, onToggle, accessibilityLabel, interactive = true, disabled}: SwitchProps) {
function Switch({isOn, onToggle, accessibilityLabel, disabled}: SwitchProps) {
const styles = useThemeStyles();
const offsetX = useRef(new Animated.Value(isOn ? OFFSET_X.ON : OFFSET_X.OFF));
const theme = useTheme();
Expand All @@ -43,20 +40,12 @@ function Switch({isOn, onToggle, accessibilityLabel, interactive = true, disable
}).start();
}, [isOn]);

const onPressOrLongPressAction = () => {
if (!interactive) {
return;
}

onToggle(!isOn);
};

return (
<PressableWithFeedback
disabled={disabled}
style={[styles.switchTrack, !isOn && styles.switchInactive, !interactive && styles.cursorDefault]}
onPress={onPressOrLongPressAction}
onLongPress={onPressOrLongPressAction}
style={[styles.switchTrack, !isOn && styles.switchInactive]}
onPress={() => onToggle(!isOn)}
onLongPress={() => onToggle(!isOn)}
role={CONST.ROLE.SWITCH}
aria-checked={isOn}
accessibilityLabel={accessibilityLabel}
Expand Down

0 comments on commit 3eef305

Please sign in to comment.