From a1c67e2b482e650b4178eda1ed84e39b766aeacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 27 Jul 2021 11:50:57 +0800 Subject: [PATCH] iOS: status bar delegate --- doric-iOS/Pod/Classes/DoricContext.h | 2 ++ doric-iOS/Pod/Classes/DoricViewController.h | 2 +- doric-iOS/Pod/Classes/DoricViewController.m | 11 +++++++ .../Pod/Classes/Plugin/DoricStatusBarPlugin.m | 16 +++------- .../StatusBar/DoricStatusBarDelegate.h | 29 +++++++++++++++++++ 5 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 doric-iOS/Pod/Classes/StatusBar/DoricStatusBarDelegate.h diff --git a/doric-iOS/Pod/Classes/DoricContext.h b/doric-iOS/Pod/Classes/DoricContext.h index a21302d6..3a9e9060 100644 --- a/doric-iOS/Pod/Classes/DoricContext.h +++ b/doric-iOS/Pod/Classes/DoricContext.h @@ -24,6 +24,7 @@ #import "DoricDriverProtocol.h" #import "DoricNavigatorDelegate.h" #import "DoricNavBarDelegate.h" +#import "DoricStatusBarDelegate.h" #import "DoricPerformanceProfile.h" NS_ASSUME_NONNULL_BEGIN @@ -34,6 +35,7 @@ NS_ASSUME_NONNULL_BEGIN @interface DoricContext : NSObject @property(nonatomic, weak) id navigator; @property(nonatomic, weak) id navBar; +@property(nonatomic, weak) id statusBar; @property(nonatomic, weak) UIViewController *vc; @property(nonatomic, strong) NSString *contextId; @property(nonatomic, strong) id driver; diff --git a/doric-iOS/Pod/Classes/DoricViewController.h b/doric-iOS/Pod/Classes/DoricViewController.h index 4d3160f7..4cbc2cbc 100644 --- a/doric-iOS/Pod/Classes/DoricViewController.h +++ b/doric-iOS/Pod/Classes/DoricViewController.h @@ -25,7 +25,7 @@ extern NSString *const DORIC_MASK_RETRY; -@interface DoricViewController : UIViewController +@interface DoricViewController : UIViewController @property(nonatomic, copy) NSString *source; @property(nonatomic, copy) NSString *alias; @property(nonatomic, copy) NSString *extra; diff --git a/doric-iOS/Pod/Classes/DoricViewController.m b/doric-iOS/Pod/Classes/DoricViewController.m index 35098745..9ece30f5 100644 --- a/doric-iOS/Pod/Classes/DoricViewController.m +++ b/doric-iOS/Pod/Classes/DoricViewController.m @@ -163,6 +163,16 @@ - (void)doric_navBar_setCenter:(UIView *)view { self.navigationItem.titleView = view; } +- (void)doric_statusBar_setHidden:(BOOL)hidden { + self.statusBarHidden = hidden; + [self setNeedsStatusBarAppearanceUpdate]; +} + +- (void)doric_statusBar_setMode:(int)mode { + self.statusBarMode = mode; + [self setNeedsStatusBarAppearanceUpdate]; +} + - (BOOL)statusBarHidden { return _statusBarHidden; } @@ -210,6 +220,7 @@ - (void)loadJSBundle { [self.doricPanel config:result alias:self.alias extra:self.extra]; self.doricPanel.doricContext.navigator = self; self.doricPanel.doricContext.navBar = self; + self.doricPanel.doricContext.statusBar = self; self.doricPanel.doricContext.vc = self; }); }; diff --git a/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.m index 2217b424..c72897cf 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.m @@ -28,12 +28,8 @@ - (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise { __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - if (self.doricContext.navBar) { - if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) { - DoricViewController *target = ((DoricViewController *) self.doricContext.navBar); - target.statusBarHidden = [param optBool:@"hidden"]; - [target setNeedsStatusBarAppearanceUpdate]; - } + if (self.doricContext.statusBar) { + [self.doricContext.statusBar doric_statusBar_setHidden:[param optBool:@"hidden"]]; } }]; } @@ -42,12 +38,8 @@ - (void)setMode:(NSDictionary *)param withPromise:(DoricPromise *)promise { __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - if (self.doricContext.navBar) { - if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) { - DoricViewController *target = ((DoricViewController *) self.doricContext.navBar); - target.statusBarMode = [[param optNumber:@"mode"] intValue]; - [target setNeedsStatusBarAppearanceUpdate]; - } + if (self.doricContext.statusBar) { + [self.doricContext.statusBar doric_statusBar_setMode:[[param optNumber:@"mode"] intValue]]; } }]; } diff --git a/doric-iOS/Pod/Classes/StatusBar/DoricStatusBarDelegate.h b/doric-iOS/Pod/Classes/StatusBar/DoricStatusBarDelegate.h new file mode 100644 index 00000000..21f6174a --- /dev/null +++ b/doric-iOS/Pod/Classes/StatusBar/DoricStatusBarDelegate.h @@ -0,0 +1,29 @@ +/* + * Copyright [2021] [Doric.Pub] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Created by jingpeng.wang on 2021/7/27. +// + +#import +#import + +@protocol DoricStatusBarDelegate + +- (void)doric_statusBar_setHidden:(BOOL)hidden; + +- (void)doric_statusBar_setMode:(int)mode; + +@end