Skip to content

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

@enriquemomice

Description

@enriquemomice

Current behaviour

When using React Native Paper's Switch component inside a Portal/Modal, the switch doesn't update its visual state on the first press, even though the state change is properly triggered and logged. The switch only updates visually on the second press. This issue doesn't occur when the same Switch is used outside of Portal/Modal contexts.

Expected behaviour

It should re render the switch as the state has changed.

How to reproduce?

// Minimal reproduction case
import { useState } from 'react';
import { Modal, Portal, Switch } from 'react-native-paper';

export default function BugDemo() {
  const [visible, setVisible] = useState(true);
  const [checked, setChecked] = useState(false);

  return (
    <Portal>
      <Modal visible={visible}>
        <Switch 
          value={checked} 
          onValueChange={setChecked} // State updates but UI doesn't on first press
        />
      </Modal>
    </Portal>
  );
}

What have you tried so far?

it works If I apply a dynamic key to the Switch like this

<Switch 
  key={`switch-${checked}`} // This fixes the issue
  value={checked} 
  onValueChange={setChecked}
/>

Your Environment

software version
ios 18.5
react-native 0.79.5
react-native-paper 5.14.5
node 22.17.1
expo sdk 53.0.20

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions