iOS:use safe method to prevent unexpected exception

This commit is contained in:
pengfeizhou 2021-02-01 15:31:24 +08:00 committed by osborn
parent 6bf38bd290
commit 5a12a770fd
11 changed files with 125 additions and 65 deletions

View File

@ -64,6 +64,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)onHidden; - (void)onHidden;
- (DoricViewNode *)targetViewNode:(NSString *)viewId; - (DoricViewNode *)targetViewNode:(NSString *)viewId;
- (void)dispatchToMainQueue:(_Nonnull dispatch_block_t)block;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -26,6 +26,7 @@
#import "DoricConstant.h" #import "DoricConstant.h"
#import "DoricExtensions.h" #import "DoricExtensions.h"
#import "DoricNativeDriver.h" #import "DoricNativeDriver.h"
#import "DoricUtil.h"
@implementation DoricContext @implementation DoricContext
@ -115,10 +116,23 @@ - (void)onShow {
- (void)onHidden { - (void)onHidden {
[self callEntity:DORIC_ENTITY_HIDDEN withArgumentsArray:@[]]; [self callEntity:DORIC_ENTITY_HIDDEN withArgumentsArray:@[]];
} }
- (UIViewController *)vc { - (UIViewController *)vc {
if(!_vc) { if (!_vc) {
return [UIApplication sharedApplication].keyWindow.rootViewController; return [UIApplication sharedApplication].keyWindow.rootViewController;
} }
return _vc; return _vc;
} }
- (void)dispatchToMainQueue:(_Nonnull dispatch_block_t)block {
dispatch_async(dispatch_get_main_queue(), ^{
@try {
block();
} @catch (NSException *exception) {
DoricLog(@"dispatchToMainQueue Error:%@", exception.reason);
[self.driver.registry onException:exception inContext:self];
}
});
}
@end @end

View File

@ -28,7 +28,9 @@ - (void)submit:(NSDictionary *)args withPromise:(DoricPromise *)promise {
- (void)animateRender:(NSDictionary *)args withPromise:(DoricPromise *)promise { - (void)animateRender:(NSDictionary *)args withPromise:(DoricPromise *)promise {
NSNumber *duration = args[@"duration"]; NSNumber *duration = args[@"duration"];
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
NSString *viewId = args[@"id"]; NSString *viewId = args[@"id"];
[UIView animateWithDuration:[duration floatValue] / 1000 [UIView animateWithDuration:[duration floatValue] / 1000
animations:^{ animations:^{
@ -45,6 +47,6 @@ - (void)animateRender:(NSDictionary *)args withPromise:(DoricPromise *)promise {
completion:^(BOOL finished) { completion:^(BOOL finished) {
[promise resolve:nil]; [promise resolve:nil];
}]; }];
}); }];
} }
@end @end

View File

@ -26,7 +26,9 @@
@implementation DoricCoordinatorPlugin @implementation DoricCoordinatorPlugin
- (void)verticalScrolling:(NSDictionary *)params withPromise:(DoricPromise *)promise { - (void)verticalScrolling:(NSDictionary *)params withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
NSArray <NSString *> *scrollableIds = params[@"scrollable"]; NSArray <NSString *> *scrollableIds = params[@"scrollable"];
DoricViewNode *scrollNode = nil; DoricViewNode *scrollNode = nil;
for (NSString *value in scrollableIds) { for (NSString *value in scrollableIds) {
@ -103,7 +105,7 @@ - (void)verticalScrolling:(NSDictionary *)params withPromise:(DoricPromise *)pro
} else { } else {
[promise reject:@"Scroller type error"]; [promise reject:@"Scroller type error"];
} }
}); }];
} }
- (void)setValue:(DoricViewNode *)viewNode isNavBar:(BOOL)isNavBar name:(NSString *)name value:(id)value { - (void)setValue:(DoricViewNode *)viewNode isNavBar:(BOOL)isNavBar name:(NSString *)name value:(id)value {

View File

@ -27,7 +27,9 @@
@implementation DoricModalPlugin @implementation DoricModalPlugin
- (void)toast:(NSDictionary *)dic withPromise:(DoricPromise *)promise { - (void)toast:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
__block DoricGravity gravity = DoricGravityBottom; __block DoricGravity gravity = DoricGravityBottom;
[dic[@"gravity"] also:^(NSNumber *it) { [dic[@"gravity"] also:^(NSNumber *it) {
gravity = (DoricGravity) [it integerValue]; gravity = (DoricGravity) [it integerValue];
@ -37,11 +39,13 @@ - (void)toast:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
} else { } else {
ShowToast(dic[@"msg"], gravity); ShowToast(dic[@"msg"], gravity);
} }
}); }];
} }
- (void)alert:(NSDictionary *)dic withPromise:(DoricPromise *)promise { - (void)alert:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"] UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"]
message:dic[@"msg"] message:dic[@"msg"]
preferredStyle:UIAlertControllerStyleAlert]; preferredStyle:UIAlertControllerStyleAlert];
@ -52,11 +56,13 @@ - (void)alert:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
}]; }];
[alert addAction:action]; [alert addAction:action];
[self.doricContext.vc presentViewController:alert animated:YES completion:nil]; [self.doricContext.vc presentViewController:alert animated:YES completion:nil];
}); }];
} }
- (void)confirm:(NSDictionary *)dic withPromise:(DoricPromise *)promise { - (void)confirm:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"] UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"]
message:dic[@"msg"] message:dic[@"msg"]
preferredStyle:UIAlertControllerStyleAlert]; preferredStyle:UIAlertControllerStyleAlert];
@ -76,11 +82,13 @@ - (void)confirm:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
[alert addAction:okAction]; [alert addAction:okAction];
[self.doricContext.vc presentViewController:alert animated:YES completion:nil]; [self.doricContext.vc presentViewController:alert animated:YES completion:nil];
}); }];
} }
- (void)prompt:(NSDictionary *)dic withPromise:(DoricPromise *)promise { - (void)prompt:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"] UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"]
message:dic[@"msg"] message:dic[@"msg"]
preferredStyle:UIAlertControllerStyleAlert]; preferredStyle:UIAlertControllerStyleAlert];
@ -113,6 +121,6 @@ - (void)prompt:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
[alert addAction:okAction]; [alert addAction:okAction];
[self.doricContext.vc presentViewController:alert animated:YES completion:nil]; [self.doricContext.vc presentViewController:alert animated:YES completion:nil];
}); }];
} }
@end @end

