Skip to content

feat: modernize Switch to MD3#4957

Open
adrcotfas wants to merge 3 commits into
@adrcotfas/tokens_structurefrom
@adrcotfas/switch
Open

feat: modernize Switch to MD3#4957
adrcotfas wants to merge 3 commits into
@adrcotfas/tokens_structurefrom
@adrcotfas/switch

Conversation

@adrcotfas
Copy link
Copy Markdown
Collaborator

@adrcotfas adrcotfas commented May 20, 2026

Motivation

Update the Switch to use the latest MD specs, including motion and RTL.

Related issue

Closes #4939
Partially closes #4892

Test plan

  • lint, existing tests and new tests pass
  • manual testing on Android, iOS and web in all states, including hovered and focused

Demo

Screen_recording_20260520_171630.webm
Simulator.Screen.Recording.-.iPhone.16e.-.2026-05-20.at.17.46.36.mov

@github-actions
Copy link
Copy Markdown

The mobile version of example app from this branch is ready! You can see it here.

Comment on lines +35 to 52
export type Props = {
/** Whether the switch is on. */
value?: boolean;
/**
* Custom color for switch.
*/
color?: string;
/**
* Callback called with the new value when it changes.
*/
onValueChange?: Function;
/** Called with the new value when the user toggles the switch. */
onValueChange?: (value: boolean) => void;
/** Disables interaction and renders the disabled visual state. */
disabled?: boolean;
/** Icon shown inside the handle when checked */
checkedIcon?: IconSource;
/** Icon shown inside the handle when unchecked. */
uncheckedIcon?: IconSource;
/** Per-slot color overrides. Unspecified keys fall back to theme defaults. */
colors?: Partial<SwitchColors>;
style?: StyleProp<ViewStyle>;
/**
* @optional
*/
testID?: string;
theme?: ThemeProp;
accessibilityLabel?: string;
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the multiline comment pattern already used in the codebase. Don't collapse them to a single line.

/** Icon shown inside the handle when unchecked. */
uncheckedIcon?: IconSource;
/** Per-slot color overrides. Unspecified keys fall back to theme defaults. */
colors?: Partial<SwitchColors>;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this prop, given that all components already receive theme as a prop. It's 2 ways to achieve the same thing.

Copy link
Copy Markdown
Collaborator Author

@adrcotfas adrcotfas May 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we had a color prop and this is what replaces it for custom colors.
I'm fine with removing it but having colors is more developer friendly since we're using explicit switch specific naming instead of having to guess what theme color token corresponds to which component token.

As a developer using this lib, I would not use this unless I want custom colors for the switch and in general I would not pass non-default/global theme to components.

What do you think?

Edit: I would prefer to remove the theme prop and use useInternalTheme() instead for the other tokens we need

Comment thread src/index.tsx
export type { Props as SwitchProps } from './components/Switch/Switch';
export type {
Props as SwitchProps,
SwitchColors,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this exposed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/components/Switch/Switch.tsx Outdated
Comment thread src/components/Switch/Switch.tsx Outdated
Comment thread src/components/Switch/utils.ts Outdated
Comment thread src/components/__tests__/Switch.test.tsx Outdated
@adrcotfas adrcotfas force-pushed the @adrcotfas/tokens_structure branch from 91d86b4 to be1c417 Compare May 25, 2026 06:21
@adrcotfas adrcotfas added the v6 label May 25, 2026
@adrcotfas adrcotfas force-pushed the @adrcotfas/tokens_structure branch from be1c417 to b41006a Compare May 25, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants