Skip to content

Conversation

@PaitoAnderson
Copy link

@PaitoAnderson PaitoAnderson commented Oct 10, 2025

Motivation

When a <Switch /> is inside a <Portal /> you must tap the switch component twice to visually toggle the state on iOS.

Related issue

Fixes #4789

Test plan

I updated the example app to Expo 54, and then added this code in the SwitchExample.tsx file and tried toggling with a single tap.

<Portal>
  <View style={[styles.row, { top: 500 }]}>
    <TextComponent>Portal {checked ? 'on' : 'off'}</TextComponent>
    <Switch value={checked} onValueChange={setChecked} />
  </View>
</Portal>

cursor[bot]

This comment was marked as outdated.

@callstack-bot
Copy link

callstack-bot commented Oct 10, 2025

Hey @PaitoAnderson, thank you for your pull request 🤗. The documentation from this branch can be viewed here.

Comment on lines +76 to +80
React.useEffect(() => {
if (typeof value === 'boolean' && value !== internalValue) {
setInternalValue(value);
}
}, [value, internalValue]);
Copy link

@gkueny gkueny Oct 29, 2025

Choose a reason for hiding this comment

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

Suggested change
React.useEffect(() => {
if (typeof value === 'boolean' && value !== internalValue) {
setInternalValue(value);
}
}, [value, internalValue]);
React.useEffect(() => {
setInternalValue(oldValue => {
if (typeof value === 'boolean' && value !== oldValue) {
return value;
}
return oldValue;
});
}, [value]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch component doesn't update visually on first press when used inside Portal/Modal

3 participants