iOS render

This commit is contained in:
pengfei.zhou 2019-07-31 14:18:20 +08:00
parent 20986340d7
commit 674335324b
24 changed files with 452 additions and 34 deletions

View File

@ -68,6 +68,7 @@ public abstract class GroupNode<F extends ViewGroup> extends ViewNode<F> {
mChildrenNode.remove(mIndexInfo.get(i).getId()); mChildrenNode.remove(mIndexInfo.get(i).getId());
mIndexInfo.remove(i); mIndexInfo.remove(i);
} }
i++;
} }
break; break;
default: default:

View File

@ -11,6 +11,7 @@
#import "DoricUtil.h" #import "DoricUtil.h"
#import "DoricContext.h" #import "DoricContext.h"
#import "DoricNativePlugin.h" #import "DoricNativePlugin.h"
#import "DoricRootNode.h"
@interface ViewController () @interface ViewController ()
@property (nonatomic,strong) DoricContext *doricContext; @property (nonatomic,strong) DoricContext *doricContext;
@ -33,6 +34,7 @@ - (void)viewDidLoad {
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"demo" ofType:@"js"]; NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"demo" ofType:@"js"];
NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
self.doricContext = [[DoricContext alloc] initWithScript:jsContent source:@"demo"]; self.doricContext = [[DoricContext alloc] initWithScript:jsContent source:@"demo"];
self.doricContext.rootNode.view = self.view;
[self.doricContext callEntity:@"__init__",@{@"width": [NSNumber numberWithFloat:self.view.width], [self.doricContext callEntity:@"__init__",@{@"width": [NSNumber numberWithFloat:self.view.width],
@"height":[NSNumber numberWithFloat:self.view.height]},nil]; @"height":[NSNumber numberWithFloat:self.view.height]},nil];
} }

View File

@ -55,6 +55,8 @@
DAEFBC72D2314E794132D06E15025AC3 /* DoricStackNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 12E65E9A959F203D44594250808719D0 /* DoricStackNode.h */; settings = {ATTRIBUTES = (Project, ); }; }; DAEFBC72D2314E794132D06E15025AC3 /* DoricStackNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 12E65E9A959F203D44594250808719D0 /* DoricStackNode.h */; settings = {ATTRIBUTES = (Project, ); }; };
DBC2D2D72A7B27EECC1FEA4218B74028 /* DoricShaderPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CB220633FAF5FB582354227A7889CC /* DoricShaderPlugin.m */; }; DBC2D2D72A7B27EECC1FEA4218B74028 /* DoricShaderPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CB220633FAF5FB582354227A7889CC /* DoricShaderPlugin.m */; };
DFB2B8E114B1081B0B285F7EF712C3FC /* UIView+Doric.h in Headers */ = {isa = PBXBuildFile; fileRef = A5FB6A497277059BC11DABD9A4F56AB5 /* UIView+Doric.h */; settings = {ATTRIBUTES = (Project, ); }; }; DFB2B8E114B1081B0B285F7EF712C3FC /* UIView+Doric.h in Headers */ = {isa = PBXBuildFile; fileRef = A5FB6A497277059BC11DABD9A4F56AB5 /* UIView+Doric.h */; settings = {ATTRIBUTES = (Project, ); }; };
E2FC3FE622F13018007A4E57 /* DoricTextNode.h in Headers */ = {isa = PBXBuildFile; fileRef = E2FC3FE422F13018007A4E57 /* DoricTextNode.h */; };
E2FC3FE722F13018007A4E57 /* DoricTextNode.m in Sources */ = {isa = PBXBuildFile; fileRef = E2FC3FE522F13018007A4E57 /* DoricTextNode.m */; };
F2F6D32AD0E092DD80D34AEADAC1606E /* DoricGroupNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 40217AFE8466A394D1004596D7804FCE /* DoricGroupNode.h */; settings = {ATTRIBUTES = (Project, ); }; }; F2F6D32AD0E092DD80D34AEADAC1606E /* DoricGroupNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 40217AFE8466A394D1004596D7804FCE /* DoricGroupNode.h */; settings = {ATTRIBUTES = (Project, ); }; };
F598DDE0FA1FE0CC6F09499064B01761 /* DoricHLayoutNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 9145FEC14942C0A3829F08841A321931 /* DoricHLayoutNode.h */; settings = {ATTRIBUTES = (Project, ); }; }; F598DDE0FA1FE0CC6F09499064B01761 /* DoricHLayoutNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 9145FEC14942C0A3829F08841A321931 /* DoricHLayoutNode.h */; settings = {ATTRIBUTES = (Project, ); }; };
F939A4A137B61D2362519D8F5381DC4E /* DoricJSEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B71CB0B4480EA08DD35197F06DBF38 /* DoricJSEngine.m */; }; F939A4A137B61D2362519D8F5381DC4E /* DoricJSEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B71CB0B4480EA08DD35197F06DBF38 /* DoricJSEngine.m */; };
@ -88,16 +90,16 @@
0A5A03FDB5D69AFA8105CD95F537E7B4 /* DoricVLayoutNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricVLayoutNode.h; sourceTree = "<group>"; }; 0A5A03FDB5D69AFA8105CD95F537E7B4 /* DoricVLayoutNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricVLayoutNode.h; sourceTree = "<group>"; };
11F84157E3FED749ED2F53440014CF74 /* DoricContext.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricContext.m; path = Pod/Classes/DoricContext.m; sourceTree = "<group>"; }; 11F84157E3FED749ED2F53440014CF74 /* DoricContext.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricContext.m; path = Pod/Classes/DoricContext.m; sourceTree = "<group>"; };
12E65E9A959F203D44594250808719D0 /* DoricStackNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricStackNode.h; sourceTree = "<group>"; }; 12E65E9A959F203D44594250808719D0 /* DoricStackNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricStackNode.h; sourceTree = "<group>"; };
165E0A231E9DDF8E3C3B339C5F991D2B /* Doric.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; lastKnownFileType = text; path = Doric.podspec; sourceTree = "<group>"; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 165E0A231E9DDF8E3C3B339C5F991D2B /* Doric.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; path = Doric.podspec; sourceTree = "<group>"; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
1DC97F881F42239F4D5EE57FE5266B1F /* Pods-ExampleUITests-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-ExampleUITests-acknowledgements.plist"; sourceTree = "<group>"; }; 1DC97F881F42239F4D5EE57FE5266B1F /* Pods-ExampleUITests-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-ExampleUITests-acknowledgements.plist"; sourceTree = "<group>"; };
1E9FEEA40A1420C03A9FA2DF019E8394 /* DoricAsyncResult.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricAsyncResult.h; sourceTree = "<group>"; }; 1E9FEEA40A1420C03A9FA2DF019E8394 /* DoricAsyncResult.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricAsyncResult.h; sourceTree = "<group>"; };
1EA815FA2776C872BADBFAE526312474 /* DoricGroupNode.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricGroupNode.m; sourceTree = "<group>"; }; 1EA815FA2776C872BADBFAE526312474 /* DoricGroupNode.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricGroupNode.m; sourceTree = "<group>"; };
1F667CC0E19EAF34E5A4119E2121F585 /* libPods-Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libPods-Example.a"; path = "libPods-Example.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 1F667CC0E19EAF34E5A4119E2121F585 /* libPods-Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Example.a"; sourceTree = BUILT_PRODUCTS_DIR; };
1FE791173F73E0ABC7A884D6D34A851A /* doric-sandbox.js */ = {isa = PBXFileReference; includeInIndex = 1; name = "doric-sandbox.js"; path = "../js-framework/bundle/doric-sandbox.js"; sourceTree = "<group>"; }; 1FE791173F73E0ABC7A884D6D34A851A /* doric-sandbox.js */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.javascript; name = "doric-sandbox.js"; path = "../js-framework/bundle/doric-sandbox.js"; sourceTree = "<group>"; };
21C8D570F3695E2C55CF1650F47FDB8E /* DoricPromise.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricPromise.h; sourceTree = "<group>"; }; 21C8D570F3695E2C55CF1650F47FDB8E /* DoricPromise.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricPromise.h; sourceTree = "<group>"; };
28C3F6DCBC4FB144EEE0564B6299B0CB /* DoricJSExecutorProtocal.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricJSExecutorProtocal.h; sourceTree = "<group>"; }; 28C3F6DCBC4FB144EEE0564B6299B0CB /* DoricJSExecutorProtocal.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricJSExecutorProtocal.h; sourceTree = "<group>"; };
2A58BA4FA12990F611D58B20153AF80B /* DoricRootNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricRootNode.h; sourceTree = "<group>"; }; 2A58BA4FA12990F611D58B20153AF80B /* DoricRootNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricRootNode.h; sourceTree = "<group>"; };
2EC07F016FD484CA2F44DB97705AAFE7 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; path = LICENSE; sourceTree = "<group>"; }; 2EC07F016FD484CA2F44DB97705AAFE7 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
34B71CB0B4480EA08DD35197F06DBF38 /* DoricJSEngine.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricJSEngine.m; sourceTree = "<group>"; }; 34B71CB0B4480EA08DD35197F06DBF38 /* DoricJSEngine.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricJSEngine.m; sourceTree = "<group>"; };
34CB220633FAF5FB582354227A7889CC /* DoricShaderPlugin.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricShaderPlugin.m; sourceTree = "<group>"; }; 34CB220633FAF5FB582354227A7889CC /* DoricShaderPlugin.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricShaderPlugin.m; sourceTree = "<group>"; };
35D3ADD1FF0C9A33D86DB110C181048B /* Pods-ExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-ExampleTests.debug.xcconfig"; sourceTree = "<group>"; }; 35D3ADD1FF0C9A33D86DB110C181048B /* Pods-ExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-ExampleTests.debug.xcconfig"; sourceTree = "<group>"; };
@ -115,7 +117,7 @@
4F4F7A3F234E0CFD4CD49EFC295447B7 /* DoricNativePlugin.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricNativePlugin.h; sourceTree = "<group>"; }; 4F4F7A3F234E0CFD4CD49EFC295447B7 /* DoricNativePlugin.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricNativePlugin.h; sourceTree = "<group>"; };
50CE420621B9D9ED01E06A8EDBD3E990 /* Pods-ExampleUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-ExampleUITests.release.xcconfig"; sourceTree = "<group>"; }; 50CE420621B9D9ED01E06A8EDBD3E990 /* Pods-ExampleUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-ExampleUITests.release.xcconfig"; sourceTree = "<group>"; };
57728CFE03A4D88821681C3D55A1FA85 /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Example.release.xcconfig"; sourceTree = "<group>"; }; 57728CFE03A4D88821681C3D55A1FA85 /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Example.release.xcconfig"; sourceTree = "<group>"; };
630CABE8F692FCDBFD1B122A2D0CE388 /* libPods-ExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libPods-ExampleTests.a"; path = "libPods-ExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 630CABE8F692FCDBFD1B122A2D0CE388 /* libPods-ExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
643CD220E77EB474B7A3E56677D5423E /* Doric.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = Doric.xcconfig; sourceTree = "<group>"; }; 643CD220E77EB474B7A3E56677D5423E /* Doric.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = Doric.xcconfig; sourceTree = "<group>"; };
672ED840695CA6755DECF6030784FB37 /* DoricBridgeExtension.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricBridgeExtension.m; sourceTree = "<group>"; }; 672ED840695CA6755DECF6030784FB37 /* DoricBridgeExtension.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricBridgeExtension.m; sourceTree = "<group>"; };
673C99F302C0D91311C4BEAB6C3F5DD2 /* DoricJSCoreExecutor.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricJSCoreExecutor.m; sourceTree = "<group>"; }; 673C99F302C0D91311C4BEAB6C3F5DD2 /* DoricJSCoreExecutor.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricJSCoreExecutor.m; sourceTree = "<group>"; };
@ -133,7 +135,7 @@
912DD5AC9B73450AB46CAC837632066E /* DoricDriver.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricDriver.h; path = Pod/Classes/DoricDriver.h; sourceTree = "<group>"; }; 912DD5AC9B73450AB46CAC837632066E /* DoricDriver.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricDriver.h; path = Pod/Classes/DoricDriver.h; sourceTree = "<group>"; };
9145FEC14942C0A3829F08841A321931 /* DoricHLayoutNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricHLayoutNode.h; sourceTree = "<group>"; }; 9145FEC14942C0A3829F08841A321931 /* DoricHLayoutNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricHLayoutNode.h; sourceTree = "<group>"; };
9CF6301AAD07F98FE89F30E7B5A07161 /* Pods-ExampleTests-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-ExampleTests-acknowledgements.plist"; sourceTree = "<group>"; }; 9CF6301AAD07F98FE89F30E7B5A07161 /* Pods-ExampleTests-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-ExampleTests-acknowledgements.plist"; sourceTree = "<group>"; };
9D940727FF8FB9C785EB98E56350EF41 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 9D940727FF8FB9C785EB98E56350EF41 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
9E3E205626DEE3A3A286F86069A99224 /* DoricContext.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricContext.h; path = Pod/Classes/DoricContext.h; sourceTree = "<group>"; }; 9E3E205626DEE3A3A286F86069A99224 /* DoricContext.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricContext.h; path = Pod/Classes/DoricContext.h; sourceTree = "<group>"; };
A12EA2D6D6F629978F16C0E458152B6E /* Pods-ExampleTests-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-ExampleTests-acknowledgements.markdown"; sourceTree = "<group>"; }; A12EA2D6D6F629978F16C0E458152B6E /* Pods-ExampleTests-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-ExampleTests-acknowledgements.markdown"; sourceTree = "<group>"; };
A5C03B5A2EF5BC47137E15CB4EBFE525 /* DoricContextHolder.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricContextHolder.h; path = Pod/Classes/DoricContextHolder.h; sourceTree = "<group>"; }; A5C03B5A2EF5BC47137E15CB4EBFE525 /* DoricContextHolder.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricContextHolder.h; path = Pod/Classes/DoricContextHolder.h; sourceTree = "<group>"; };
@ -141,15 +143,17 @@
A7BBF360102FA3B4372193E445788A75 /* DoricConstant.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricConstant.m; sourceTree = "<group>"; }; A7BBF360102FA3B4372193E445788A75 /* DoricConstant.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricConstant.m; sourceTree = "<group>"; };
AAC90DCBF1BFE57FD63FA71236CD9617 /* DoricUtil.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricUtil.h; sourceTree = "<group>"; }; AAC90DCBF1BFE57FD63FA71236CD9617 /* DoricUtil.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricUtil.h; sourceTree = "<group>"; };
AEAB7D461045D326881C99D36EB09F06 /* DoricContextManager.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricContextManager.m; path = Pod/Classes/DoricContextManager.m; sourceTree = "<group>"; }; AEAB7D461045D326881C99D36EB09F06 /* DoricContextManager.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricContextManager.m; path = Pod/Classes/DoricContextManager.m; sourceTree = "<group>"; };
C232398D4E3A40F2337F8A40D7F8D751 /* libPods-ExampleUITests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libPods-ExampleUITests.a"; path = "libPods-ExampleUITests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; C232398D4E3A40F2337F8A40D7F8D751 /* libPods-ExampleUITests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ExampleUITests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
C40472CC88C197C1D9E0FAEF8AEEA012 /* DoricUtil.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricUtil.m; sourceTree = "<group>"; }; C40472CC88C197C1D9E0FAEF8AEEA012 /* DoricUtil.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricUtil.m; sourceTree = "<group>"; };
C6D6AA5E2B4BA8E824A10E9272A0C408 /* DoricNativePlugin.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricNativePlugin.m; sourceTree = "<group>"; }; C6D6AA5E2B4BA8E824A10E9272A0C408 /* DoricNativePlugin.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricNativePlugin.m; sourceTree = "<group>"; };
C78507DD6E36D475B8675ACBB6CB29BB /* DoricRegistry.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricRegistry.m; path = Pod/Classes/DoricRegistry.m; sourceTree = "<group>"; }; C78507DD6E36D475B8675ACBB6CB29BB /* DoricRegistry.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricRegistry.m; path = Pod/Classes/DoricRegistry.m; sourceTree = "<group>"; };
CB6504BD07E3990E6F058E4073421ADA /* libDoric.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libDoric.a; path = libDoric.a; sourceTree = BUILT_PRODUCTS_DIR; }; CB6504BD07E3990E6F058E4073421ADA /* libDoric.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libDoric.a; sourceTree = BUILT_PRODUCTS_DIR; };
D1CC34B6D8FB8039D88C3D24DD3AFA6F /* doric-lib.js */ = {isa = PBXFileReference; includeInIndex = 1; name = "doric-lib.js"; path = "../js-framework/bundle/doric-lib.js"; sourceTree = "<group>"; }; D1CC34B6D8FB8039D88C3D24DD3AFA6F /* doric-lib.js */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.javascript; name = "doric-lib.js"; path = "../js-framework/bundle/doric-lib.js"; sourceTree = "<group>"; };
D94AF2C3306CFE8E84FE37B99B27675B /* DoricModalPlugin.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricModalPlugin.h; sourceTree = "<group>"; }; D94AF2C3306CFE8E84FE37B99B27675B /* DoricModalPlugin.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricModalPlugin.h; sourceTree = "<group>"; };
DC9CA9CA257999E08AC1FF1683E7A4D0 /* DoricViewNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricViewNode.h; sourceTree = "<group>"; }; DC9CA9CA257999E08AC1FF1683E7A4D0 /* DoricViewNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricViewNode.h; sourceTree = "<group>"; };
DFFAD17E7567EE856A59F246D50A9B0B /* Pods-Example-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-Example-acknowledgements.plist"; sourceTree = "<group>"; }; DFFAD17E7567EE856A59F246D50A9B0B /* Pods-Example-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-Example-acknowledgements.plist"; sourceTree = "<group>"; };
E2FC3FE422F13018007A4E57 /* DoricTextNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoricTextNode.h; sourceTree = "<group>"; };
E2FC3FE522F13018007A4E57 /* DoricTextNode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DoricTextNode.m; sourceTree = "<group>"; };
E340F908A05867E06E975FDCDD32315C /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Example.debug.xcconfig"; sourceTree = "<group>"; }; E340F908A05867E06E975FDCDD32315C /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Example.debug.xcconfig"; sourceTree = "<group>"; };
E6260EBC3191F783549F257021CB739F /* DoricBridgeExtension.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricBridgeExtension.h; sourceTree = "<group>"; }; E6260EBC3191F783549F257021CB739F /* DoricBridgeExtension.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricBridgeExtension.h; sourceTree = "<group>"; };
E7932F4E2884A330FF1506551365C865 /* DoricShaderPlugin.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricShaderPlugin.h; sourceTree = "<group>"; }; E7932F4E2884A330FF1506551365C865 /* DoricShaderPlugin.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricShaderPlugin.h; sourceTree = "<group>"; };
@ -280,6 +284,8 @@
460F14FF387A5DD08430DA1FD75E10EE /* DoricViewNode.m */, 460F14FF387A5DD08430DA1FD75E10EE /* DoricViewNode.m */,
0A5A03FDB5D69AFA8105CD95F537E7B4 /* DoricVLayoutNode.h */, 0A5A03FDB5D69AFA8105CD95F537E7B4 /* DoricVLayoutNode.h */,
49D245CB8651BC5097588071D90D8EA5 /* DoricVLayoutNode.m */, 49D245CB8651BC5097588071D90D8EA5 /* DoricVLayoutNode.m */,
E2FC3FE422F13018007A4E57 /* DoricTextNode.h */,
E2FC3FE522F13018007A4E57 /* DoricTextNode.m */,
); );
name = Shader; name = Shader;
path = Pod/Classes/Shader; path = Pod/Classes/Shader;
@ -448,6 +454,7 @@
DAEFBC72D2314E794132D06E15025AC3 /* DoricStackNode.h in Headers */, DAEFBC72D2314E794132D06E15025AC3 /* DoricStackNode.h in Headers */,
13A302CDD2B011A4DF5CF1112E09E937 /* DoricUtil.h in Headers */, 13A302CDD2B011A4DF5CF1112E09E937 /* DoricUtil.h in Headers */,
0A85A5F9A3EE11F072A89DE84A6FA0B8 /* DoricViewContainer.h in Headers */, 0A85A5F9A3EE11F072A89DE84A6FA0B8 /* DoricViewContainer.h in Headers */,
E2FC3FE622F13018007A4E57 /* DoricTextNode.h in Headers */,
CDB42B526F58B185A238F2F725094FA3 /* DoricViewNode.h in Headers */, CDB42B526F58B185A238F2F725094FA3 /* DoricViewNode.h in Headers */,
A2A8E68788BDBA92162E3958CC947636 /* DoricVLayoutNode.h in Headers */, A2A8E68788BDBA92162E3958CC947636 /* DoricVLayoutNode.h in Headers */,
DFB2B8E114B1081B0B285F7EF712C3FC /* UIView+Doric.h in Headers */, DFB2B8E114B1081B0B285F7EF712C3FC /* UIView+Doric.h in Headers */,
@ -616,6 +623,7 @@
81D52405D6E15FB19C6ADE196CEBFED4 /* DoricNativePlugin.m in Sources */, 81D52405D6E15FB19C6ADE196CEBFED4 /* DoricNativePlugin.m in Sources */,
9819AF9920746EF21542E98566455571 /* DoricPromise.m in Sources */, 9819AF9920746EF21542E98566455571 /* DoricPromise.m in Sources */,
159F44077D988BE31CFAA0FABB4B97F5 /* DoricRegistry.m in Sources */, 159F44077D988BE31CFAA0FABB4B97F5 /* DoricRegistry.m in Sources */,
E2FC3FE722F13018007A4E57 /* DoricTextNode.m in Sources */,
1E3AEF0D767322EEB63622B26806ACEE /* DoricRootNode.m in Sources */, 1E3AEF0D767322EEB63622B26806ACEE /* DoricRootNode.m in Sources */,
DBC2D2D72A7B27EECC1FEA4218B74028 /* DoricShaderPlugin.m in Sources */, DBC2D2D72A7B27EECC1FEA4218B74028 /* DoricShaderPlugin.m in Sources */,
0F15CD85BB2DB16EAADAD04B6FCE5A86 /* DoricStackNode.m in Sources */, 0F15CD85BB2DB16EAADAD04B6FCE5A86 /* DoricStackNode.m in Sources */,