View File

@ -30,9 +30,11 @@ @implementation DoricNavBarPlugin
- (void)isHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise { - (void)isHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
if (self.doricContext.navBar) { if (self.doricContext.navBar) {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
[promise resolve:@([self.doricContext.navBar doric_navBar_isHidden])]; [promise resolve:@([self.doricContext.navBar doric_navBar_isHidden])];
}); }];
} else { } else {
[promise reject:@"Not implement NavBar"]; [promise reject:@"Not implement NavBar"];
} }
@ -40,10 +42,12 @@ - (void)isHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
- (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise { - (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
if (self.doricContext.navBar) { if (self.doricContext.navBar) {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
[self.doricContext.navBar doric_navBar_setHidden:[param[@"hidden"] boolValue]]; [self.doricContext.navBar doric_navBar_setHidden:[param[@"hidden"] boolValue]];
[promise resolve:nil]; [promise resolve:nil];
}); }];
} else { } else {
[promise reject:@"Not implement NavBar"]; [promise reject:@"Not implement NavBar"];
} }
@ -51,10 +55,12 @@ - (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
- (void)setTitle:(NSDictionary *)param withPromise:(DoricPromise *)promise { - (void)setTitle:(NSDictionary *)param withPromise:(DoricPromise *)promise {
if (self.doricContext.navBar) { if (self.doricContext.navBar) {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
[self.doricContext.navBar doric_navBar_setTitle:param[@"title"]]; [self.doricContext.navBar doric_navBar_setTitle:param[@"title"]];
[promise resolve:nil]; [promise resolve:nil];
}); }];
} else { } else {
[promise reject:@"Not implement NavBar"]; [promise reject:@"Not implement NavBar"];
} }
@ -62,11 +68,13 @@ - (void)setTitle:(NSDictionary *)param withPromise:(DoricPromise *)promise {
- (void)setBgColor:(NSDictionary *)param withPromise:(DoricPromise *)promise { - (void)setBgColor:(NSDictionary *)param withPromise:(DoricPromise *)promise {
if (self.doricContext.navBar) { if (self.doricContext.navBar) {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
UIColor *color = DoricColor(param[@"color"]); UIColor *color = DoricColor(param[@"color"]);
[self.doricContext.navBar doric_navBar_setBackgroundColor:color]; [self.doricContext.navBar doric_navBar_setBackgroundColor:color];
[promise resolve:nil]; [promise resolve:nil];
}); }];
} else { } else {
[promise reject:@"Not implement NavBar"]; [promise reject:@"Not implement NavBar"];
} }
@ -74,7 +82,9 @@ - (void)setBgColor:(NSDictionary *)param withPromise:(DoricPromise *)promise {
- (void)setLeft:(NSDictionary *)params withPromise:(DoricPromise *)promise { - (void)setLeft:(NSDictionary *)params withPromise:(DoricPromise *)promise {
if (self.doricContext.navBar) { if (self.doricContext.navBar) {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
NSString *viewId = params[@"id"]; NSString *viewId = params[@"id"];
NSString *type = params[@"type"]; NSString *type = params[@"type"];
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId]; DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
@ -96,7 +106,7 @@ - (void)setLeft:(NSDictionary *)params withPromise:(DoricPromise *)promise {
[viewNode blend:params[@"props"]]; [viewNode blend:params[@"props"]];
[self.doricContext.navBar doric_navBar_setLeft:viewNode.view]; [self.doricContext.navBar doric_navBar_setLeft:viewNode.view];
[promise resolve:nil]; [promise resolve:nil];
}); }];
} else { } else {
[promise reject:@"Not implement NavBar"]; [promise reject:@"Not implement NavBar"];
} }
@ -104,7 +114,9 @@ - (void)setLeft:(NSDictionary *)params withPromise:(DoricPromise *)promise {
- (void)setRight:(NSDictionary *)params withPromise:(DoricPromise *)promise { - (void)setRight:(NSDictionary *)params withPromise:(DoricPromise *)promise {
if (self.doricContext.navBar) { if (self.doricContext.navBar) {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
NSString *viewId = params[@"id"]; NSString *viewId = params[@"id"];
NSString *type = params[@"type"]; NSString *type = params[@"type"];
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId]; DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
@ -126,7 +138,7 @@ - (void)setRight:(NSDictionary *)params withPromise:(DoricPromise *)promise {
[viewNode blend:params[@"props"]]; [viewNode blend:params[@"props"]];
[self.doricContext.navBar doric_navBar_setRight:viewNode.view]; [self.doricContext.navBar doric_navBar_setRight:viewNode.view];
[promise resolve:nil]; [promise resolve:nil];
}); }];
} else { } else {
[promise reject:@"Not implement NavBar"]; [promise reject:@"Not implement NavBar"];
} }
@ -134,7 +146,9 @@ - (void)setRight:(NSDictionary *)params withPromise:(DoricPromise *)promise {
- (void)setCenter:(NSDictionary *)params withPromise:(DoricPromise *)promise { - (void)setCenter:(NSDictionary *)params withPromise:(DoricPromise *)promise {
if (self.doricContext.navBar) { if (self.doricContext.navBar) {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
NSString *viewId = params[@"id"]; NSString *viewId = params[@"id"];
NSString *type = params[@"type"]; NSString *type = params[@"type"];
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId]; DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
@ -156,7 +170,7 @@ - (void)setCenter:(NSDictionary *)params withPromise:(DoricPromise *)promise {
[viewNode blend:params[@"props"]]; [viewNode blend:params[@"props"]];
[self.doricContext.navBar doric_navBar_setCenter:viewNode.view]; [self.doricContext.navBar doric_navBar_setCenter:viewNode.view];
[promise resolve:nil]; [promise resolve:nil];
}); }];
} else { } else {
[promise reject:@"Not implement NavBar"]; [promise reject:@"Not implement NavBar"];
} }

