feat: iOS add ssr demo

This commit is contained in:
pengfei.zhou 2022-11-07 13:57:41 +08:00 committed by osborn
parent d416e9dc81
commit 1c306bd3f6
5 changed files with 88 additions and 10 deletions

View File

@ -26,6 +26,7 @@
E2C9315923B0A263007933D9 /* src in Resources */ = {isa = PBXBuildFile; fileRef = E2C9315823B0A263007933D9 /* src */; }; E2C9315923B0A263007933D9 /* src in Resources */ = {isa = PBXBuildFile; fileRef = E2C9315823B0A263007933D9 /* src */; };
E2EF0C0F275F6702007801C5 /* iconfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = E2EF0C0E275F6702007801C5 /* iconfont.ttf */; }; E2EF0C0F275F6702007801C5 /* iconfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = E2EF0C0E275F6702007801C5 /* iconfont.ttf */; };
E2EF0C13275F6934007801C5 /* assets in Resources */ = {isa = PBXBuildFile; fileRef = E2EF0C12275F6934007801C5 /* assets */; }; E2EF0C13275F6934007801C5 /* assets in Resources */ = {isa = PBXBuildFile; fileRef = E2EF0C12275F6934007801C5 /* assets */; };
E2F3CCB02918B44800772FF1 /* DemoSSRVC.m in Sources */ = {isa = PBXBuildFile; fileRef = E2F3CCAF2918B44800772FF1 /* DemoSSRVC.m */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@ -83,6 +84,8 @@
E2C9315823B0A263007933D9 /* src */ = {isa = PBXFileReference; lastKnownFileType = folder; name = src; path = "../../../doric-demo/bundle/src"; sourceTree = "<group>"; }; E2C9315823B0A263007933D9 /* src */ = {isa = PBXFileReference; lastKnownFileType = folder; name = src; path = "../../../doric-demo/bundle/src"; sourceTree = "<group>"; };
E2EF0C0E275F6702007801C5 /* iconfont.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = iconfont.ttf; path = "../../doric-demo/bundle/assets/iconfont.ttf"; sourceTree = "<group>"; }; E2EF0C0E275F6702007801C5 /* iconfont.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = iconfont.ttf; path = "../../doric-demo/bundle/assets/iconfont.ttf"; sourceTree = "<group>"; };
E2EF0C12275F6934007801C5 /* assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = assets; path = "../../../doric-demo/bundle/assets"; sourceTree = "<group>"; }; E2EF0C12275F6934007801C5 /* assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = assets; path = "../../../doric-demo/bundle/assets"; sourceTree = "<group>"; };
E2F3CCAF2918B44800772FF1 /* DemoSSRVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DemoSSRVC.m; sourceTree = "<group>"; };
E2F3CCB12918B49500772FF1 /* DemoSSRVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DemoSSRVC.h; sourceTree = "<group>"; };
FD2D6CCC8DCDABA7F86EAE7C /* libPods-ExampleUITests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ExampleUITests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; FD2D6CCC8DCDABA7F86EAE7C /* libPods-ExampleUITests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ExampleUITests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@ -184,6 +187,8 @@
D751DB0CB3009E12990F661E /* DemoLibrary.h */, D751DB0CB3009E12990F661E /* DemoLibrary.h */,
E24217D9287E999900F4DBEA /* DoricEmbeddedExampleVC.m */, E24217D9287E999900F4DBEA /* DoricEmbeddedExampleVC.m */,
E24217DB287E99D100F4DBEA /* DoricEmbeddedExampleVC.h */, E24217DB287E99D100F4DBEA /* DoricEmbeddedExampleVC.h */,
E2F3CCAF2918B44800772FF1 /* DemoSSRVC.m */,
E2F3CCB12918B49500772FF1 /* DemoSSRVC.h */,
); );
path = Example; path = Example;
sourceTree = "<group>"; sourceTree = "<group>";
@ -454,6 +459,7 @@
E2334AFE22E9D2070098A085 /* main.m in Sources */, E2334AFE22E9D2070098A085 /* main.m in Sources */,
E24217DA287E999900F4DBEA /* DoricEmbeddedExampleVC.m in Sources */, E24217DA287E999900F4DBEA /* DoricEmbeddedExampleVC.m in Sources */,
E2334AF022E9D2060098A085 /* AppDelegate.m in Sources */, E2334AF022E9D2060098A085 /* AppDelegate.m in Sources */,
E2F3CCB02918B44800772FF1 /* DemoSSRVC.m in Sources */,
D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */, D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */,
D751DDB012BAF476A252CD93 /* DemoLibrary.m in Sources */, D751DDB012BAF476A252CD93 /* DemoLibrary.m in Sources */,
8BCADA7C23CD5B65005EEF96 /* NavigationController.m in Sources */, 8BCADA7C23CD5B65005EEF96 /* NavigationController.m in Sources */,

View File

@ -0,0 +1,15 @@
//
// DemoSSRVC.h
// Example
//
// Created by pengfei.zhou on 2022/11/7.
// Copyright © 2022 pengfei.zhou. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface DemoSSRVC : UIViewController
- (instancetype)initWithPath:(NSString *)filePath;
@end

View File

@ -0,0 +1,52 @@
//
// DemoSSRVC.m
// Example
//
// Created by pengfei.zhou on 2022/11/7.
// Copyright © 2022 pengfei.zhou. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "DemoSSRVC.h"
#import <DoricCore/Doric.h>
#import <JavaScriptCore/JavaScriptCore.h>
@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

View File

@ -8,11 +8,11 @@
#import <DoricCore/Doric.h> #import <DoricCore/Doric.h>
#import <DoricDevkit/DoricDev.h> #import <DoricDevkit/DoricDev.h>
#import "ViewController.h" #import "ViewController.h"
#import "DemoLibrary.h" #import "DemoLibrary.h"
#import "DoricPanelListViewController.h" #import "DoricPanelListViewController.h"
#import "DoricEmbeddedExampleVC.h" #import "DoricEmbeddedExampleVC.h"
#import "DemoSSRVC.h"
@interface ViewController () <UITableViewDelegate, UITableViewDataSource> @interface ViewController () <UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, copy) NSArray <NSString *> *demoFilePaths; @property(nonatomic, copy) NSArray <NSString *> *demoFilePaths;
@ -113,6 +113,10 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
return; return;
} }
NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row]; NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row];
if ([file hasSuffix:@".json"]) {
DemoSSRVC *vc = [[DemoSSRVC alloc] initWithPath:file];
[self.navigationController pushViewController:vc animated:NO];
} else {
DoricViewController *doricViewController = [[DoricViewController alloc] DoricViewController *doricViewController = [[DoricViewController alloc]
initWithSource:[NSString stringWithFormat:@"assets://src/%@", file] initWithSource:[NSString stringWithFormat:@"assets://src/%@", file]
alias:@"__dev__"//self.demoFilePaths[(NSUInteger) indexPath.row] alias:@"__dev__"//self.demoFilePaths[(NSUInteger) indexPath.row]
@ -122,5 +126,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
doricViewController.navigationItem.rightBarButtonItem = rightBarItem; doricViewController.navigationItem.rightBarButtonItem = rightBarItem;
[self.navigationController pushViewController:doricViewController animated:NO]; [self.navigationController pushViewController:doricViewController animated:NO];
} }
}
@end @end