Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions design-tokens/input/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -5077,11 +5077,11 @@
"checkedHoverBackground": "{color.bg.neutral.strong.hover}"
},
"handle": {
"background": "{color.bg.surface.raised.default}",
"hoverBackground": "{color.bg.surface.raised.default}",
"background": "{color.fg.on.fill.default}",
"hoverBackground": "{color.fg.on.fill.default}",
"disabledBackground": "{color.bg.neutral.medium.strong}",
"checkedBackground": "{color.bg.surface.raised.default}",
"checkedHoverBackground": "{color.bg.surface.raised.default}",
"checkedBackground": "{color.fg.inverse.active}",
"checkedHoverBackground": "{color.fg.inverse.active}",
"color": "{color.fg.default}",
"hoverColor": "{color.fg.default}",
"checkedColor": "{color.fg.default}",
Expand All @@ -5090,22 +5090,22 @@
},
"dark": {
"handle": {
"background": "{color.bg.surface.raised.default}",
"checkedBackground": "{color.bg.surface.raised.default}",
"background": "{color.fg.on.fill.default}",
"checkedBackground": "{color.fg.inverse.active}",
"checkedColor": "{color.fg.inverse.focus}",
"checkedHoverBackground": "{color.bg.surface.raised.default}",
"checkedHoverBackground": "{color.fg.inverse.active}",
"checkedHoverColor": "{color.fg.on.brand.hover}",
"color": "{color.fg.inverse.default}",
"disabledBackground": "{color.bg.surface.raised.active}",
"hoverBackground": "{color.bg.surface.raised.default}",
"disabledBackground": "{color.bg.neutral.medium.strong}",
"hoverBackground": "{color.fg.on.fill.default}",
"hoverColor": "{color.fg.on.brand.hover}"
},
"root": {
"background": "{color.bg.neutral.medium.active}",
"checkedBackground": "{color.bg.surface.canvas.default}",
"checkedHoverBackground": "{color.bg.surface.canvas.hover}",
"disabledBackground": "{color.bg.neutral.strong.hover}",
"hoverBackground": "{color.bg.surface.raised.active}"
"checkedBackground": "{color.bg.neutral.strong.default}",
"checkedHoverBackground": "{color.bg.neutral.strong.hover}",
"disabledBackground": "{color.bg.surface.canvas.hover}",
"hoverBackground": "{color.bg.neutral.medium.strong}"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Input/InputSwitch/InputSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const InputSwitch = memo<InputSwitchProps>(
}) => {
const { containerStyle, sliderStyle, onPressIn, onPressOut } =
useSliderStyles(checked, disabled, danger)
const { handleStyle } = useHandleStyles(checked)
const { handleStyle } = useHandleStyles(checked, disabled)

const handlePress = useCallback(() => {
onCheckedChange?.(!checked)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 26 additions & 6 deletions src/components/Input/InputSwitch/styles/useHandleStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useSharedValue, withTiming } from 'react-native-reanimated'

import { StyleSheet } from 'react-native-unistyles'

export const useHandleStyles = (checked: boolean) => {
export const useHandleStyles = (checked: boolean, disabled: boolean) => {
const styles = handleStyles
const handleOnLeft = styles.handleOn.left
const handleOffLeft = styles.handleOff.left
Expand All @@ -15,23 +15,39 @@ export const useHandleStyles = (checked: boolean) => {
)

const calculateHandleBackground = useCallback(
(checked: boolean) =>
checked ? styles.handleOn.backgroundColor : styles.handle.backgroundColor,
[styles.handle.backgroundColor, styles.handleOn.backgroundColor]
(checked: boolean, disabled: boolean) => {
if (disabled) {
return styles.handleDisabled.backgroundColor
}

return checked
? styles.handleOn.backgroundColor
: styles.handle.backgroundColor
},
[
styles.handle.backgroundColor,
styles.handleDisabled.backgroundColor,
styles.handleOn.backgroundColor,
]
)

const handleLeftPosition = useSharedValue(
calculateHandleLeftPosition(checked)
)
const handleBackground = useSharedValue(calculateHandleBackground(checked))
const handleBackground = useSharedValue(
calculateHandleBackground(checked, disabled)
)

useEffect(() => {
handleLeftPosition.value = withTiming(calculateHandleLeftPosition(checked))
handleBackground.value = withTiming(calculateHandleBackground(checked))
handleBackground.value = withTiming(
calculateHandleBackground(checked, disabled)
)
}, [
calculateHandleBackground,
calculateHandleLeftPosition,
checked,
disabled,
handleLeftPosition,
handleBackground,
])
Expand Down Expand Up @@ -63,6 +79,10 @@ const handleStyles = StyleSheet.create(({ components: { toggleswitch } }) => ({
left: toggleswitch.root.gap - toggleswitch.root.borderWidth,
},

handleDisabled: {
backgroundColor: toggleswitch.colorScheme.handle.disabledBackground,
},

handleOn: {
backgroundColor: toggleswitch.colorScheme.handle.checkedBackground,
left:
Expand Down
14 changes: 7 additions & 7 deletions src/theme/tokens/components/dark.json
Original file line number Diff line number Diff line change
Expand Up @@ -2801,21 +2801,21 @@
"toggleswitch": {
"colorScheme": {
"handle": {
"background": "#56595f",
"checkedBackground": "#56595f",
"background": "#ffffff",
"checkedBackground": "#181a1f",
"checkedColor": "#2b2e33",
"checkedHoverBackground": "#56595f",
"checkedHoverBackground": "#181a1f",
"checkedHoverColor": "#2b2e33",
"color": "#2b2e33",
"disabledBackground": "#85888e",
"hoverBackground": "#56595f",
"hoverBackground": "#ffffff",
"hoverColor": "#2b2e33"
},
"root": {
"background": "#6d7076",
"checkedBackground": "#2b2e33",
"checkedHoverBackground": "#404348",
"disabledBackground": "#e2e2e4",
"checkedBackground": "#f0f0f1",
"checkedHoverBackground": "#e2e2e4",
"disabledBackground": "#404348",
"hoverBackground": "#85888e"
}
},
Expand Down
Loading