View File

@ -10,11 +10,14 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class DoricRootNode;
@interface DoricContext : NSObject @interface DoricContext : NSObject
@property (nonatomic,strong) NSString *contextId; @property (nonatomic,strong) NSString *contextId;
@property (nonatomic,strong) DoricDriver *driver; @property (nonatomic,strong) DoricDriver *driver;
@property (nonatomic,strong) NSMutableDictionary *pluginInstanceMap; @property (nonatomic,strong) NSMutableDictionary *pluginInstanceMap;
@property (nonatomic,strong) DoricRootNode *rootNode;
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source; - (instancetype)initWithScript:(NSString *)script source:(NSString *)source;

View File

@ -7,6 +7,7 @@
#import "DoricContext.h" #import "DoricContext.h"
#import "DoricContextManager.h" #import "DoricContextManager.h"
#import "DoricRootNode.h"
@implementation DoricContext @implementation DoricContext
@ -15,6 +16,7 @@ - (instancetype)initWithScript:(NSString *)script source:(NSString *)source {
_driver = [DoricDriver instance]; _driver = [DoricDriver instance];
_pluginInstanceMap = [[NSMutableDictionary alloc] init]; _pluginInstanceMap = [[NSMutableDictionary alloc] init];
[[DoricContextManager instance] createContext:self script:script source:source]; [[DoricContextManager instance] createContext:self script:script source:source];
_rootNode = [[DoricRootNode alloc] initWithContext:self];
} }
return self; return self;
} }

