feat:rename protocol to delegate

This commit is contained in:
pengfei.zhou 2019-11-25 14:27:14 +08:00
parent 28f29d7396
commit cec878320f
11 changed files with 33 additions and 67 deletions

View File

@ -22,5 +22,6 @@
#import "DoricUtil.h"
#import "DoricPanel.h"
#import "DoricJSLoaderManager.h"
#import "DoricNavigatorProtocol.h"
#import "DoricNavigatorDelegate.h"
#import "DoricNavBarDelegate.h"
#import "DoricViewController.h"

View File

@ -22,16 +22,16 @@
#import <Foundation/Foundation.h>
#import "DoricDriver.h"
#import "DoricNavigatorProtocol.h"
#import "DoricNavBarProtocol.h"
#import "DoricNavigatorDelegate.h"
#import "DoricNavBarDelegate.h"
NS_ASSUME_NONNULL_BEGIN
@class DoricRootNode;
@interface DoricContext : NSObject
@property(nonatomic, weak) id <DoricNavigatorProtocol> navigator;
@property(nonatomic, weak) id <DoricNavBarProtocol> navBar;
@property(nonatomic, weak) id <DoricNavigatorDelegate> navigator;
@property(nonatomic, weak) id <DoricNavBarDelegate> navBar;
@property(nonatomic, strong) NSString *contextId;
@property(nonatomic, strong) DoricDriver *driver;
@property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap;

View File

@ -20,7 +20,7 @@
#import <Foundation/Foundation.h>
#import "DoricContext.h"
#import "DoricNavigatorProtocol.h"
#import "DoricNavigatorDelegate.h"
@interface DoricPanel : UIViewController
@property(nonatomic, strong) DoricContext *doricContext;

View File

@ -18,9 +18,9 @@
//
#import <Foundation/Foundation.h>
#import "DoricNavigatorProtocol.h"
#import "DoricNavBarProtocol.h"
#import "DoricNavigatorDelegate.h"
#import "DoricNavBarDelegate.h"
@interface DoricViewController : UIViewController <DoricNavigatorProtocol, DoricNavBarProtocol>
@interface DoricViewController : UIViewController <DoricNavigatorDelegate, DoricNavBarDelegate>
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias;
@end

View File

