fixed switch

This commit is contained in:
Riccardo Cipolleschi
2025-10-14 13:51:44 -04:00
parent e7e32f70b0
commit 5bff0c313f
2 changed files with 29 additions and 1 deletions
+5 -1
View File
@@ -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;
@@ -8,10 +8,29 @@
#import "RCTSwitchManager.h"
#import <React/RCTUIManager.h>
#import <React/RCTUtils.h>
#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 @@ RCT_EXPORT_MODULE()
}
}
- (RCTShadowView *)shadowView
{
return [RCTSwitchShadowView new];
}
RCT_EXPORT_METHOD(setValue : (nonnull NSNumber *)viewTag toValue : (BOOL)value)
{
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {