From 3545424f626407d7fd686746e74a7364c71b4535 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Wed, 11 Dec 2019 11:08:45 +0800 Subject: [PATCH] feat:add DoricLibrary --- Example/Example.xcodeproj/project.pbxproj | 6 ++++ Example/Example/DemoLibrary.h | 10 +++++++ Example/Example/DemoLibrary.m | 24 ++++++++++++++++ Example/Example/ViewController.m | 2 ++ Pod/Classes/Doric.h | 4 ++- Pod/Classes/DoricLibrary.h | 25 +++++++++++++++++ Pod/Classes/DoricLibrary.m | 26 +++++++++++++++++ Pod/Classes/DoricRegistry.h | 3 ++ Pod/Classes/DoricRegistry.m | 34 +++++++++++++++++++++++ 9 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 Example/Example/DemoLibrary.h create mode 100644 Example/Example/DemoLibrary.m create mode 100644 Pod/Classes/DoricLibrary.h create mode 100644 Pod/Classes/DoricLibrary.m diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index d39b1805..a2d131ee 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ C6AF7EB0B40D76A46B2BB384 /* Pods_ExampleUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF50786B1D1793EC3228133B /* Pods_ExampleUITests.framework */; }; D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */ = {isa = PBXBuildFile; fileRef = D751D19E97EF4EDD7588FEBE /* DemoVC.m */; }; D751D4FCC0A2322211DE3D55 /* QRScanViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D751DA399F1ADB6D34563B5D /* QRScanViewController.m */; }; + D751DDB012BAF476A252CD93 /* DemoLibrary.m in Sources */ = {isa = PBXBuildFile; fileRef = D751D2175D09F2C10691FB81 /* DemoLibrary.m */; }; E2334AF022E9D2060098A085 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E2334AEF22E9D2060098A085 /* AppDelegate.m */; }; E2334AF322E9D2060098A085 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E2334AF222E9D2060098A085 /* ViewController.m */; }; E2334AF622E9D2060098A085 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E2334AF422E9D2060098A085 /* Main.storyboard */; }; @@ -51,7 +52,9 @@ BF50786B1D1793EC3228133B /* Pods_ExampleUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ExampleUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D751D18AD6496F4A9BE1AB45 /* QRScanViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QRScanViewController.h; sourceTree = ""; }; D751D19E97EF4EDD7588FEBE /* DemoVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoVC.m; sourceTree = ""; }; + D751D2175D09F2C10691FB81 /* DemoLibrary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoLibrary.m; sourceTree = ""; }; D751DA399F1ADB6D34563B5D /* QRScanViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QRScanViewController.m; sourceTree = ""; }; + D751DB0CB3009E12990F661E /* DemoLibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoLibrary.h; sourceTree = ""; }; D751DDEC114E037231257E64 /* DemoVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoVC.h; sourceTree = ""; }; D91241144B5A3356A3C60644 /* Pods-ExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExampleTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ExampleTests/Pods-ExampleTests.debug.xcconfig"; sourceTree = ""; }; E2334AEB22E9D2060098A085 /* Doric Playground.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Doric Playground.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -163,6 +166,8 @@ D751DDEC114E037231257E64 /* DemoVC.h */, D751DA399F1ADB6D34563B5D /* QRScanViewController.m */, D751D18AD6496F4A9BE1AB45 /* QRScanViewController.h */, + D751D2175D09F2C10691FB81 /* DemoLibrary.m */, + D751DB0CB3009E12990F661E /* DemoLibrary.h */, ); path = Example; sourceTree = ""; @@ -430,6 +435,7 @@ E2334AF022E9D2060098A085 /* AppDelegate.m in Sources */, D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */, D751D4FCC0A2322211DE3D55 /* QRScanViewController.m in Sources */, + D751DDB012BAF476A252CD93 /* DemoLibrary.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Example/Example/DemoLibrary.h b/Example/Example/DemoLibrary.h new file mode 100644 index 00000000..0fbc97f8 --- /dev/null +++ b/Example/Example/DemoLibrary.h @@ -0,0 +1,10 @@ +// +// Created by pengfei.zhou on 2019/12/11. +// Copyright (c) 2019 pengfei.zhou. All rights reserved. +// + +#import +#import + +@interface DemoLibrary : DoricLibrary +@end \ No newline at end of file diff --git a/Example/Example/DemoLibrary.m b/Example/Example/DemoLibrary.m new file mode 100644 index 00000000..72b1df4b --- /dev/null +++ b/Example/Example/DemoLibrary.m @@ -0,0 +1,24 @@ +// +// Created by pengfei.zhou on 2019/12/11. +// Copyright (c) 2019 pengfei.zhou. All rights reserved. +// + +#import "DemoLibrary.h" + +@interface DoricDemoPlugin : DoricNativePlugin + +@end + +@implementation DoricDemoPlugin +- (void)test { + dispatch_async(dispatch_get_main_queue(), ^{ + ShowToast(@"Test called", CENTER); + }); +} +@end + +@implementation DemoLibrary +- (void)load:(DoricRegistry *)registry { + [registry registerNativePlugin:[DoricDemoPlugin class] withName:@"demo"]; +} +@end \ No newline at end of file diff --git a/Example/Example/ViewController.m b/Example/Example/ViewController.m index f2a2a583..fba9576c 100644 --- a/Example/Example/ViewController.m +++ b/Example/Example/ViewController.m @@ -10,6 +10,7 @@ #import #import "DemoVC.h" #import "QRScanViewController.h" +#import "DemoLibrary.h" @interface ViewController () @property(nonatomic, copy) NSArray *demoFilePaths; @@ -41,6 +42,7 @@ - (void)viewDidLoad { it.dataSource = self; it.delegate = self; }]]; + [DoricRegistry register:[DemoLibrary new]]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { diff --git a/Pod/Classes/Doric.h b/Pod/Classes/Doric.h index e96c2565..487653b9 100644 --- a/Pod/Classes/Doric.h +++ b/Pod/Classes/Doric.h @@ -25,4 +25,6 @@ #import "DoricNavigatorDelegate.h" #import "DoricNavBarDelegate.h" #import "DoricViewController.h" -#import "DoricPromise.h" \ No newline at end of file +#import "DoricPromise.h" +#import "DoricLibrary.h" +#import "DoricNativePlugin.h" \ No newline at end of file diff --git a/Pod/Classes/DoricLibrary.h b/Pod/Classes/DoricLibrary.h new file mode 100644 index 00000000..3fed330f --- /dev/null +++ b/Pod/Classes/DoricLibrary.h @@ -0,0 +1,25 @@ +/* + * 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 pengfei.zhou on 2019/12/11. +// + +#import +#import "DoricRegistry.h" + +@interface DoricLibrary : NSObject +- (void)load:(DoricRegistry *)registry; +@end \ No newline at end of file diff --git a/Pod/Classes/DoricLibrary.m b/Pod/Classes/DoricLibrary.m new file mode 100644 index 00000000..1e477023 --- /dev/null +++ b/Pod/Classes/DoricLibrary.m @@ -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 pengfei.zhou on 2019/12/11. +// + +#import "DoricLibrary.h" + + +@implementation DoricLibrary +- (void)load:(DoricRegistry *)registry { +} +@end \ No newline at end of file diff --git a/Pod/Classes/DoricRegistry.h b/Pod/Classes/DoricRegistry.h index 021fc88f..910affd5 100644 --- a/Pod/Classes/DoricRegistry.h +++ b/Pod/Classes/DoricRegistry.h @@ -23,6 +23,7 @@ #import NS_ASSUME_NONNULL_BEGIN +@class DoricLibrary; @interface DoricRegistry : NSObject @@ -38,6 +39,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)registerViewNode:(Class)nodeClass withName:(NSString *)name; - (Class)acquireViewNode:(NSString *)name; + ++ (void)register:(DoricLibrary *)library; @end NS_ASSUME_NONNULL_END diff --git a/Pod/Classes/DoricRegistry.m b/Pod/Classes/DoricRegistry.m index f9614756..0157912f 100644 --- a/Pod/Classes/DoricRegistry.m +++ b/Pod/Classes/DoricRegistry.m @@ -43,6 +43,33 @@ #import "DoricPopoverPlugin.h" #import "DoricAnimatePlugin.h" #import "DoricNestedSliderNode.h" +#import "DoricLibrary.h" + + +@interface DoricLibraries : NSObject +@property(nonatomic, strong) NSMutableSet *libraries; + ++ (instancetype)instance; +@end + +@implementation DoricLibraries +- (instancetype)init { + if (self = [super init]) { + _libraries = [NSMutableSet new]; + } + return self; +} + ++ (instancetype)instance { + static DoricLibraries *_instance; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + _instance = [[DoricLibraries alloc] init]; + }); + return _instance; +} + +@end @interface DoricRegistry () @@ -54,12 +81,19 @@ @interface DoricRegistry () @implementation DoricRegistry ++ (void)register:(DoricLibrary *)library { + [DoricLibraries.instance.libraries addObject:library]; +} + - (instancetype)init { if (self = [super init]) { _bundles = [[NSMutableDictionary alloc] init]; _plugins = [[NSMutableDictionary alloc] init]; _nodes = [[NSMutableDictionary alloc] init]; [self innerRegister]; + [DoricLibraries.instance.libraries enumerateObjectsUsingBlock:^(DoricLibrary *obj, BOOL *stop) { + [obj load:self]; + }]; } return self; }