View File

@ -22,7 +22,9 @@
@implementation DoricNavigatorPlugin @implementation DoricNavigatorPlugin
- (void)push:(NSDictionary *)params { - (void)push:(NSDictionary *)params {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
BOOL animated = YES; BOOL animated = YES;
NSString *source = params[@"source"]; NSString *source = params[@"source"];
NSString *alias = source; NSString *alias = source;
@ -37,21 +39,23 @@ - (void)push:(NSDictionary *)params {
} }
} }
[self.doricContext.navigator doric_navigator_push:source alias:alias animated:animated extra:config[@"extra"]]; [self.doricContext.navigator doric_navigator_push:source alias:alias animated:animated extra:config[@"extra"]];
}); }];
} }
- (void)pop:(NSDictionary *)params { - (void)pop:(NSDictionary *)params {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
BOOL animated = YES; BOOL animated = YES;
if (params[@"animated"]) { if (params[@"animated"]) {
animated = [params[@"animated"] boolValue]; animated = [params[@"animated"] boolValue];
} }
[self.doricContext.navigator doric_navigator_pop:animated]; [self.doricContext.navigator doric_navigator_pop:animated];
}); }];
} }
- (void)openUrl:(NSString *)urlString withPromise:(DoricPromise *)promise { - (void)openUrl:(NSString *)urlString withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ [self.doricContext dispatchToMainQueue:^{
NSURL *url = [NSURL URLWithString:urlString]; NSURL *url = [NSURL URLWithString:urlString];
[UIApplication.sharedApplication openURL:url options:@{} completionHandler:^(BOOL success) { [UIApplication.sharedApplication openURL:url options:@{} completionHandler:^(BOOL success) {
if (success) { if (success) {
@ -60,6 +64,6 @@ - (void)openUrl:(NSString *)urlString withPromise:(DoricPromise *)promise {
[promise reject:@"Cannot open"]; [promise reject:@"Cannot open"];
} }
}]; }];
}); }];
} }
@end @end