View File

@ -11,6 +11,7 @@
#import "DoricStackNode.h" #import "DoricStackNode.h"
#import "DoricVLayoutNode.h" #import "DoricVLayoutNode.h"
#import "DoricHLayoutNode.h" #import "DoricHLayoutNode.h"
#import "DoricTextNode.h"
@interface DoricRegistry () @interface DoricRegistry ()
@ -39,6 +40,8 @@ - (void)innerRegister {
[self registerViewNode:DoricStackNode.class withName:@"Stack"]; [self registerViewNode:DoricStackNode.class withName:@"Stack"];
[self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"]; [self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"];
[self registerViewNode:DoricHLayoutNode.class withName:@"HLayout"]; [self registerViewNode:DoricHLayoutNode.class withName:@"HLayout"];
[self registerViewNode:DoricTextNode.class withName:@"Text"];
} }
- (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name { - (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name {

View File

@ -6,11 +6,16 @@
// //
#import "DoricShaderPlugin.h" #import "DoricShaderPlugin.h"
#import "DoricRootNode.h"
@implementation DoricShaderPlugin @implementation DoricShaderPlugin
- (void)render:(NSDictionary *)argument withPromise:(DoricPromise *)promise { - (void)render:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
NSLog(@"%@",argument); __weak typeof(self) _self = self;
dispatch_async(dispatch_get_main_queue(), ^{
__strong typeof(_self) self = _self;
[self.doricContext.rootNode render:[argument objectForKey:@"props"]];
});
} }
@end @end

View File

@ -12,6 +12,10 @@ NS_ASSUME_NONNULL_BEGIN
@interface DoricGroupNode : DoricViewNode<UIView *> @interface DoricGroupNode : DoricViewNode<UIView *>
@property (nonatomic,strong) NSMutableDictionary *children; @property (nonatomic,strong) NSMutableDictionary *children;
@property (nonatomic,strong) NSMutableArray *indexedChildren;
@property (nonatomic) CGFloat desiredWidth;
@property (nonatomic) CGFloat desiredHeight;
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig; - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig;

View File

@ -7,16 +7,12 @@
#import "DoricGroupNode.h" #import "DoricGroupNode.h"
@interface DoricGroupNode ()
@property (nonatomic,strong) NSMutableArray *indexInfo;
@end
@implementation DoricGroupNode @implementation DoricGroupNode
- (instancetype)init { - (instancetype)init {
if(self = [super init]) { if(self = [super init]) {
_children = [[NSMutableDictionary alloc] init]; _children = [[NSMutableDictionary alloc] init];
_indexInfo = [[NSMutableArray alloc] init]; _indexedChildren = [[NSMutableArray alloc] init];
} }
return self; return self;
} }
@ -52,18 +48,20 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
params = [self generateDefaultLayoutParams]; params = [self generateDefaultLayoutParams];
} }
[node blend:[val objectForKey:@"props"]]; [node blend:[val objectForKey:@"props"]];
if ([self.indexInfo objectAtIndex:i] == nil) { if ([self.indexedChildren objectAtIndex:i] == nil) {
[self.view insertSubview:node.view atIndex:i]; [self.view insertSubview:node.view atIndex:i];
[self.indexInfo setObject:node atIndexedSubscript:i]; [self.indexedChildren setObject:node atIndexedSubscript:i];
} }
} }
for (; i < self.view.subviews.count; i++) {
while (i < self.view.subviews.count) {
[self.view.subviews[i] removeFromSuperview]; [self.view.subviews[i] removeFromSuperview];
DoricViewNode *node = [self.indexInfo objectAtIndex:i]; DoricViewNode *node = [self.indexedChildren objectAtIndex:i];
if (node != nil) { if (node != nil) {
[self.children removeObjectForKey: node.viewId]; [self.children removeObjectForKey: node.viewId];
[self.indexInfo removeObjectAtIndex:i]; [self.indexedChildren removeObjectAtIndex:i];
} }
i++;
} }
} else { } else {
[super blendView:view forPropName:name propValue:prop]; [super blendView:view forPropName:name propValue:prop];
@ -78,9 +76,12 @@ - (LayoutParams *)generateDefaultLayoutParams {
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig { - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig {
LayoutParams *params = child.layoutParams; LayoutParams *params = child.layoutParams;
NSDictionary *margin = [layoutconfig objectForKey:@"margin"]; NSDictionary *margin = [layoutconfig objectForKey:@"margin"];
if (margin) {
params.margin.top = [(NSNumber *)[margin objectForKey:@"top"] floatValue]; params.margin.top = [(NSNumber *)[margin objectForKey:@"top"] floatValue];
params.margin.left = [(NSNumber *)[margin objectForKey:@"left"] floatValue]; params.margin.left = [(NSNumber *)[margin objectForKey:@"left"] floatValue];
params.margin.right = [(NSNumber *)[margin objectForKey:@"right"] floatValue]; params.margin.right = [(NSNumber *)[margin objectForKey:@"right"] floatValue];
params.margin.bottom = [(NSNumber *)[margin objectForKey:@"bottom"] floatValue]; params.margin.bottom = [(NSNumber *)[margin objectForKey:@"bottom"] floatValue];
} }
}
@end @end

View File

@ -10,7 +10,8 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricHLayoutNode : DoricGroupNode @interface DoricHLayoutNode : DoricGroupNode
@property (nonatomic) CGFloat space;
@property (nonatomic) DoricGravity gravity;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -8,5 +8,39 @@
#import "DoricHLayoutNode.h" #import "DoricHLayoutNode.h"
@implementation DoricHLayoutNode @implementation DoricHLayoutNode
- (instancetype)init {
if (self = [super init]) {
_space = 0;
_gravity = 0;
}
return self;
}
- (void)measureByParent:(DoricGroupNode *)parent {
DoricLayoutDesc widthSpec = self.layoutParams.width;
DoricLayoutDesc heightSpec = self.layoutParams.height;
CGFloat maxWidth = 0,maxHeight = 0;
for (DoricViewNode *child in self.indexedChildren) {
[child measureByParent:self];
UIView *childView = child.view;
CGFloat placeWidth = childView.width + child.layoutParams.margin.left + child.layoutParams.margin.right;
CGFloat placeHeight = childView.height + child.layoutParams.margin.top + child.layoutParams.margin.bottom;
maxWidth += placeWidth + self.space;
maxHeight = MAX(maxHeight, placeHeight);
}
maxWidth -= self.space;
self.desiredWidth = maxWidth;
self.desiredHeight = maxHeight;
if (widthSpec == LAYOUT_WRAP_CONTENT) {
self.view.width = maxWidth;
}
if (heightSpec == LAYOUT_WRAP_CONTENT) {
self.view.height = maxHeight;
}
}
@end @end

View File

@ -11,6 +11,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface DoricRootNode : DoricStackNode @interface DoricRootNode : DoricStackNode
- (void)setupRootView:(UIView *)view;
- (void)render:(NSDictionary *)props;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -8,5 +8,18 @@
#import "DoricRootNode.h" #import "DoricRootNode.h"
@implementation DoricRootNode @implementation DoricRootNode
- (void)setupRootView:(UIView *)view {
self.view = view;
}
- (void)measureByParent:(DoricGroupNode *)parent {
// Do noting for root
}
- (void)render:(NSDictionary *)props {
[self blend:props];
[self measureByParent:self];
}
@end @end

View File

@ -10,7 +10,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricStackNode : DoricGroupNode @interface DoricStackNode : DoricGroupNode
@property (nonatomic) DoricGravity gravity;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -9,4 +9,67 @@
@implementation DoricStackNode @implementation DoricStackNode
- (instancetype)init {
if (self = [super init]){
_gravity = 0;
}
return self;
}
- (void)measureByParent:(DoricGroupNode *)parent {
DoricLayoutDesc widthSpec = self.layoutParams.width;
DoricLayoutDesc heightSpec = self.layoutParams.height;
CGFloat maxWidth = 0,maxHeight = 0;
for (DoricViewNode *child in self.indexedChildren) {
[child measureByParent:self];
UIView *childView = child.view;
CGFloat placeWidth = childView.width + child.layoutParams.margin.left + child.layoutParams.margin.right;
CGFloat placeHeight = childView.height + child.layoutParams.margin.top + child.layoutParams.margin.bottom;
maxWidth = MAX(maxWidth, placeWidth);
maxHeight = MAX(maxHeight, placeHeight);
}
self.desiredWidth = maxWidth;
self.desiredHeight = maxHeight;
if (widthSpec == LAYOUT_WRAP_CONTENT) {
self.view.width = maxWidth;
}
if (heightSpec == LAYOUT_WRAP_CONTENT) {
self.view.height = maxHeight;
}
}
- (void)layoutByParent:(DoricGroupNode *)parent {
for (DoricViewNode *child in self.indexedChildren) {
[child measureByParent:self];
UIView *childView = child.view;
if (child.layoutParams.width == LAYOUT_MATCH_PARENT) {
childView.width = self.view.width;
}
if (child.layoutParams.height == LAYOUT_MATCH_PARENT) {
childView.height = self.view.height;
}
DoricGravity gravity = self.layoutParams.alignment;
if ((gravity & LEFT) == LEFT) {
childView.left = self.view.left;
}
if ((gravity & RIGHT) == RIGHT) {
childView.right = self.view.right;
}
if ((gravity & TOP) == TOP) {
childView.top = self.view.top;
}
if ((gravity & BOTTOM) == BOTTOM) {
childView.bottom = self.view.bottom;
}
if ((gravity & CENTER_X) == CENTER_X) {
childView.centerX = self.view.centerX;
}
if ((gravity & CENTER_Y) == CENTER_Y) {
childView.centerY = self.view.centerY;
}
}
}
@end @end

View File

@ -0,0 +1,16 @@
//
// DoricTextNode.h
// Doric
//
// Created by pengfei.zhou on 2019/7/31.
//
#import "DoricViewNode.h"
NS_ASSUME_NONNULL_BEGIN
@interface DoricTextNode : DoricViewNode<UILabel *>
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,50 @@
//
// DoricTextNode.m
// Doric
//
// Created by pengfei.zhou on 2019/7/31.
//
#import "DoricTextNode.h"
#import "DoricUtil.h"
#import "DoricGroupNode.h"
@implementation DoricTextNode
- (id)build:(NSDictionary *)props {
return [[UILabel alloc] init];
}
- (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)prop {
if ([name isEqualToString:@"text"]) {
view.text = prop;
} else if ([name isEqualToString:@"textSize"]) {
view.font = [UIFont systemFontOfSize:[(NSNumber *)prop floatValue]];
} else if ([name isEqualToString:@"textColor"]) {
view.textColor = DoricColor(prop);
} else if ([name isEqualToString:@"textAlignment"]) {
DoricGravity gravity = [(NSNumber *)prop integerValue];
NSTextAlignment alignment = NSTextAlignmentCenter;
switch (gravity) {
case LEFT:
alignment = NSTextAlignmentLeft;
break;
case RIGHT:
alignment = NSTextAlignmentRight;
break;
default:
break;
}
view.textAlignment = alignment;
} else {
[super blendView:view forPropName:name propValue:prop];
}
}
- (void)measureByParent:(DoricGroupNode *)parent {
DoricLayoutDesc widthSpec = self.layoutParams.width;
DoricLayoutDesc heightSpec = self.layoutParams.height;
if (widthSpec == LAYOUT_WRAP_CONTENT || heightSpec == LAYOUT_WRAP_CONTENT) {
[self.view sizeToFit];
}
}
@end

View File

@ -10,7 +10,8 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricVLayoutNode : DoricGroupNode @interface DoricVLayoutNode : DoricGroupNode
@property (nonatomic) CGFloat space;
@property (nonatomic) DoricGravity gravity;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -8,5 +8,78 @@
#import "DoricVLayoutNode.h" #import "DoricVLayoutNode.h"
@implementation DoricVLayoutNode @implementation DoricVLayoutNode
- (instancetype)init {
if (self = [super init]) {
_space = 0;
_gravity = 0;
}
return self;
}
- (void)measureByParent:(DoricGroupNode *)parent {
DoricLayoutDesc widthSpec = self.layoutParams.width;
DoricLayoutDesc heightSpec = self.layoutParams.height;
CGFloat maxWidth = 0,maxHeight = 0;
for (DoricViewNode *child in self.indexedChildren) {
[child measureByParent:self];
UIView *childView = child.view;
CGFloat placeWidth = childView.width + child.layoutParams.margin.left + child.layoutParams.margin.right;
CGFloat placeHeight = childView.height + child.layoutParams.margin.top + child.layoutParams.margin.bottom;
maxWidth = MAX(maxWidth, placeWidth);
maxHeight += placeHeight + self.space;
}
maxHeight -= self.space;
self.desiredWidth = maxWidth;
self.desiredHeight = maxHeight;
if (widthSpec == LAYOUT_WRAP_CONTENT) {
self.view.width = maxWidth;
}
if (heightSpec == LAYOUT_WRAP_CONTENT) {
self.view.height = maxHeight;
}
}
- (void)layoutByParent:(DoricGroupNode *)parent {
if (self.layoutParams.width == LAYOUT_MATCH_PARENT) {
self.view.width = parent.view.width;
}
if (self.layoutParams.height == LAYOUT_MATCH_PARENT) {
self.view.height = parent.view.height;
}
CGFloat start = 0;
for (DoricViewNode *child in self.indexedChildren) {
[child measureByParent:self];
UIView *childView = child.view;
if (child.layoutParams.width == LAYOUT_MATCH_PARENT) {
childView.width = self.view.width;
}
if (child.layoutParams.height == LAYOUT_MATCH_PARENT) {
childView.height = self.view.height;
}
DoricGravity gravity = self.layoutParams.alignment;
if ((gravity & LEFT) == LEFT) {
childView.left = self.view.left;
}
if ((gravity & RIGHT) == RIGHT) {
childView.right = self.view.right;
}
if ((gravity & TOP) == TOP) {
childView.top = self.view.top;
}
if ((gravity & BOTTOM) == BOTTOM) {
childView.bottom = self.view.bottom;
}
if ((gravity & CENTER_X) == CENTER_X) {
childView.centerX = self.view.centerX;
}
if ((gravity & CENTER_Y) == CENTER_Y) {
childView.centerY = self.view.centerY;
}
childView.top = start;
start = childView.bottom + self.space;
}
}
@end @end

View File

@ -7,9 +7,6 @@
#import "UIView+Doric.h" #import "UIView+Doric.h"
#define LAYOUT_MATCH_PARENT -1
#define LAYOUT_WRAP_CONTENT -2
typedef NS_ENUM(NSInteger,DoricGravity) { typedef NS_ENUM(NSInteger,DoricGravity) {
SPECIFIED = 1, SPECIFIED = 1,
START = 1 << 1, START = 1 << 1,
@ -25,6 +22,12 @@ typedef NS_ENUM(NSInteger,DoricGravity) {
CENTER = CENTER_X | CENTER_Y, CENTER = CENTER_X | CENTER_Y,
}; };
typedef NS_ENUM(NSInteger,DoricLayoutDesc) {
LAYOUT_DEFAULT = 0,
LAYOUT_MATCH_PARENT = -1,
LAYOUT_WRAP_CONTENT = -2,
};
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricRect :NSObject @interface DoricRect :NSObject
@ -35,7 +38,10 @@ NS_ASSUME_NONNULL_BEGIN
@end @end
@interface LayoutParams : NSObject @interface LayoutParams : NSObject
@property (nonatomic) DoricLayoutDesc width;
@property (nonatomic) DoricLayoutDesc height;
@property (nonatomic) DoricGravity alignment; @property (nonatomic) DoricGravity alignment;
@property (nonatomic,strong) DoricRect *margin; @property (nonatomic,strong) DoricRect *margin;
@end @end

View File

@ -9,12 +9,24 @@
#import <objc/runtime.h> #import <objc/runtime.h>
@implementation DoricRect @implementation DoricRect
- (instancetype)init {
if (self = [super init]) {
_left = 0;
_right = 0;
_top = 0;
_bottom = 0;
}
return self;
}
@end @end
@implementation LayoutParams @implementation LayoutParams
- (instancetype)init { - (instancetype)init {
if (self = [super init]) { if (self = [super init]) {
_margin = [[DoricRect alloc] init]; _margin = [[DoricRect alloc] init];
_width = LAYOUT_DEFAULT;
_height = LAYOUT_DEFAULT;
_alignment = 0;
} }
return self; return self;
} }

View File

@ -26,6 +26,18 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic,strong,readonly) NSArray<NSString *> *idList; @property (nonatomic,strong,readonly) NSArray<NSString *> *idList;
@property (nonatomic) CGFloat x;
@property (nonatomic) CGFloat y;
@property (nonatomic) CGFloat width;
@property (nonatomic) CGFloat height;
@property (nonatomic) CGFloat centerX;
@property (nonatomic) CGFloat centerY;
@property (nonatomic) CGFloat top;
@property (nonatomic) CGFloat left;
@property (nonatomic) CGFloat right;
@property (nonatomic) CGFloat bottom;
- (V)build:(NSDictionary *)props; - (V)build:(NSDictionary *)props;
- (void)blend:(NSDictionary *)props; - (void)blend:(NSDictionary *)props;
@ -34,6 +46,10 @@ NS_ASSUME_NONNULL_BEGIN
- (void)callJSResponse:(NSString *)funcId,...; - (void)callJSResponse:(NSString *)funcId,...;
- (void)measureByParent:(DoricGroupNode *)parent;
- (void)layoutByParent:(DoricGroupNode *)parent;
+ (DoricViewNode *)create:(DoricContext *)context withType:(NSString *)type; + (DoricViewNode *)create:(DoricContext *)context withType:(NSString *)type;
@end @end

View File

@ -29,9 +29,19 @@ - (void)blend:(NSDictionary *)props {
- (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop { - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop {
if([name isEqualToString:@"width"]) { if([name isEqualToString:@"width"]) {
view.width = [(NSNumber *)prop floatValue]; NSNumber *width = (NSNumber *)prop;
if ([width integerValue] < 0) {
self.layoutParams.width = [width integerValue];
} else {
view.width = [width floatValue];
}
} else if([name isEqualToString:@"height"]) { } else if([name isEqualToString:@"height"]) {
view.height = [(NSNumber *)prop floatValue]; NSNumber *height = (NSNumber *)prop;
if ([height integerValue] < 0) {
self.layoutParams.height = [height integerValue];
} else {
view.height = [height floatValue];
}
} else if([name isEqualToString:@"x"]) { } else if([name isEqualToString:@"x"]) {
view.x = [(NSNumber *)prop floatValue]; view.x = [(NSNumber *)prop floatValue];
} else if([name isEqualToString:@"y"]) { } else if([name isEqualToString:@"y"]) {
@ -47,6 +57,14 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
} }
} }
- (void)measureByParent:(DoricGroupNode *)parent {
}
- (void)layoutByParent:(DoricGroupNode *)parent {
}
- (NSArray<NSString *> *)idList { - (NSArray<NSString *> *)idList {
NSMutableArray *ret = [[NSMutableArray alloc] init]; NSMutableArray *ret = [[NSMutableArray alloc] init];
DoricViewNode *node = self; DoricViewNode *node = self;
@ -78,4 +96,84 @@ + (DoricViewNode *)create:(DoricContext *)context withType:(NSString *)type {
return [[clz alloc] initWithContext:context]; return [[clz alloc] initWithContext:context];
} }
- (CGFloat)x {
return ((UIView *)self.view).x;
}
- (CGFloat)y {
return ((UIView *)self.view).y;
}
- (CGFloat)width {
return ((UIView *)self.view).width;
}
- (CGFloat)height {
return ((UIView *)self.view).height;
}
- (CGFloat)top {
return ((UIView *)self.view).top;
}
- (CGFloat)bottom {
return ((UIView *)self.view).bottom;
}
- (CGFloat)left {
return ((UIView *)self.view).left;
}
- (CGFloat)right {
return ((UIView *)self.view).right;
}
- (CGFloat)centerX {
return ((UIView *)self.view).centerX;
}
- (CGFloat)centerY {
return ((UIView *)self.view).centerX;
}
- (void)setX:(CGFloat)x {
((UIView *)self.view).x = x;
}
- (void)setY:(CGFloat)y {
((UIView *)self.view).y = y;
}
- (void)setWidth:(CGFloat)width {
((UIView *)self.view).width = width;
}
- (void)setHeight:(CGFloat)height {
((UIView *)self.view).height = height;
}
- (void)setLeft:(CGFloat)left {
((UIView *)self.view).left = left;
}
- (void)setRight:(CGFloat)right {
((UIView *)self.view).right = right;
}
- (void)setTop:(CGFloat)top {
((UIView *)self.view).top = top;
}
- (void)setBottom:(CGFloat)bottom {
((UIView *)self.view).bottom = bottom;
}
- (void)setCenterX:(CGFloat)centerX {
((UIView *)self.view).centerX = centerX;
}
- (void)setCenterY:(CGFloat)centerY {
((UIView *)self.view).centerY = centerY;
}
@end @end

View File

@ -11,6 +11,8 @@ class CounterView extends ViewHolder {
counter = new Text counter = new Text
build(root: Group) { build(root: Group) {
const vlayout = new VLayout const vlayout = new VLayout
vlayout.width = 200
vlayout.height = 200
this.number.textSize = 40 this.number.textSize = 40
this.number.layoutConfig = { this.number.layoutConfig = {
alignment: new Gravity().center() alignment: new Gravity().center()
@ -25,7 +27,8 @@ class CounterView extends ViewHolder {
} }
vlayout.addChild(this.number) vlayout.addChild(this.number)
vlayout.addChild(this.counter) vlayout.addChild(this.counter)
root.bgColor = Color.parse('#00ff00')
vlayout.bgColor = Color.parse('#ff00ff')
root.addChild(vlayout) root.addChild(vlayout)
} }
@ -48,6 +51,7 @@ class CounterVM extends ViewModel<CountModel, CounterView> {
} }
} }
@Entry
class MyPage extends VMPanel<CountModel, CounterView>{ class MyPage extends VMPanel<CountModel, CounterView>{
getVMClass() { getVMClass() {
@ -371,7 +375,6 @@ class SnakeVM extends ViewModel<SnakeModel, SnakeView>{
} }
} }
} }
@Entry
class SnakePanel extends VMPanel<SnakeModel, SnakeView>{ class SnakePanel extends VMPanel<SnakeModel, SnakeView>{
getVMClass() { getVMClass() {