diff --git a/doric-iOS/Example/Example.xcodeproj/project.pbxproj b/doric-iOS/Example/Example.xcodeproj/project.pbxproj index cfe89265..b2056b5c 100644 --- a/doric-iOS/Example/Example.xcodeproj/project.pbxproj +++ b/doric-iOS/Example/Example.xcodeproj/project.pbxproj @@ -26,6 +26,7 @@ E2C9315923B0A263007933D9 /* src in Resources */ = {isa = PBXBuildFile; fileRef = E2C9315823B0A263007933D9 /* src */; }; E2EF0C0F275F6702007801C5 /* iconfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = E2EF0C0E275F6702007801C5 /* iconfont.ttf */; }; E2EF0C13275F6934007801C5 /* assets in Resources */ = {isa = PBXBuildFile; fileRef = E2EF0C12275F6934007801C5 /* assets */; }; + E2F3CCB02918B44800772FF1 /* DemoSSRVC.m in Sources */ = {isa = PBXBuildFile; fileRef = E2F3CCAF2918B44800772FF1 /* DemoSSRVC.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -83,6 +84,8 @@ E2C9315823B0A263007933D9 /* src */ = {isa = PBXFileReference; lastKnownFileType = folder; name = src; path = "../../../doric-demo/bundle/src"; sourceTree = ""; }; E2EF0C0E275F6702007801C5 /* iconfont.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = iconfont.ttf; path = "../../doric-demo/bundle/assets/iconfont.ttf"; sourceTree = ""; }; E2EF0C12275F6934007801C5 /* assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = assets; path = "../../../doric-demo/bundle/assets"; sourceTree = ""; }; + E2F3CCAF2918B44800772FF1 /* DemoSSRVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DemoSSRVC.m; sourceTree = ""; }; + E2F3CCB12918B49500772FF1 /* DemoSSRVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DemoSSRVC.h; sourceTree = ""; }; FD2D6CCC8DCDABA7F86EAE7C /* libPods-ExampleUITests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ExampleUITests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -184,6 +187,8 @@ D751DB0CB3009E12990F661E /* DemoLibrary.h */, E24217D9287E999900F4DBEA /* DoricEmbeddedExampleVC.m */, E24217DB287E99D100F4DBEA /* DoricEmbeddedExampleVC.h */, + E2F3CCAF2918B44800772FF1 /* DemoSSRVC.m */, + E2F3CCB12918B49500772FF1 /* DemoSSRVC.h */, ); path = Example; sourceTree = ""; @@ -454,6 +459,7 @@ E2334AFE22E9D2070098A085 /* main.m in Sources */, E24217DA287E999900F4DBEA /* DoricEmbeddedExampleVC.m in Sources */, E2334AF022E9D2060098A085 /* AppDelegate.m in Sources */, + E2F3CCB02918B44800772FF1 /* DemoSSRVC.m in Sources */, D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */, D751DDB012BAF476A252CD93 /* DemoLibrary.m in Sources */, 8BCADA7C23CD5B65005EEF96 /* NavigationController.m in Sources */, diff --git a/doric-iOS/Example/Example/DemoSSRVC.h b/doric-iOS/Example/Example/DemoSSRVC.h new file mode 100644 index 00000000..2f2f9dd5 --- /dev/null +++ b/doric-iOS/Example/Example/DemoSSRVC.h @@ -0,0 +1,15 @@ +// +// DemoSSRVC.h +// Example +// +// Created by pengfei.zhou on 2022/11/7. +// Copyright © 2022 pengfei.zhou. All rights reserved. +// + +#import +#import + + +@interface DemoSSRVC : UIViewController +- (instancetype)initWithPath:(NSString *)filePath; +@end diff --git a/doric-iOS/Example/Example/DemoSSRVC.m b/doric-iOS/Example/Example/DemoSSRVC.m new file mode 100644 index 00000000..bcf48f04 --- /dev/null +++ b/doric-iOS/Example/Example/DemoSSRVC.m @@ -0,0 +1,52 @@ +// +// DemoSSRVC.m +// Example +// +// Created by pengfei.zhou on 2022/11/7. +// Copyright © 2022 pengfei.zhou. All rights reserved. +// + +#import + +#import "DemoSSRVC.h" +#import +#import + +@interface DemoSSRVC () +@property(nonatomic, copy) NSString *filePath; +@end + +@implementation DemoSSRVC +- (instancetype)initWithPath:(NSString *)filePath { + if (self = [self init]) { + _filePath = filePath; + } + return self; +} + +- (void)viewDidLoad { + self.title = self.filePath; + self.view.backgroundColor = [UIColor whiteColor]; + NSString *path = [[NSBundle mainBundle] bundlePath]; + NSString *demoPath = [path stringByAppendingPathComponent:@"src"]; + NSString *fullPath = [demoPath stringByAppendingPathComponent:self.filePath]; + NSString *jsContent = [NSString stringWithContentsOfFile:fullPath encoding:NSUTF8StringEncoding error:nil]; + DoricContext *context = [[DoricContext alloc] initWithScript:@"" source:@"" extra:@""]; + DoricRootNode *rootNode = [[DoricRootNode alloc] initWithContext:context]; + [rootNode setupRootView:[[DoricRootView new] also:^(DoricRootView *it) { + it.width = self.view.width; + it.height = self.view.height; + it.clipsToBounds = YES; + it.frameChangedBlock = ^(CGSize oldSize, CGSize newSize) { + NSLog(@"frameChangedBlock:%@,%@", @(oldSize), @(newSize)); + }; + [self.view addSubview:it]; + }]]; + [context setRootNode:rootNode]; + NSData *data = [jsContent dataUsingEncoding:NSUTF8StringEncoding]; + NSDictionary *viewModels = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:NULL]; + [rootNode blend:[viewModels optObject:@"props"]]; + [rootNode requestLayout]; +} + +@end diff --git a/doric-iOS/Example/Example/ViewController.m b/doric-iOS/Example/Example/ViewController.m index 87513fea..c6bb46ee 100644 --- a/doric-iOS/Example/Example/ViewController.m +++ b/doric-iOS/Example/Example/ViewController.m @@ -8,11 +8,11 @@ #import #import - #import "ViewController.h" #import "DemoLibrary.h" #import "DoricPanelListViewController.h" #import "DoricEmbeddedExampleVC.h" +#import "DemoSSRVC.h" @interface ViewController () @property(nonatomic, copy) NSArray *demoFilePaths; @@ -113,14 +113,19 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath return; } NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row]; - DoricViewController *doricViewController = [[DoricViewController alloc] - initWithSource:[NSString stringWithFormat:@"assets://src/%@", file] - alias:@"__dev__"//self.demoFilePaths[(NSUInteger) indexPath.row] - extra:nil - ]; - UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"Devkit" style:UIBarButtonItemStylePlain target:self action:@selector(onOpenDevkit)]; - doricViewController.navigationItem.rightBarButtonItem = rightBarItem; - [self.navigationController pushViewController:doricViewController animated:NO]; + if ([file hasSuffix:@".json"]) { + DemoSSRVC *vc = [[DemoSSRVC alloc] initWithPath:file]; + [self.navigationController pushViewController:vc animated:NO]; + } else { + DoricViewController *doricViewController = [[DoricViewController alloc] + initWithSource:[NSString stringWithFormat:@"assets://src/%@", file] + alias:@"__dev__"//self.demoFilePaths[(NSUInteger) indexPath.row] + extra:nil + ]; + UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"Devkit" style:UIBarButtonItemStylePlain target:self action:@selector(onOpenDevkit)]; + doricViewController.navigationItem.rightBarButtonItem = rightBarItem; + [self.navigationController pushViewController:doricViewController animated:NO]; + } } @end diff --git a/doric-iOS/Pod/Classes/DoricSingleton.m b/doric-iOS/Pod/Classes/DoricSingleton.m index 639f9189..93a5128a 100644 --- a/doric-iOS/Pod/Classes/DoricSingleton.m +++ b/doric-iOS/Pod/Classes/DoricSingleton.m @@ -67,4 +67,4 @@ - (void)setEnvironmentValue:(NSDictionary *)value { } } } -@end \ No newline at end of file +@end