Add setValue command to RCTSwitchManager

Reviewed By: shergin

Differential Revision: D17714133

fbshipit-source-id: ccb89be1b763678f44f1271e4d5882afd37ccf65
This commit is contained in:
Samuel Susla
2019-10-03 03:58:00 -07:00
committed by Facebook Github Bot
parent bdb4278523
commit eb08b428b6
+19
View File
@@ -11,6 +11,7 @@
#import "RCTEventDispatcher.h"
#import "RCTSwitch.h"
#import "UIView+React.h"
#import <React/RCTUIManager.h>
@implementation RCTSwitchManager
@@ -35,6 +36,24 @@ RCT_EXPORT_MODULE()
}
}
RCT_EXPORT_METHOD(setValue : (nonnull NSNumber *)viewTag toValue : (BOOL)value)
{
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
UIView *view = viewRegistry[viewTag];
if ([view isKindOfClass:[UISwitch class]]) {
[(UISwitch *)view setOn:value animated:NO];
} else {
UIView *subview = view.subviews.firstObject;
if ([subview isKindOfClass:[UISwitch class]]) {
[(UISwitch *)subview setOn:value animated:NO];
} else {
RCTLogError(@"view type must be UISwitch");
}
}
}];
}
RCT_EXPORT_VIEW_PROPERTY(onTintColor, UIColor);
RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor);
RCT_EXPORT_VIEW_PROPERTY(thumbTintColor, UIColor);