@ -48,24 +48,28 @@ - (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias {
return self;
}
- (void)push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated {
- (void)doric_navigator_push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated {
DoricViewController *viewController = [[DoricViewController alloc] initWithScheme:scheme alias:alias];
[self.navigationController pushViewController:viewController animated:animated];
}
- (void)pop:(BOOL)animated {
- (void)doric_navigator_pop:(BOOL)animated {
[self.navigationController popViewControllerAnimated:animated];
}
- (BOOL)isHidden {
- (BOOL)doric_navBar_isHidden {
return self.navigationController.navigationBarHidden;
}
- (void)setHidden:(BOOL)hidden {
- (void)doric_navBar_setHidden:(BOOL)hidden {
[self.navigationController setNavigationBarHidden:hidden];
}
- (void)setBackgroundColor:(UIColor *)color {
- (void)doric_navBar_setTitle:(NSString *)title {
self.title = title;
}
- (void)doric_navBar_setBackgroundColor:(UIColor *)color {
[self.navigationController.navigationBar setBackgroundColor:color];
}

View File

@ -20,12 +20,12 @@
#import <Foundation/Foundation.h>
@protocol DoricNavBarProtocol <NSObject>
- (BOOL)isHidden;
@protocol DoricNavBarDelegate <NSObject>
- (BOOL)doric_navBar_isHidden;
- (void)setHidden:(BOOL)hidden;
- (void)doric_navBar_setHidden:(BOOL)hidden;
- (void)setTitle:(NSString *)title;
- (void)doric_navBar_setTitle:(NSString *)title;
- (void)setBackgroundColor:(UIColor *)color;
- (void)doric_navBar_setBackgroundColor:(UIColor *)color;
@end

View File

@ -1,10 +0,0 @@
//
// Created by pengfei.zhou on 2019/11/25.
//
#import <Foundation/Foundation.h>
#import "DoricNavigatorProtocol.h"
@interface DoricDefaultNavigator : NSObject <DoricNavigatorProtocol>
- (instancetype)initWithNavigationController:(UINavigationController *)navigationController;
@end

View File

@ -1,29 +0,0 @@
//
// Created by pengfei.zhou on 2019/11/25.
//
#import "DoricDefaultNavigator.h"
#import "DoricViewController.h"
@interface DoricDefaultNavigator ()
@property(nonatomic, weak) UINavigationController *navigationController;
@end
@implementation DoricDefaultNavigator
- (instancetype)initWithNavigationController:(UINavigationController *)navigationController {
if (self = [super init]) {
_navigationController = navigationController;
}
return self;
}
- (void)push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated {
DoricViewController *viewController = [[DoricViewController alloc] initWithScheme:scheme alias:alias];
[self.navigationController pushViewController:viewController animated:animated];
}
- (void)pop:(BOOL)animated {
[self.navigationController popViewControllerAnimated:animated];
}
@end

View File

@ -19,8 +19,8 @@
#import <Foundation/Foundation.h>
@protocol DoricNavigatorProtocol <NSObject>
- (void)push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated;
@protocol DoricNavigatorDelegate <NSObject>
- (void)doric_navigator_push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated;
- (void)pop:(BOOL)animated;
- (void)doric_navigator_pop:(BOOL)animated;
@end

View File

@ -24,7 +24,7 @@ @implementation DoricNavBarPlugin
- (void)isHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
if (self.doricContext.navBar) {
dispatch_async(dispatch_get_main_queue(), ^{
[promise resolve:@([self.doricContext.navBar isHidden])];
[promise resolve:@([self.doricContext.navBar doric_navBar_isHidden])];
});
} else {
[promise reject:@"Not implement NavBar"];
@ -34,7 +34,7 @@ - (void)isHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
- (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
if (self.doricContext.navBar) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.doricContext.navBar setHidden:[param[@"hidden"] boolValue]];
[self.doricContext.navBar doric_navBar_setHidden:[param[@"hidden"] boolValue]];
[promise resolve:nil];
});
} else {
@ -45,7 +45,7 @@ - (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
- (void)setTitle:(NSDictionary *)param withPromise:(DoricPromise *)promise {
if (self.doricContext.navBar) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.doricContext.navBar setTitle:param[@"title"]];
[self.doricContext.navBar doric_navBar_setTitle:param[@"title"]];
[promise resolve:nil];
});
} else {
@ -57,7 +57,7 @@ - (void)setBgColor:(NSDictionary *)param withPromise:(DoricPromise *)promise {
if (self.doricContext.navBar) {
dispatch_async(dispatch_get_main_queue(), ^{
UIColor *color = DoricColor(param[@"color"]);
[self.doricContext.navBar setBackgroundColor:color];
[self.doricContext.navBar doric_navBar_setBackgroundColor:color];
[promise resolve:nil];
});
} else {

View File

@ -27,7 +27,7 @@ - (void)push:(NSDictionary *)params {
if (params[@"animated"]) {
animated = [params[@"animated"] boolValue];
}
[self.doricContext.navigator push:params[@"scheme"] alias:params[@"alias"] animated:animated];
[self.doricContext.navigator doric_navigator_push:params[@"scheme"] alias:params[@"alias"] animated:animated];
});
}
@ -37,7 +37,7 @@ - (void)pop:(NSDictionary *)params {
if (params[@"animated"]) {
animated = [params[@"animated"] boolValue];
}
[self.doricContext.navigator pop:animated];
[self.doricContext.navigator doric_navigator_pop:animated];
});
}
@end