diff --git a/doric-iOS/Example/Example.xcodeproj/project.pbxproj b/doric-iOS/Example/Example.xcodeproj/project.pbxproj index b2762de1..44169e03 100644 --- a/doric-iOS/Example/Example.xcodeproj/project.pbxproj +++ b/doric-iOS/Example/Example.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 8BCADA7C23CD5B65005EEF96 /* NavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BCADA7B23CD5B64005EEF96 /* NavigationController.m */; }; A1E221FB2DCA40D85C4D9520 /* libPods-ExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4F233ACD236542275AED3DE0 /* libPods-ExampleTests.a */; }; CC537F4B9F59400BA5B4FF8F /* libPods-Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DEE8411A69609CC9C86063CC /* libPods-Example.a */; }; D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */ = {isa = PBXBuildFile; fileRef = D751D19E97EF4EDD7588FEBE /* DemoVC.m */; }; @@ -46,6 +47,8 @@ 3D75F592D76A665674B31A66 /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-Example/Pods-Example.release.xcconfig"; sourceTree = ""; }; 4F233ACD236542275AED3DE0 /* libPods-ExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 8231E841CCAF382F85C9F576 /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Example/Pods-Example.debug.xcconfig"; sourceTree = ""; }; + 8BCADA7A23CD5B5F005EEF96 /* NavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NavigationController.h; sourceTree = ""; }; + 8BCADA7B23CD5B64005EEF96 /* NavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationController.m; sourceTree = ""; }; B93423722F2E06DC238CDD18 /* Pods-ExampleUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExampleUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-ExampleUITests/Pods-ExampleUITests.release.xcconfig"; sourceTree = ""; }; B93D4DB00FD244178B7CE7C4 /* Pods-ExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExampleTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-ExampleTests/Pods-ExampleTests.release.xcconfig"; sourceTree = ""; }; D751D18AD6496F4A9BE1AB45 /* QRScanViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QRScanViewController.h; sourceTree = ""; }; @@ -157,6 +160,8 @@ E2334AEF22E9D2060098A085 /* AppDelegate.m */, E2334AF122E9D2060098A085 /* ViewController.h */, E2334AF222E9D2060098A085 /* ViewController.m */, + 8BCADA7A23CD5B5F005EEF96 /* NavigationController.h */, + 8BCADA7B23CD5B64005EEF96 /* NavigationController.m */, E2334AF422E9D2060098A085 /* Main.storyboard */, E2334AF722E9D2070098A085 /* Assets.xcassets */, E2334AFC22E9D2070098A085 /* Info.plist */, @@ -436,6 +441,7 @@ D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */, D751D4FCC0A2322211DE3D55 /* QRScanViewController.m in Sources */, D751DDB012BAF476A252CD93 /* DemoLibrary.m in Sources */, + 8BCADA7C23CD5B65005EEF96 /* NavigationController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/doric-iOS/Example/Example/AppDelegate.m b/doric-iOS/Example/Example/AppDelegate.m index 28002f7c..ca2140a8 100644 --- a/doric-iOS/Example/Example/AppDelegate.m +++ b/doric-iOS/Example/Example/AppDelegate.m @@ -7,11 +7,12 @@ // #import "AppDelegate.h" +#import "NavigationController.h" #import "ViewController.h" @interface AppDelegate () @property(nonatomic, strong) UIViewController *rootVC; -@property(nonatomic, strong) UINavigationController *navigationController; +@property(nonatomic, strong) NavigationController *navigationController; @end @implementation AppDelegate @@ -22,9 +23,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.rootVC = [[ViewController alloc] init]; - self.window.rootViewController = self.rootVC; - self.navigationController = [[UINavigationController + self.navigationController = [[NavigationController alloc] initWithRootViewController:self.rootVC]; + self.window.rootViewController = self.navigationController; [self.window addSubview:self.navigationController.view]; [self.window makeKeyAndVisible]; return YES; diff --git a/doric-iOS/Example/Example/Info.plist b/doric-iOS/Example/Example/Info.plist index dc0608e9..6f38a78e 100644 --- a/doric-iOS/Example/Example/Info.plist +++ b/doric-iOS/Example/Example/Info.plist @@ -50,5 +50,7 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + UIViewControllerBasedStatusBarAppearance + diff --git a/doric-iOS/Example/Example/NavigationController.h b/doric-iOS/Example/Example/NavigationController.h new file mode 100644 index 00000000..6de073d6 --- /dev/null +++ b/doric-iOS/Example/Example/NavigationController.h @@ -0,0 +1,28 @@ +/* + * Copyright [2019] [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. + */ +// +// NavigationController.h +// Doric +// +// Created by jingpeng.wang on 2020/1/14. +// + +#import + +@interface NavigationController : UINavigationController + +@end + diff --git a/doric-iOS/Example/Example/NavigationController.m b/doric-iOS/Example/Example/NavigationController.m new file mode 100644 index 00000000..835ef130 --- /dev/null +++ b/doric-iOS/Example/Example/NavigationController.m @@ -0,0 +1,33 @@ +/* + * Copyright [2019] [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. + */ +// +// NavigationController.m +// Doric +// +// Created by jingpeng.wang on 2020/1/14. +// +#import "NavigationController.h" + +@implementation NavigationController + +- (UIStatusBarStyle)preferredStatusBarStyle { + return [self.topViewController preferredStatusBarStyle]; +} + +- (BOOL)prefersStatusBarHidden { + return [self.topViewController prefersStatusBarHidden]; +} +@end diff --git a/doric-iOS/Example/Example/ViewController.m b/doric-iOS/Example/Example/ViewController.m index 3fabcfa0..1116f9ed 100644 --- a/doric-iOS/Example/Example/ViewController.m +++ b/doric-iOS/Example/Example/ViewController.m @@ -6,9 +6,9 @@ // Copyright © 2019 pengfei.zhou. All rights reserved. // -#import "ViewController.h" #import -#import "DemoVC.h" + +#import "ViewController.h" #import "QRScanViewController.h" #import "DemoLibrary.h" diff --git a/doric-iOS/Pod/Classes/DoricRegistry.m b/doric-iOS/Pod/Classes/DoricRegistry.m index e50445d5..e9d243b4 100644 --- a/doric-iOS/Pod/Classes/DoricRegistry.m +++ b/doric-iOS/Pod/Classes/DoricRegistry.m @@ -47,6 +47,7 @@ #import "DoricDraggableNode.h" #import "DoricLibrary.h" #import "DoricNotificationPlugin.h" +#import "DoricStatusBarPlugin.h" #import "DoricUtil.h" @interface DoricLibraries : NSObject @@ -128,6 +129,7 @@ - (void)innerRegister { [self registerNativePlugin:DoricPopoverPlugin.class withName:@"popover"]; [self registerNativePlugin:DoricAnimatePlugin.class withName:@"animate"]; [self registerNativePlugin:DoricNotificationPlugin.class withName:@"notification"]; + [self registerNativePlugin:DoricStatusBarPlugin.class withName:@"statusbar"]; [self registerViewNode:DoricStackNode.class withName:@"Stack"]; [self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"]; diff --git a/doric-iOS/Pod/Classes/DoricViewController.h b/doric-iOS/Pod/Classes/DoricViewController.h index c4c7eb5e..249625eb 100644 --- a/doric-iOS/Pod/Classes/DoricViewController.h +++ b/doric-iOS/Pod/Classes/DoricViewController.h @@ -20,7 +20,12 @@ #import #import "DoricNavigatorDelegate.h" #import "DoricNavBarDelegate.h" +#import "DoricPanel.h" @interface DoricViewController : UIViewController +@property(nonatomic, strong) DoricPanel *doricPanel; +@property(nonatomic) BOOL statusBarHidden; +@property(nonatomic) int statusBarMode; + - (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias extra:(NSString *)extra; @end diff --git a/doric-iOS/Pod/Classes/DoricViewController.m b/doric-iOS/Pod/Classes/DoricViewController.m index d94c3863..db1266f1 100644 --- a/doric-iOS/Pod/Classes/DoricViewController.m +++ b/doric-iOS/Pod/Classes/DoricViewController.m @@ -20,13 +20,11 @@ #import "DoricViewController.h" #import "DoricAsyncResult.h" #import "DoricJSLoaderManager.h" -#import "DoricPanel.h" #import "UIView+Doric.h" #import "DoricExtensions.h" #import "DoricUtil.h" @interface DoricViewController () -@property(nonatomic, strong) DoricPanel *doricPanel; @property(nonatomic) BOOL navBarHidden; @property(nonatomic, strong) UIImage *navBarImage; @end @@ -113,5 +111,20 @@ - (void)doric_navBar_setRight:(UIView *)view { self.navigationItem.rightBarButtonItem = custom; } +- (BOOL)statusBarHidden { + return _statusBarHidden; +} + +- (UIStatusBarStyle)preferredStatusBarStyle { + if (self.statusBarMode == 0) { + return UIStatusBarStyleLightContent; + } else { + return UIStatusBarStyleDefault; + } +} + +- (BOOL)prefersStatusBarHidden { + return self.statusBarHidden; +} @end diff --git a/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.h b/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.h new file mode 100644 index 00000000..2118b358 --- /dev/null +++ b/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.h @@ -0,0 +1,26 @@ +/* + * Copyright [2019] [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 2020/01/11. +// + +#import + +#import "DoricNativePlugin.h" + +@interface DoricStatusBarPlugin : DoricNativePlugin + +@end diff --git a/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.m new file mode 100644 index 00000000..b8bd2441 --- /dev/null +++ b/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.m @@ -0,0 +1,61 @@ +/* + * Copyright [2019] [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 2020/01/11. +// + +#import "DoricStatusBarPlugin.h" +#import "DoricUtil.h" +#import "DoricViewNode.h" +#import "DoricExtensions.h" +#import "DoricViewController.h" + +@implementation DoricStatusBarPlugin + +- (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise { + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.doricContext.navBar) { + if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) { + DoricViewController * target = ((DoricViewController *)self.doricContext.navBar); + target.statusBarHidden = [param[@"hidden"] boolValue]; + [target setNeedsStatusBarAppearanceUpdate]; + } + } + }); +} + +- (void)setMode:(NSDictionary *)param withPromise:(DoricPromise *)promise { + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.doricContext.navBar) { + if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) { + DoricViewController * target = ((DoricViewController *)self.doricContext.navBar); + target.statusBarMode = [param[@"mode"] intValue]; + [target setNeedsStatusBarAppearanceUpdate]; + } + } + }); +} + +- (void)setColor:(NSDictionary *)param withPromise:(DoricPromise *)promise { + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.doricContext.navBar) { + UIColor *color = DoricColor(param[@"color"]); + [self.doricContext.navBar doric_navBar_setBackgroundColor:color]; + } + }); +} + +@end