View File

@ -30,7 +30,9 @@ - (instancetype)initWithContext:(DoricContext *)doricContext {
} }
- (void)inset:(NSDictionary *)argument withPromise:(DoricPromise *)promise { - (void)inset:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
if (@available(iOS 11.0, *)) { if (@available(iOS 11.0, *)) {
UIView *superView; UIView *superView;
if (self.doricContext.vc) { if (self.doricContext.vc) {
@ -44,19 +46,19 @@ - (void)inset:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
CGFloat bottom = superView.safeAreaInsets.bottom; CGFloat bottom = superView.safeAreaInsets.bottom;
CGFloat right = superView.safeAreaInsets.right; CGFloat right = superView.safeAreaInsets.right;
[promise resolve:@{ [promise resolve:@{
@"top": @(top), @"top": @(top),
@"left": @(left), @"left": @(left),
@"bottom": @(bottom), @"bottom": @(bottom),
@"right": @(right), @"right": @(right),
}]; }];
} else { } else {
[promise resolve:@{ [promise resolve:@{
@"top": @(0), @"top": @(0),
@"left": @(0), @"left": @(0),
@"bottom": @(0), @"bottom": @(0),
@"right": @(0), @"right": @(0),
}]; }];
} }
}); }];
} }
@end @end

View File

