mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
fixed switch
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user