feat:The same VC use diffrent childVC
This commit is contained in:
parent
76bceb084e
commit
c666c7b81c
@ -58,8 +58,16 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
|
||||
[self.navigationController pushViewController:[QRScanViewController new] animated:NO];
|
||||
return;
|
||||
}
|
||||
DemoVC *demoVC = [[DemoVC alloc] initWithPath:self.demoFilePaths[(NSUInteger) indexPath.row]];
|
||||
[self.navigationController pushViewController:demoVC animated:NO];
|
||||
NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row];
|
||||
if ([file containsString:@"NavigatorDemo"]) {
|
||||
DoricViewController *doricViewController = [[DoricViewController alloc]
|
||||
initWithScheme:[NSString stringWithFormat:@"assets://demo/%@", file]
|
||||
alias:self.demoFilePaths[(NSUInteger) indexPath.row]];
|
||||
[self.navigationController pushViewController:doricViewController animated:NO];
|
||||
} else {
|
||||
DemoVC *demoVC = [[DemoVC alloc] initWithPath:file];
|
||||
[self.navigationController pushViewController:demoVC animated:NO];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -20,4 +20,7 @@
|
||||
#import "DoricRootNode.h"
|
||||
#import "UIView+Doric.h"
|
||||
#import "DoricUtil.h"
|
||||
#import "DoricPanel.h"
|
||||
#import "DoricPanel.h"
|
||||
#import "DoricJSLoaderManager.h"
|
||||
#import "DoricNavigatorProtocol.h"
|
||||
#import "DoricViewController.h"
|
@ -20,6 +20,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "DoricContext.h"
|
||||
#import "DoricNavigatorProtocol.h"
|
||||
|
||||
@interface DoricPanel : UIViewController
|
||||
@property(nonatomic, strong) DoricContext *doricContext;
|
||||
|
@ -20,11 +20,13 @@
|
||||
#import "DoricPanel.h"
|
||||
#import "Doric.h"
|
||||
|
||||
|
||||
@implementation DoricPanel
|
||||
|
||||
- (void)config:(NSString *)script alias:(NSString *)alias {
|
||||
self.doricContext = [[[DoricContext alloc] initWithScript:script source:alias] also:^(DoricContext *it) {
|
||||
if ([self.parentViewController conformsToProtocol:@protocol(DoricNavigatorProtocol)]) {
|
||||
it.navigator = (id <DoricNavigatorProtocol>) self.parentViewController;
|
||||
}
|
||||
[it.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) {
|
||||
it.width = self.view.width;
|
||||
it.height = self.view.height;
|
||||
@ -43,4 +45,5 @@ - (void)viewDidDisappear:(BOOL)animated {
|
||||
[super viewDidDisappear:animated];
|
||||
[self.doricContext onHidden];
|
||||
}
|
||||
@end
|
||||
|
||||
@end
|
||||
|
25
iOS/Pod/Classes/DoricViewController.h
Normal file
25
iOS/Pod/Classes/DoricViewController.h
Normal 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/11/23.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNavigatorProtocol.h"
|
||||
|
||||
@interface DoricViewController : UIViewController <DoricNavigatorProtocol>
|
||||
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias;
|
||||
@end
|
71
iOS/Pod/Classes/DoricViewController.m
Normal file
71
iOS/Pod/Classes/DoricViewController.m
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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/11/23.
|
||||
//
|
||||
|
||||
#import "DoricViewController.h"
|
||||
#import "DoricAsyncResult.h"
|
||||
#import "DoricJSLoaderManager.h"
|
||||
#import "DoricPanel.h"
|
||||
#import "UIView+Doric.h"
|
||||
#import "DoricExtensions.h"
|
||||
|
||||
@implementation DoricViewController
|
||||
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias {
|
||||
if (self = [super init]) {
|
||||
[self push:scheme alias:alias];
|
||||
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回"
|
||||
style:UIBarButtonItemStylePlain
|
||||
target:self
|
||||
action:@selector(pop)];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)push:(NSString *)scheme alias:(NSString *)alias {
|
||||
DoricAsyncResult <NSString *> *result = [DoricJSLoaderManager.instance request:scheme];
|
||||
result.resultCallback = ^(NSString *result) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
DoricPanel *panel = [DoricPanel new];
|
||||
[panel.view also:^(UIView *it) {
|
||||
it.backgroundColor = [UIColor whiteColor];
|
||||
it.width = self.view.width;
|
||||
it.height = self.view.height - 88;
|
||||
it.top = 88;
|
||||
}];
|
||||
[self.view addSubview:panel.view];
|
||||
[self addChildViewController:panel];
|
||||
[panel config:result alias:alias];
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
- (void)pop {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.childViewControllers.count > 1) {
|
||||
[self.childViewControllers.lastObject also:^(UIViewController *it) {
|
||||
[it removeFromParentViewController];
|
||||
[it.view removeFromSuperview];
|
||||
}];
|
||||
} else {
|
||||
[self.navigationController popViewControllerAnimated:NO];
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
@ -26,15 +26,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
||||
@interface DoricAsyncResult <R> : NSObject
|
||||
typedef void(^DoricResultCallback)(R);
|
||||
|
||||
typedef void(^DoricExceptionCallback)(NSException *);
|
||||
|
||||
typedef void(^DoricFinishCallback)(void);
|
||||
|
||||
@property(nonatomic, strong) DoricResultCallback resultCallback;
|
||||
@property(nonatomic, strong) DoricExceptionCallback exceptionCallback;
|
||||
@property(nonatomic, strong) DoricFinishCallback finishCallback;
|
||||
@property(nonatomic, strong) void (^resultCallback)(R result);
|
||||
@property(nonatomic, strong) void (^exceptionCallback)(NSException *e);
|
||||
@property(nonatomic, strong) void (^finishCallback)(void);
|
||||
|
||||
- (void)setupResult:(R)result;
|
||||
|
||||
|
@ -56,24 +56,24 @@ - (id)getResult {
|
||||
return self.result;
|
||||
}
|
||||
|
||||
- (void)setResultCallback:(DoricResultCallback)callback {
|
||||
- (void)setResultCallback:(void (^)(id))callback {
|
||||
_resultCallback = callback;
|
||||
if (self.result && ![self.result isKindOfClass:[NSException class]]) {
|
||||
callback(self.result);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setExceptionCallback:(DoricExceptionCallback)exceptionCallback {
|
||||
- (void)setExceptionCallback:(void (^)(NSException *))exceptionCallback {
|
||||
_exceptionCallback = exceptionCallback;
|
||||
if ([self.result isKindOfClass:[NSException class]]) {
|
||||
exceptionCallback(self.result);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setFinishCallback:(DoricFinishCallback)callback {
|
||||
_finishCallback = callback;
|
||||
- (void)setFinishCallback:(void (^)(void))finishCallback {
|
||||
_finishCallback = finishCallback;
|
||||
if (self.result) {
|
||||
callback();
|
||||
finishCallback();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user