From 5bff0c313fbc95890dafda56ef3e2e4c4d3fbd32 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Tue, 14 Oct 2025 13:51:44 -0400 Subject: [PATCH] fixed switch --- packages/react-native/React/Base/RCTUtils.mm | 6 ++++- .../React/Views/RCTSwitchManager.m | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/react-native/React/Base/RCTUtils.mm b/packages/react-native/React/Base/RCTUtils.mm index 6d89ba623039e3..af16d367dfc654 100644 --- a/packages/react-native/React/Base/RCTUtils.mm +++ b/packages/react-native/React/Base/RCTUtils.mm @@ -432,7 +432,11 @@ CGSize RCTSwitchSize(void) static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ RCTUnsafeExecuteOnMainQueueSync(^{ - rctSwitchSize = [UISwitch new].intrinsicContentSize; + CGSize switchSize = [UISwitch new].intrinsicContentSize; + // Apple does not take into account the thumb border when returning the + // width of the UISwitch component, so we are adding 2 pixels for the border + // which is not customizable and it is the same for legacy and liquid glass. + rctSwitchSize = CGSizeMake(switchSize.width + 2, switchSize.height); }); }); return rctSwitchSize; diff --git a/packages/react-native/React/Views/RCTSwitchManager.m b/packages/react-native/React/Views/RCTSwitchManager.m index b04b51f844e11a..753932fc3f42d4 100644 --- a/packages/react-native/React/Views/RCTSwitchManager.m +++ b/packages/react-native/React/Views/RCTSwitchManager.m @@ -8,10 +8,29 @@ #import "RCTSwitchManager.h" #import +#import #import "RCTBridge.h" +#import "RCTShadowView.h" #import "RCTSwitch.h" #import "UIView+React.h" +@interface RCTSwitchShadowView : RCTShadowView + +@end + +@implementation RCTSwitchShadowView + +- (instancetype)init +{ + if (self = [super init]) { + self.intrinsicContentSize = RCTSwitchSize(); + } + + return self; +} + +@end + @implementation RCTSwitchManager RCT_EXPORT_MODULE() @@ -33,6 +52,11 @@ - (void)onChange:(RCTSwitch *)sender } } +- (RCTShadowView *)shadowView +{ + return [RCTSwitchShadowView new]; +} + RCT_EXPORT_METHOD(setValue : (nonnull NSNumber *)viewTag toValue : (BOOL)value) { [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry) {