From 674335324bec016a46a6b3dba84f37a0e8dfce48 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Wed, 31 Jul 2019 14:18:20 +0800 Subject: [PATCH] iOS render --- .../penfeizhou/doric/shader/GroupNode.java | 1 + iOS/Example/Example/ViewController.m | 2 + .../Pods/Pods.xcodeproj/project.pbxproj | 26 +++-- iOS/Pod/Classes/DoricContext.h | 3 + iOS/Pod/Classes/DoricContext.m | 2 + iOS/Pod/Classes/DoricRegistry.m | 3 + iOS/Pod/Classes/Plugin/DoricShaderPlugin.m | 7 +- iOS/Pod/Classes/Shader/DoricGroupNode.h | 4 + iOS/Pod/Classes/Shader/DoricGroupNode.m | 29 ++--- iOS/Pod/Classes/Shader/DoricHLayoutNode.h | 3 +- iOS/Pod/Classes/Shader/DoricHLayoutNode.m | 34 ++++++ iOS/Pod/Classes/Shader/DoricRootNode.h | 3 + iOS/Pod/Classes/Shader/DoricRootNode.m | 13 +++ iOS/Pod/Classes/Shader/DoricStackNode.h | 2 +- iOS/Pod/Classes/Shader/DoricStackNode.m | 63 +++++++++++ iOS/Pod/Classes/Shader/DoricTextNode.h | 16 +++ iOS/Pod/Classes/Shader/DoricTextNode.m | 50 +++++++++ iOS/Pod/Classes/Shader/DoricVLayoutNode.h | 3 +- iOS/Pod/Classes/Shader/DoricVLayoutNode.m | 73 +++++++++++++ iOS/Pod/Classes/Shader/DoricViewContainer.h | 12 ++- iOS/Pod/Classes/Shader/DoricViewContainer.m | 12 +++ iOS/Pod/Classes/Shader/DoricViewNode.h | 16 +++ iOS/Pod/Classes/Shader/DoricViewNode.m | 102 +++++++++++++++++- js-framework/demo.ts | 7 +- 24 files changed, 452 insertions(+), 34 deletions(-) create mode 100644 iOS/Pod/Classes/Shader/DoricTextNode.h create mode 100644 iOS/Pod/Classes/Shader/DoricTextNode.m diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java index 061d5811..2fdef5a3 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java @@ -68,6 +68,7 @@ public abstract class GroupNode extends ViewNode { mChildrenNode.remove(mIndexInfo.get(i).getId()); mIndexInfo.remove(i); } + i++; } break; default: diff --git a/iOS/Example/Example/ViewController.m b/iOS/Example/Example/ViewController.m index 5e7f1ab4..b1251638 100644 --- a/iOS/Example/Example/ViewController.m +++ b/iOS/Example/Example/ViewController.m @@ -11,6 +11,7 @@ #import "DoricUtil.h" #import "DoricContext.h" #import "DoricNativePlugin.h" +#import "DoricRootNode.h" @interface ViewController () @property (nonatomic,strong) DoricContext *doricContext; @@ -33,6 +34,7 @@ - (void)viewDidLoad { NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"demo" ofType:@"js"]; NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; self.doricContext = [[DoricContext alloc] initWithScript:jsContent source:@"demo"]; + self.doricContext.rootNode.view = self.view; [self.doricContext callEntity:@"__init__",@{@"width": [NSNumber numberWithFloat:self.view.width], @"height":[NSNumber numberWithFloat:self.view.height]},nil]; } diff --git a/iOS/Example/Pods/Pods.xcodeproj/project.pbxproj b/iOS/Example/Pods/Pods.xcodeproj/project.pbxproj index 11b3f644..764315a1 100644 --- a/iOS/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/iOS/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -55,6 +55,8 @@ 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 */; }; 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, ); }; }; 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 */; }; @@ -88,16 +90,16 @@ 0A5A03FDB5D69AFA8105CD95F537E7B4 /* DoricVLayoutNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricVLayoutNode.h; sourceTree = ""; }; 11F84157E3FED749ED2F53440014CF74 /* DoricContext.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricContext.m; path = Pod/Classes/DoricContext.m; sourceTree = ""; }; 12E65E9A959F203D44594250808719D0 /* DoricStackNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricStackNode.h; sourceTree = ""; }; - 165E0A231E9DDF8E3C3B339C5F991D2B /* Doric.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; lastKnownFileType = text; path = Doric.podspec; sourceTree = ""; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + 165E0A231E9DDF8E3C3B339C5F991D2B /* Doric.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; path = Doric.podspec; sourceTree = ""; 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 = ""; }; 1E9FEEA40A1420C03A9FA2DF019E8394 /* DoricAsyncResult.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricAsyncResult.h; sourceTree = ""; }; 1EA815FA2776C872BADBFAE526312474 /* DoricGroupNode.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricGroupNode.m; sourceTree = ""; }; - 1F667CC0E19EAF34E5A4119E2121F585 /* libPods-Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libPods-Example.a"; 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 = ""; }; + 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; lastKnownFileType = sourcecode.javascript; name = "doric-sandbox.js"; path = "../js-framework/bundle/doric-sandbox.js"; sourceTree = ""; }; 21C8D570F3695E2C55CF1650F47FDB8E /* DoricPromise.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricPromise.h; sourceTree = ""; }; 28C3F6DCBC4FB144EEE0564B6299B0CB /* DoricJSExecutorProtocal.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricJSExecutorProtocal.h; sourceTree = ""; }; 2A58BA4FA12990F611D58B20153AF80B /* DoricRootNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricRootNode.h; sourceTree = ""; }; - 2EC07F016FD484CA2F44DB97705AAFE7 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; path = LICENSE; sourceTree = ""; }; + 2EC07F016FD484CA2F44DB97705AAFE7 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; 34B71CB0B4480EA08DD35197F06DBF38 /* DoricJSEngine.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricJSEngine.m; sourceTree = ""; }; 34CB220633FAF5FB582354227A7889CC /* DoricShaderPlugin.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricShaderPlugin.m; sourceTree = ""; }; 35D3ADD1FF0C9A33D86DB110C181048B /* Pods-ExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-ExampleTests.debug.xcconfig"; sourceTree = ""; }; @@ -115,7 +117,7 @@ 4F4F7A3F234E0CFD4CD49EFC295447B7 /* DoricNativePlugin.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricNativePlugin.h; sourceTree = ""; }; 50CE420621B9D9ED01E06A8EDBD3E990 /* Pods-ExampleUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-ExampleUITests.release.xcconfig"; sourceTree = ""; }; 57728CFE03A4D88821681C3D55A1FA85 /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Example.release.xcconfig"; sourceTree = ""; }; - 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 = ""; }; 672ED840695CA6755DECF6030784FB37 /* DoricBridgeExtension.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricBridgeExtension.m; sourceTree = ""; }; 673C99F302C0D91311C4BEAB6C3F5DD2 /* DoricJSCoreExecutor.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricJSCoreExecutor.m; sourceTree = ""; }; @@ -133,7 +135,7 @@ 912DD5AC9B73450AB46CAC837632066E /* DoricDriver.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricDriver.h; path = Pod/Classes/DoricDriver.h; sourceTree = ""; }; 9145FEC14942C0A3829F08841A321931 /* DoricHLayoutNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricHLayoutNode.h; sourceTree = ""; }; 9CF6301AAD07F98FE89F30E7B5A07161 /* Pods-ExampleTests-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-ExampleTests-acknowledgements.plist"; sourceTree = ""; }; - 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 = ""; }; A12EA2D6D6F629978F16C0E458152B6E /* Pods-ExampleTests-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-ExampleTests-acknowledgements.markdown"; sourceTree = ""; }; A5C03B5A2EF5BC47137E15CB4EBFE525 /* DoricContextHolder.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricContextHolder.h; path = Pod/Classes/DoricContextHolder.h; sourceTree = ""; }; @@ -141,15 +143,17 @@ A7BBF360102FA3B4372193E445788A75 /* DoricConstant.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricConstant.m; sourceTree = ""; }; AAC90DCBF1BFE57FD63FA71236CD9617 /* DoricUtil.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricUtil.h; sourceTree = ""; }; AEAB7D461045D326881C99D36EB09F06 /* DoricContextManager.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricContextManager.m; path = Pod/Classes/DoricContextManager.m; sourceTree = ""; }; - 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 = ""; }; C6D6AA5E2B4BA8E824A10E9272A0C408 /* DoricNativePlugin.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = DoricNativePlugin.m; sourceTree = ""; }; C78507DD6E36D475B8675ACBB6CB29BB /* DoricRegistry.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricRegistry.m; path = Pod/Classes/DoricRegistry.m; sourceTree = ""; }; - CB6504BD07E3990E6F058E4073421ADA /* libDoric.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libDoric.a; 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 = ""; }; + 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; lastKnownFileType = sourcecode.javascript; name = "doric-lib.js"; path = "../js-framework/bundle/doric-lib.js"; sourceTree = ""; }; D94AF2C3306CFE8E84FE37B99B27675B /* DoricModalPlugin.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricModalPlugin.h; sourceTree = ""; }; DC9CA9CA257999E08AC1FF1683E7A4D0 /* DoricViewNode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricViewNode.h; sourceTree = ""; }; DFFAD17E7567EE856A59F246D50A9B0B /* Pods-Example-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-Example-acknowledgements.plist"; sourceTree = ""; }; + E2FC3FE422F13018007A4E57 /* DoricTextNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoricTextNode.h; sourceTree = ""; }; + E2FC3FE522F13018007A4E57 /* DoricTextNode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DoricTextNode.m; sourceTree = ""; }; E340F908A05867E06E975FDCDD32315C /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Example.debug.xcconfig"; sourceTree = ""; }; E6260EBC3191F783549F257021CB739F /* DoricBridgeExtension.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricBridgeExtension.h; sourceTree = ""; }; E7932F4E2884A330FF1506551365C865 /* DoricShaderPlugin.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = DoricShaderPlugin.h; sourceTree = ""; }; @@ -280,6 +284,8 @@ 460F14FF387A5DD08430DA1FD75E10EE /* DoricViewNode.m */, 0A5A03FDB5D69AFA8105CD95F537E7B4 /* DoricVLayoutNode.h */, 49D245CB8651BC5097588071D90D8EA5 /* DoricVLayoutNode.m */, + E2FC3FE422F13018007A4E57 /* DoricTextNode.h */, + E2FC3FE522F13018007A4E57 /* DoricTextNode.m */, ); name = Shader; path = Pod/Classes/Shader; @@ -448,6 +454,7 @@ DAEFBC72D2314E794132D06E15025AC3 /* DoricStackNode.h in Headers */, 13A302CDD2B011A4DF5CF1112E09E937 /* DoricUtil.h in Headers */, 0A85A5F9A3EE11F072A89DE84A6FA0B8 /* DoricViewContainer.h in Headers */, + E2FC3FE622F13018007A4E57 /* DoricTextNode.h in Headers */, CDB42B526F58B185A238F2F725094FA3 /* DoricViewNode.h in Headers */, A2A8E68788BDBA92162E3958CC947636 /* DoricVLayoutNode.h in Headers */, DFB2B8E114B1081B0B285F7EF712C3FC /* UIView+Doric.h in Headers */, @@ -616,6 +623,7 @@ 81D52405D6E15FB19C6ADE196CEBFED4 /* DoricNativePlugin.m in Sources */, 9819AF9920746EF21542E98566455571 /* DoricPromise.m in Sources */, 159F44077D988BE31CFAA0FABB4B97F5 /* DoricRegistry.m in Sources */, + E2FC3FE722F13018007A4E57 /* DoricTextNode.m in Sources */, 1E3AEF0D767322EEB63622B26806ACEE /* DoricRootNode.m in Sources */, DBC2D2D72A7B27EECC1FEA4218B74028 /* DoricShaderPlugin.m in Sources */, 0F15CD85BB2DB16EAADAD04B6FCE5A86 /* DoricStackNode.m in Sources */, diff --git a/iOS/Pod/Classes/DoricContext.h b/iOS/Pod/Classes/DoricContext.h index c4f4e61d..9bdb10ba 100644 --- a/iOS/Pod/Classes/DoricContext.h +++ b/iOS/Pod/Classes/DoricContext.h @@ -10,11 +10,14 @@ NS_ASSUME_NONNULL_BEGIN +@class DoricRootNode; + @interface DoricContext : NSObject @property (nonatomic,strong) NSString *contextId; @property (nonatomic,strong) DoricDriver *driver; @property (nonatomic,strong) NSMutableDictionary *pluginInstanceMap; +@property (nonatomic,strong) DoricRootNode *rootNode; - (instancetype)initWithScript:(NSString *)script source:(NSString *)source; diff --git a/iOS/Pod/Classes/DoricContext.m b/iOS/Pod/Classes/DoricContext.m index e1fdbe33..395867c8 100644 --- a/iOS/Pod/Classes/DoricContext.m +++ b/iOS/Pod/Classes/DoricContext.m @@ -7,6 +7,7 @@ #import "DoricContext.h" #import "DoricContextManager.h" +#import "DoricRootNode.h" @implementation DoricContext @@ -15,6 +16,7 @@ - (instancetype)initWithScript:(NSString *)script source:(NSString *)source { _driver = [DoricDriver instance]; _pluginInstanceMap = [[NSMutableDictionary alloc] init]; [[DoricContextManager instance] createContext:self script:script source:source]; + _rootNode = [[DoricRootNode alloc] initWithContext:self]; } return self; } diff --git a/iOS/Pod/Classes/DoricRegistry.m b/iOS/Pod/Classes/DoricRegistry.m index e52805dc..8a20b06a 100644 --- a/iOS/Pod/Classes/DoricRegistry.m +++ b/iOS/Pod/Classes/DoricRegistry.m @@ -11,6 +11,7 @@ #import "DoricStackNode.h" #import "DoricVLayoutNode.h" #import "DoricHLayoutNode.h" +#import "DoricTextNode.h" @interface DoricRegistry () @@ -39,6 +40,8 @@ - (void)innerRegister { [self registerViewNode:DoricStackNode.class withName:@"Stack"]; [self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"]; [self registerViewNode:DoricHLayoutNode.class withName:@"HLayout"]; + [self registerViewNode:DoricTextNode.class withName:@"Text"]; + } - (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name { diff --git a/iOS/Pod/Classes/Plugin/DoricShaderPlugin.m b/iOS/Pod/Classes/Plugin/DoricShaderPlugin.m index e9dc92b9..a4c9a25d 100644 --- a/iOS/Pod/Classes/Plugin/DoricShaderPlugin.m +++ b/iOS/Pod/Classes/Plugin/DoricShaderPlugin.m @@ -6,11 +6,16 @@ // #import "DoricShaderPlugin.h" +#import "DoricRootNode.h" @implementation DoricShaderPlugin - (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 diff --git a/iOS/Pod/Classes/Shader/DoricGroupNode.h b/iOS/Pod/Classes/Shader/DoricGroupNode.h index e4277454..99e13dd0 100644 --- a/iOS/Pod/Classes/Shader/DoricGroupNode.h +++ b/iOS/Pod/Classes/Shader/DoricGroupNode.h @@ -12,6 +12,10 @@ NS_ASSUME_NONNULL_BEGIN @interface DoricGroupNode : DoricViewNode @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; diff --git a/iOS/Pod/Classes/Shader/DoricGroupNode.m b/iOS/Pod/Classes/Shader/DoricGroupNode.m index 35038bef..c3fc295f 100644 --- a/iOS/Pod/Classes/Shader/DoricGroupNode.m +++ b/iOS/Pod/Classes/Shader/DoricGroupNode.m @@ -7,16 +7,12 @@ #import "DoricGroupNode.h" -@interface DoricGroupNode () -@property (nonatomic,strong) NSMutableArray *indexInfo; -@end - @implementation DoricGroupNode - (instancetype)init { if(self = [super init]) { _children = [[NSMutableDictionary alloc] init]; - _indexInfo = [[NSMutableArray alloc] init]; + _indexedChildren = [[NSMutableArray alloc] init]; } return self; } @@ -52,18 +48,20 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop params = [self generateDefaultLayoutParams]; } [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.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]; - DoricViewNode *node = [self.indexInfo objectAtIndex:i]; + DoricViewNode *node = [self.indexedChildren objectAtIndex:i]; if (node != nil) { [self.children removeObjectForKey: node.viewId]; - [self.indexInfo removeObjectAtIndex:i]; + [self.indexedChildren removeObjectAtIndex:i]; } + i++; } } else { [super blendView:view forPropName:name propValue:prop]; @@ -78,9 +76,12 @@ - (LayoutParams *)generateDefaultLayoutParams { - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig { LayoutParams *params = child.layoutParams; NSDictionary *margin = [layoutconfig objectForKey:@"margin"]; - params.margin.top = [(NSNumber *)[margin objectForKey:@"top"] floatValue]; - params.margin.left = [(NSNumber *)[margin objectForKey:@"left"] floatValue]; - params.margin.right = [(NSNumber *)[margin objectForKey:@"right"] floatValue]; - params.margin.bottom = [(NSNumber *)[margin objectForKey:@"bottom"] floatValue]; + if (margin) { + params.margin.top = [(NSNumber *)[margin objectForKey:@"top"] floatValue]; + params.margin.left = [(NSNumber *)[margin objectForKey:@"left"] floatValue]; + params.margin.right = [(NSNumber *)[margin objectForKey:@"right"] floatValue]; + params.margin.bottom = [(NSNumber *)[margin objectForKey:@"bottom"] floatValue]; + } } + @end diff --git a/iOS/Pod/Classes/Shader/DoricHLayoutNode.h b/iOS/Pod/Classes/Shader/DoricHLayoutNode.h index acb4c143..569dec08 100644 --- a/iOS/Pod/Classes/Shader/DoricHLayoutNode.h +++ b/iOS/Pod/Classes/Shader/DoricHLayoutNode.h @@ -10,7 +10,8 @@ NS_ASSUME_NONNULL_BEGIN @interface DoricHLayoutNode : DoricGroupNode - +@property (nonatomic) CGFloat space; +@property (nonatomic) DoricGravity gravity; @end NS_ASSUME_NONNULL_END diff --git a/iOS/Pod/Classes/Shader/DoricHLayoutNode.m b/iOS/Pod/Classes/Shader/DoricHLayoutNode.m index 7af5871d..62befefd 100644 --- a/iOS/Pod/Classes/Shader/DoricHLayoutNode.m +++ b/iOS/Pod/Classes/Shader/DoricHLayoutNode.m @@ -8,5 +8,39 @@ #import "DoricHLayoutNode.h" @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 diff --git a/iOS/Pod/Classes/Shader/DoricRootNode.h b/iOS/Pod/Classes/Shader/DoricRootNode.h index a7c3f3dc..0380e884 100644 --- a/iOS/Pod/Classes/Shader/DoricRootNode.h +++ b/iOS/Pod/Classes/Shader/DoricRootNode.h @@ -11,6 +11,9 @@ NS_ASSUME_NONNULL_BEGIN @interface DoricRootNode : DoricStackNode +- (void)setupRootView:(UIView *)view; + +- (void)render:(NSDictionary *)props; @end NS_ASSUME_NONNULL_END diff --git a/iOS/Pod/Classes/Shader/DoricRootNode.m b/iOS/Pod/Classes/Shader/DoricRootNode.m index ab348f6c..fe9cb055 100644 --- a/iOS/Pod/Classes/Shader/DoricRootNode.m +++ b/iOS/Pod/Classes/Shader/DoricRootNode.m @@ -8,5 +8,18 @@ #import "DoricRootNode.h" @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 diff --git a/iOS/Pod/Classes/Shader/DoricStackNode.h b/iOS/Pod/Classes/Shader/DoricStackNode.h index 792d2762..098a94d0 100644 --- a/iOS/Pod/Classes/Shader/DoricStackNode.h +++ b/iOS/Pod/Classes/Shader/DoricStackNode.h @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN @interface DoricStackNode : DoricGroupNode - +@property (nonatomic) DoricGravity gravity; @end NS_ASSUME_NONNULL_END diff --git a/iOS/Pod/Classes/Shader/DoricStackNode.m b/iOS/Pod/Classes/Shader/DoricStackNode.m index 2f4d1581..6ab37bfa 100644 --- a/iOS/Pod/Classes/Shader/DoricStackNode.m +++ b/iOS/Pod/Classes/Shader/DoricStackNode.m @@ -9,4 +9,67 @@ @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 diff --git a/iOS/Pod/Classes/Shader/DoricTextNode.h b/iOS/Pod/Classes/Shader/DoricTextNode.h new file mode 100644 index 00000000..82a45276 --- /dev/null +++ b/iOS/Pod/Classes/Shader/DoricTextNode.h @@ -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 + +@end + +NS_ASSUME_NONNULL_END diff --git a/iOS/Pod/Classes/Shader/DoricTextNode.m b/iOS/Pod/Classes/Shader/DoricTextNode.m new file mode 100644 index 00000000..be8cac1d --- /dev/null +++ b/iOS/Pod/Classes/Shader/DoricTextNode.m @@ -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 diff --git a/iOS/Pod/Classes/Shader/DoricVLayoutNode.h b/iOS/Pod/Classes/Shader/DoricVLayoutNode.h index 01a6e5c2..c77e1eaa 100644 --- a/iOS/Pod/Classes/Shader/DoricVLayoutNode.h +++ b/iOS/Pod/Classes/Shader/DoricVLayoutNode.h @@ -10,7 +10,8 @@ NS_ASSUME_NONNULL_BEGIN @interface DoricVLayoutNode : DoricGroupNode - +@property (nonatomic) CGFloat space; +@property (nonatomic) DoricGravity gravity; @end NS_ASSUME_NONNULL_END diff --git a/iOS/Pod/Classes/Shader/DoricVLayoutNode.m b/iOS/Pod/Classes/Shader/DoricVLayoutNode.m index 3750833d..22ec2c93 100644 --- a/iOS/Pod/Classes/Shader/DoricVLayoutNode.m +++ b/iOS/Pod/Classes/Shader/DoricVLayoutNode.m @@ -8,5 +8,78 @@ #import "DoricVLayoutNode.h" @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 diff --git a/iOS/Pod/Classes/Shader/DoricViewContainer.h b/iOS/Pod/Classes/Shader/DoricViewContainer.h index 9f9d1b1a..a734b224 100644 --- a/iOS/Pod/Classes/Shader/DoricViewContainer.h +++ b/iOS/Pod/Classes/Shader/DoricViewContainer.h @@ -7,9 +7,6 @@ #import "UIView+Doric.h" -#define LAYOUT_MATCH_PARENT -1 -#define LAYOUT_WRAP_CONTENT -2 - typedef NS_ENUM(NSInteger,DoricGravity) { SPECIFIED = 1, START = 1 << 1, @@ -25,6 +22,12 @@ typedef NS_ENUM(NSInteger,DoricGravity) { 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 @interface DoricRect :NSObject @@ -35,7 +38,10 @@ NS_ASSUME_NONNULL_BEGIN @end + @interface LayoutParams : NSObject +@property (nonatomic) DoricLayoutDesc width; +@property (nonatomic) DoricLayoutDesc height; @property (nonatomic) DoricGravity alignment; @property (nonatomic,strong) DoricRect *margin; @end diff --git a/iOS/Pod/Classes/Shader/DoricViewContainer.m b/iOS/Pod/Classes/Shader/DoricViewContainer.m index a1556f78..6f67fda4 100644 --- a/iOS/Pod/Classes/Shader/DoricViewContainer.m +++ b/iOS/Pod/Classes/Shader/DoricViewContainer.m @@ -9,12 +9,24 @@ #import @implementation DoricRect +- (instancetype)init { + if (self = [super init]) { + _left = 0; + _right = 0; + _top = 0; + _bottom = 0; + } + return self; +} @end @implementation LayoutParams - (instancetype)init { if (self = [super init]) { _margin = [[DoricRect alloc] init]; + _width = LAYOUT_DEFAULT; + _height = LAYOUT_DEFAULT; + _alignment = 0; } return self; } diff --git a/iOS/Pod/Classes/Shader/DoricViewNode.h b/iOS/Pod/Classes/Shader/DoricViewNode.h index 5f557802..1f69ac63 100644 --- a/iOS/Pod/Classes/Shader/DoricViewNode.h +++ b/iOS/Pod/Classes/Shader/DoricViewNode.h @@ -26,6 +26,18 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic,strong,readonly) NSArray *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; - (void)blend:(NSDictionary *)props; @@ -34,6 +46,10 @@ NS_ASSUME_NONNULL_BEGIN - (void)callJSResponse:(NSString *)funcId,...; +- (void)measureByParent:(DoricGroupNode *)parent; + +- (void)layoutByParent:(DoricGroupNode *)parent; + + (DoricViewNode *)create:(DoricContext *)context withType:(NSString *)type; @end diff --git a/iOS/Pod/Classes/Shader/DoricViewNode.m b/iOS/Pod/Classes/Shader/DoricViewNode.m index fb04f9be..509f9f47 100644 --- a/iOS/Pod/Classes/Shader/DoricViewNode.m +++ b/iOS/Pod/Classes/Shader/DoricViewNode.m @@ -29,9 +29,19 @@ - (void)blend:(NSDictionary *)props { - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop { 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"]) { - 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"]) { view.x = [(NSNumber *)prop floatValue]; } 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 *)idList { NSMutableArray *ret = [[NSMutableArray alloc] init]; DoricViewNode *node = self; @@ -78,4 +96,84 @@ + (DoricViewNode *)create:(DoricContext *)context withType:(NSString *)type { 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 diff --git a/js-framework/demo.ts b/js-framework/demo.ts index 50d5add0..5ef14eeb 100644 --- a/js-framework/demo.ts +++ b/js-framework/demo.ts @@ -11,6 +11,8 @@ class CounterView extends ViewHolder { counter = new Text build(root: Group) { const vlayout = new VLayout + vlayout.width = 200 + vlayout.height = 200 this.number.textSize = 40 this.number.layoutConfig = { alignment: new Gravity().center() @@ -25,7 +27,8 @@ class CounterView extends ViewHolder { } vlayout.addChild(this.number) vlayout.addChild(this.counter) - + root.bgColor = Color.parse('#00ff00') + vlayout.bgColor = Color.parse('#ff00ff') root.addChild(vlayout) } @@ -48,6 +51,7 @@ class CounterVM extends ViewModel { } } +@Entry class MyPage extends VMPanel{ getVMClass() { @@ -371,7 +375,6 @@ class SnakeVM extends ViewModel{ } } } -@Entry class SnakePanel extends VMPanel{ getVMClass() {