feat:add DoricLibrary

This commit is contained in:
pengfei.zhou 2019-12-11 11:08:45 +08:00
parent 30d8fb4b71
commit 3545424f62
9 changed files with 133 additions and 1 deletions

View File

@ -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 = "<group>"; };
D751D19E97EF4EDD7588FEBE /* DemoVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoVC.m; sourceTree = "<group>"; };
D751D2175D09F2C10691FB81 /* DemoLibrary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoLibrary.m; sourceTree = "<group>"; };
D751DA399F1ADB6D34563B5D /* QRScanViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QRScanViewController.m; sourceTree = "<group>"; };
D751DB0CB3009E12990F661E /* DemoLibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoLibrary.h; sourceTree = "<group>"; };
D751DDEC114E037231257E64 /* DemoVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoVC.h; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>";
@ -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;
};

View File

@ -0,0 +1,10 @@
//
// Created by pengfei.zhou on 2019/12/11.
// Copyright (c) 2019 pengfei.zhou. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Doric/Doric.h>
@interface DemoLibrary : DoricLibrary
@end

View File

@ -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

View File

@ -10,6 +10,7 @@
#import <Doric/Doric.h>
#import "DemoVC.h"
#import "QRScanViewController.h"
#import "DemoLibrary.h"
@interface ViewController () <UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, copy) NSArray <NSString *> *demoFilePaths;
@ -41,6 +42,7 @@ - (void)viewDidLoad {
it.dataSource = self;
it.delegate = self;
}]];
[DoricRegistry register:[DemoLibrary new]];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

View File

@ -25,4 +25,6 @@
#import "DoricNavigatorDelegate.h"
#import "DoricNavBarDelegate.h"
#import "DoricViewController.h"
#import "DoricPromise.h"
#import "DoricPromise.h"
#import "DoricLibrary.h"
#import "DoricNativePlugin.h"

View File

@ -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 <Foundation/Foundation.h>
#import "DoricRegistry.h"
@interface DoricLibrary : NSObject
- (void)load:(DoricRegistry *)registry;
@end

View File

@ -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

View File

@ -23,6 +23,7 @@
#import <Foundation/Foundation.h>
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

View File

@ -43,6 +43,33 @@
#import "DoricPopoverPlugin.h"
#import "DoricAnimatePlugin.h"
#import "DoricNestedSliderNode.h"
#import "DoricLibrary.h"
@interface DoricLibraries : NSObject
@property(nonatomic, strong) NSMutableSet <DoricLibrary *> *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;
}