iOS: add doric panel list
This commit is contained in:
11
doric-iOS/Example/Example/DoricPanelListViewController.h
Normal file
11
doric-iOS/Example/Example/DoricPanelListViewController.h
Normal file
@@ -0,0 +1,11 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/19.
|
||||
// Copyright (c) 2019 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
@interface DoricPanelListViewController : UIViewController
|
||||
@end
|
102
doric-iOS/Example/Example/DoricPanelListViewController.m
Normal file
102
doric-iOS/Example/Example/DoricPanelListViewController.m
Normal file
@@ -0,0 +1,102 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/19.
|
||||
// Copyright (c) 2019 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
#import <DoricCore/Doric.h>
|
||||
|
||||
#import "DoricPanelListViewController.h"
|
||||
#import "DoricSingleton.h"
|
||||
|
||||
@interface DoricPanelListViewController () <UITableViewDelegate, UITableViewDataSource>
|
||||
@property(nonatomic, copy) NSArray <NSString *> *demoFilePaths;
|
||||
@property(nonatomic, strong) NSMutableDictionary *doricViewControllers;
|
||||
@end
|
||||
|
||||
@implementation DoricPanelListViewController
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_doricViewControllers = [NSMutableDictionary new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
[super viewDidAppear:animated];
|
||||
[self.view addSubview:[[UITableView new] also:^(UITableView *it) {
|
||||
it.width = self.view.width;
|
||||
it.height = self.view.height;
|
||||
it.left = it.top = 0;
|
||||
it.dataSource = self;
|
||||
it.delegate = self;
|
||||
}]];
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
self.title = @"Doric Panel List";
|
||||
[self.navigationController.navigationBar setBackgroundImage:UIImageWithColor(UIColor.whiteColor) forBarMetrics:UIBarMetricsDefault];
|
||||
NSString *path = [[NSBundle mainBundle] bundlePath];
|
||||
NSString *demoPath = [path stringByAppendingPathComponent:@"src"];
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
self.demoFilePaths = [[mgr subpathsAtPath:demoPath] filter:^BOOL(NSString *obj) {
|
||||
return ![obj containsString:@".map"] && ![obj containsString:@"es5."];
|
||||
}];
|
||||
NSMutableArray <NSString *> *tmp = [self.demoFilePaths mutableCopy];
|
||||
NSStringCompareOptions comparisonOptions = NSCaseInsensitiveSearch | NSNumericSearch | NSWidthInsensitiveSearch | NSForcedOrderingSearch;
|
||||
[tmp sortUsingComparator:^NSComparisonResult(NSString *obj1, NSString *obj2) {
|
||||
NSRange range = NSMakeRange(0, obj1.length);
|
||||
return [obj1 compare:obj2 options:comparisonOptions range:range];
|
||||
}];
|
||||
self.demoFilePaths = tmp;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
return self.demoFilePaths.count;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
NSString *cellId = [@(indexPath.row) stringValue];
|
||||
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
|
||||
if (cell == nil) {
|
||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
|
||||
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
cell.textLabel.hidden = YES;
|
||||
|
||||
NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row];
|
||||
DoricViewController *doricViewController = [[DoricViewController alloc]
|
||||
initWithSource:[NSString stringWithFormat:@"assets://src/%@", file]
|
||||
alias:@"__dev__"
|
||||
extra:nil
|
||||
];
|
||||
|
||||
[self addChildViewController:doricViewController];
|
||||
[cell.contentView addSubview:doricViewController.view];
|
||||
|
||||
doricViewController.view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
NSLayoutConstraint *leading = [NSLayoutConstraint constraintWithItem:doricViewController.view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0];
|
||||
NSLayoutConstraint *trailing = [NSLayoutConstraint constraintWithItem:doricViewController.view attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0];
|
||||
NSLayoutConstraint *top = [NSLayoutConstraint constraintWithItem:doricViewController.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0];
|
||||
NSLayoutConstraint *bottom = [NSLayoutConstraint constraintWithItem:doricViewController.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0];
|
||||
|
||||
[cell.contentView addConstraint:leading];
|
||||
[cell.contentView addConstraint:trailing];
|
||||
[cell.contentView addConstraint:top];
|
||||
[cell.contentView addConstraint:bottom];
|
||||
|
||||
[doricViewController didMoveToParentViewController:self];
|
||||
[doricViewController.view layoutIfNeeded];
|
||||
} else {
|
||||
//TODO at here to handle data bind
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return 300;
|
||||
}
|
||||
|
||||
@end
|
@@ -7,12 +7,11 @@
|
||||
//
|
||||
|
||||
#import <DoricCore/Doric.h>
|
||||
|
||||
#import <DoricDevkit/DoricDev.h>
|
||||
|
||||
#import "ViewController.h"
|
||||
|
||||
#import "DemoLibrary.h"
|
||||
#import "DoricPanelListViewController.h""
|
||||
|
||||
@interface ViewController () <UITableViewDelegate, UITableViewDataSource>
|
||||
@property(nonatomic, copy) NSArray <NSString *> *demoFilePaths;
|
||||
@@ -38,6 +37,7 @@ - (void)viewDidLoad {
|
||||
return [obj1 compare:obj2 options:comparisonOptions range:range];
|
||||
}];
|
||||
[tmp insertObject:@"Dev Kit" atIndex:0];
|
||||
[tmp insertObject:@"Doric Panel List" atIndex:1];
|
||||
self.demoFilePaths = tmp;
|
||||
|
||||
[Doric registerLibrary:[DemoLibrary new]];
|
||||
@@ -84,6 +84,19 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
|
||||
[[DoricDev instance] openDevMode:self];
|
||||
return;
|
||||
}
|
||||
if (indexPath.row == 1) {
|
||||
DoricPanelListViewController *panelListViewController = [DoricPanelListViewController new];
|
||||
|
||||
UIViewController *viewController = [UIApplication sharedApplication].delegate.window.rootViewController;
|
||||
UINavigationController *navigationController;
|
||||
if ([viewController isKindOfClass:[UINavigationController class]]) {
|
||||
navigationController = (UINavigationController *) viewController;
|
||||
} else {
|
||||
navigationController = viewController.navigationController;
|
||||
}
|
||||
[navigationController pushViewController:panelListViewController animated:NO];
|
||||
return;
|
||||
}
|
||||
NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row];
|
||||
DoricViewController *doricViewController = [[DoricViewController alloc]
|
||||
initWithSource:[NSString stringWithFormat:@"assets://src/%@", file]
|
||||
|
Reference in New Issue
Block a user