From 997dcd0ca831c1c292da9698eab6590879c19f6c Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Sun, 16 Mar 2025 21:59:47 +0800 Subject: [PATCH 1/2] [Fabric] iOS: Fixes Switch component incorrectly renders as toggled on even though value prop is hardcoded to false --- .../Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm index c3d44953ef3c66..8c7327402d239b 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm @@ -47,6 +47,9 @@ - (void)prepareForRecycle { [super prepareForRecycle]; _isInitialValueSet = NO; + + const auto &switchProps = static_cast(*_props); + _switchView.on = switchProps.value; } + (ComponentDescriptorProvider)componentDescriptorProvider From c6bcde1c4169ef1cc2c5b74bc0667c6a7dd3dead Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Mon, 17 Mar 2025 22:08:20 +0800 Subject: [PATCH 2/2] update --- .../Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm index 8c7327402d239b..c4e36804615fbc 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm @@ -47,9 +47,6 @@ - (void)prepareForRecycle { [super prepareForRecycle]; _isInitialValueSet = NO; - - const auto &switchProps = static_cast(*_props); - _switchView.on = switchProps.value; } + (ComponentDescriptorProvider)componentDescriptorProvider @@ -63,7 +60,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared & const auto &newSwitchProps = static_cast(*props); // `value` - if (oldSwitchProps.value != newSwitchProps.value) { + if (!_isInitialValueSet || oldSwitchProps.value != newSwitchProps.value) { BOOL shouldAnimate = _isInitialValueSet == YES; [_switchView setOn:newSwitchProps.value animated:shouldAnimate]; }