Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/react-native/React/Base/RCTUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions packages/react-native/React/Views/RCTSwitchManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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<NSNumber *, UIView *> *viewRegistry) {
Expand Down
Loading