mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add setValue command to RCTSwitchManager
Reviewed By: shergin Differential Revision: D17714133 fbshipit-source-id: ccb89be1b763678f44f1271e4d5882afd37ccf65
This commit is contained in:
committed by
Facebook Github Bot
parent
bdb4278523
commit
eb08b428b6
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user