@ -14,7 +14,9 @@ @implementation DoricPopoverPlugin
static NSString *TYPE = @"popover"; static NSString *TYPE = @"popover";
- (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise { - (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
UIView *superView = self.doricContext.vc.view; UIView *superView = self.doricContext.vc.view;
if (!self.fullScreenView) { if (!self.fullScreenView) {
self.fullScreenView = [[UIView new] also:^(UIView *it) { self.fullScreenView = [[UIView new] also:^(UIView *it) {
@ -52,12 +54,14 @@ - (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
[viewNode blend:params[@"props"]]; [viewNode blend:params[@"props"]];
[self.fullScreenView.doricLayout apply]; [self.fullScreenView.doricLayout apply];
[promise resolve:nil]; [promise resolve:nil];
}); }];
} }
- (void)dismiss:(NSDictionary *)params withPromise:(DoricPromise *)promise { - (void)dismiss:(NSDictionary *)params withPromise:(DoricPromise *)promise {
NSString *viewId = params[@"id"]; NSString *viewId = params[@"id"];
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
if (viewId) { if (viewId) {
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId]; DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
[self dismissViewNode:viewNode]; [self dismissViewNode:viewNode];
@ -65,7 +69,7 @@ - (void)dismiss:(NSDictionary *)params withPromise:(DoricPromise *)promise {
[self dismissPopover]; [self dismissPopover];
} }
[promise resolve:nil]; [promise resolve:nil];
}); }];
} }
- (void)dismissViewNode:(DoricViewNode *)node { - (void)dismissViewNode:(DoricViewNode *)node {

View File

@ -33,7 +33,7 @@ - (void)render:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
return; return;
} }
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
dispatch_async(dispatch_get_main_queue(), ^{ [self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
if (self.doricContext == nil) { if (self.doricContext == nil) {
return; return;
@ -50,11 +50,13 @@ - (void)render:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
[viewNode requestLayout]; [viewNode requestLayout];
} }
[promise resolve:nil]; [promise resolve:nil];
}); }];
} }
- (void)command:(NSDictionary *)argument withPromise:(DoricPromise *)promise { - (void)command:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
if (self.doricContext == nil) { if (self.doricContext == nil) {
return; return;
} }
@ -76,7 +78,7 @@ - (void)command:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
} else { } else {
[self findClass:[viewNode class] target:viewNode method:name promise:promise argument:args]; [self findClass:[viewNode class] target:viewNode method:name promise:promise argument:args];
} }
}); }];
} }
- (id)createParamWithMethodName:(NSString *)method promise:(DoricPromise *)promise argument:(id)argument { - (id)createParamWithMethodName:(NSString *)method promise:(DoricPromise *)promise argument:(id)argument {

View File

@ -26,36 +26,42 @@
@implementation DoricStatusBarPlugin @implementation DoricStatusBarPlugin
- (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise { - (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
if (self.doricContext.navBar) { if (self.doricContext.navBar) {
if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) { if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) {
DoricViewController * target = ((DoricViewController *)self.doricContext.navBar); DoricViewController *target = ((DoricViewController *) self.doricContext.navBar);
target.statusBarHidden = [param[@"hidden"] boolValue]; target.statusBarHidden = [param[@"hidden"] boolValue];
[target setNeedsStatusBarAppearanceUpdate]; [target setNeedsStatusBarAppearanceUpdate];
} }
} }
}); }];
} }
- (void)setMode:(NSDictionary *)param withPromise:(DoricPromise *)promise { - (void)setMode:(NSDictionary *)param withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
if (self.doricContext.navBar) { if (self.doricContext.navBar) {
if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) { if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) {
DoricViewController * target = ((DoricViewController *)self.doricContext.navBar); DoricViewController *target = ((DoricViewController *) self.doricContext.navBar);
target.statusBarMode = [param[@"mode"] intValue]; target.statusBarMode = [param[@"mode"] intValue];
[target setNeedsStatusBarAppearanceUpdate]; [target setNeedsStatusBarAppearanceUpdate];
} }
} }
}); }];
} }
- (void)setColor:(NSDictionary *)param withPromise:(DoricPromise *)promise { - (void)setColor:(NSDictionary *)param withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ __weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
if (self.doricContext.navBar) { if (self.doricContext.navBar) {
UIColor *color = DoricColor(param[@"color"]); UIColor *color = DoricColor(param[@"color"]);
[self.doricContext.navBar doric_navBar_setBackgroundColor:color]; [self.doricContext.navBar doric_navBar_setBackgroundColor:color];
} }
}); }];
} }
@end @end