diff --git a/React/Views/RCTSwitchManager.m b/React/Views/RCTSwitchManager.m index 0aa33fbafb0..0986378959d 100644 --- a/React/Views/RCTSwitchManager.m +++ b/React/Views/RCTSwitchManager.m @@ -11,6 +11,7 @@ #import "RCTEventDispatcher.h" #import "RCTSwitch.h" #import "UIView+React.h" +#import @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 *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);