From f62e981b5ed7fa6fd63538fb797956f73f6872ba Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Thu, 21 Aug 2025 13:12:21 +0100 Subject: [PATCH] fix crash for feature flag --- packages/react-native/React/Base/RCTUtils.mm | 4 +++- .../react/renderer/components/switch/IOSSwitchShadowNode.mm | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/react-native/React/Base/RCTUtils.mm b/packages/react-native/React/Base/RCTUtils.mm index d2bf9ded0d1..6d89ba62303 100644 --- a/packages/react-native/React/Base/RCTUtils.mm +++ b/packages/react-native/React/Base/RCTUtils.mm @@ -431,7 +431,9 @@ CGSize RCTSwitchSize(void) static CGSize rctSwitchSize; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - rctSwitchSize = [UISwitch new].intrinsicContentSize; + RCTUnsafeExecuteOnMainQueueSync(^{ + rctSwitchSize = [UISwitch new].intrinsicContentSize; + }); }); return rctSwitchSize; } diff --git a/packages/react-native/ReactCommon/react/renderer/components/switch/iosswitch/react/renderer/components/switch/IOSSwitchShadowNode.mm b/packages/react-native/ReactCommon/react/renderer/components/switch/iosswitch/react/renderer/components/switch/IOSSwitchShadowNode.mm index b38b0b0509c..d1981f17c06 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/switch/iosswitch/react/renderer/components/switch/IOSSwitchShadowNode.mm +++ b/packages/react-native/ReactCommon/react/renderer/components/switch/iosswitch/react/renderer/components/switch/IOSSwitchShadowNode.mm @@ -20,7 +20,9 @@ Size SwitchShadowNode::measureContent( const LayoutConstraints & /*layoutConstraints*/) const { CGSize uiSwitchSize = RCTSwitchSize(); - return {.width = uiSwitchSize.width, .height = uiSwitchSize.height}; + // Apple has some error when returning the width of the component and it doesn't + // account for the borders. + return {.width = uiSwitchSize.width + 2, .height = uiSwitchSize.height}; } } // namespace facebook::react