diff --git a/Android/app/src/main/AndroidManifest.xml b/Android/app/src/main/AndroidManifest.xml
index e5194a3b..36ce1127 100644
--- a/Android/app/src/main/AndroidManifest.xml
+++ b/Android/app/src/main/AndroidManifest.xml
@@ -19,7 +19,9 @@
-
+
diff --git a/Android/app/src/main/java/pub/doric/demo/DemoActivity.java b/Android/app/src/main/java/pub/doric/demo/DemoActivity.java
index 7110f3f9..8aa99201 100644
--- a/Android/app/src/main/java/pub/doric/demo/DemoActivity.java
+++ b/Android/app/src/main/java/pub/doric/demo/DemoActivity.java
@@ -18,6 +18,7 @@ package pub.doric.demo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.ViewGroup;
+import android.view.Window;
import android.widget.FrameLayout;
import androidx.annotation.Nullable;
diff --git a/iOS/Example/Example.xcodeproj/project.pbxproj b/iOS/Example/Example.xcodeproj/project.pbxproj
index b7439e60..2b1ea696 100644
--- a/iOS/Example/Example.xcodeproj/project.pbxproj
+++ b/iOS/Example/Example.xcodeproj/project.pbxproj
@@ -9,9 +9,8 @@
/* Begin PBXBuildFile section */
AAAF5D5802FC6E7E4F481F5D /* libPods-ExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 942158E9B500A4C975FD37F3 /* libPods-ExampleTests.a */; };
B1AF6AE00A9B4675290F5947 /* libPods-ExampleUITests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 64B9242B26FEC4AEC20FF43D /* libPods-ExampleUITests.a */; };
+ D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */ = {isa = PBXBuildFile; fileRef = D751D19E97EF4EDD7588FEBE /* DemoVC.m */; };
D9E087DE6FF1DB083B30D9E7 /* libPods-Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C043B7BA79339ABA1CF46881 /* libPods-Example.a */; };
- E21DC9D42302870000660C5C /* Snake.js in Resources */ = {isa = PBXBuildFile; fileRef = E21DC9D22302865E00660C5C /* Snake.js */; };
- E21DC9D52302870000660C5C /* Counter.js in Resources */ = {isa = PBXBuildFile; fileRef = E21DC9D32302865E00660C5C /* Counter.js */; };
E2334AF022E9D2060098A085 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E2334AEF22E9D2060098A085 /* AppDelegate.m */; };
E2334AF322E9D2060098A085 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E2334AF222E9D2060098A085 /* ViewController.m */; };
E2334AF622E9D2060098A085 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E2334AF422E9D2060098A085 /* Main.storyboard */; };
@@ -20,8 +19,7 @@
E2334AFE22E9D2070098A085 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E2334AFD22E9D2070098A085 /* main.m */; };
E2334B0822E9D2070098A085 /* ExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E2334B0722E9D2070098A085 /* ExampleTests.m */; };
E2334B1322E9D2070098A085 /* ExampleUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = E2334B1222E9D2070098A085 /* ExampleUITests.m */; };
- E2BF7BF7237E8E9F001B0EDC /* ListDemo.js in Resources */ = {isa = PBXBuildFile; fileRef = E2BF7BF6237E8E9F001B0EDC /* ListDemo.js */; };
- E2F447F42383924B00073C7F /* ScrollerDemo.js in Resources */ = {isa = PBXBuildFile; fileRef = E2F447F32383924B00073C7F /* ScrollerDemo.js */; };
+ E2F4481723839AC500073C7F /* demo in Resources */ = {isa = PBXBuildFile; fileRef = E2F4481623839AC500073C7F /* demo */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -51,8 +49,8 @@
942158E9B500A4C975FD37F3 /* libPods-ExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
A5AE090AE3815360EC768C8D /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-Example/Pods-Example.release.xcconfig"; sourceTree = ""; };
C043B7BA79339ABA1CF46881 /* libPods-Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Example.a"; sourceTree = BUILT_PRODUCTS_DIR; };
- E21DC9D22302865E00660C5C /* Snake.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = Snake.js; sourceTree = ""; };
- E21DC9D32302865E00660C5C /* Counter.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = Counter.js; sourceTree = ""; };
+ D751D19E97EF4EDD7588FEBE /* DemoVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoVC.m; sourceTree = ""; };
+ D751DDEC114E037231257E64 /* DemoVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoVC.h; sourceTree = ""; };
E2334AEB22E9D2060098A085 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
E2334AEE22E9D2060098A085 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
E2334AEF22E9D2060098A085 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
@@ -69,8 +67,7 @@
E2334B0E22E9D2070098A085 /* ExampleUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ExampleUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
E2334B1222E9D2070098A085 /* ExampleUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ExampleUITests.m; sourceTree = ""; };
E2334B1422E9D2070098A085 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
- E2BF7BF6237E8E9F001B0EDC /* ListDemo.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = ListDemo.js; sourceTree = ""; };
- E2F447F32383924B00073C7F /* ScrollerDemo.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = ScrollerDemo.js; sourceTree = ""; };
+ E2F4481623839AC500073C7F /* demo */ = {isa = PBXFileReference; lastKnownFileType = folder; path = demo; sourceTree = ""; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -124,22 +121,9 @@
name = Frameworks;
sourceTree = "";
};
- E21DC9D12302865E00660C5C /* src */ = {
- isa = PBXGroup;
- children = (
- E2F447F32383924B00073C7F /* ScrollerDemo.js */,
- E2BF7BF6237E8E9F001B0EDC /* ListDemo.js */,
- E21DC9D22302865E00660C5C /* Snake.js */,
- E21DC9D32302865E00660C5C /* Counter.js */,
- );
- name = src;
- path = ../../demo/bundle/src;
- sourceTree = "";
- };
E2334AE222E9D2060098A085 = {
isa = PBXGroup;
children = (
- E21DC9D12302865E00660C5C /* src */,
E2334AED22E9D2060098A085 /* Example */,
E2334B0622E9D2070098A085 /* ExampleTests */,
E2334B1122E9D2070098A085 /* ExampleUITests */,
@@ -162,6 +146,7 @@
E2334AED22E9D2060098A085 /* Example */ = {
isa = PBXGroup;
children = (
+ E2F4481623839AC500073C7F /* demo */,
E2334AEE22E9D2060098A085 /* AppDelegate.h */,
E2334AEF22E9D2060098A085 /* AppDelegate.m */,
E2334AF122E9D2060098A085 /* ViewController.h */,
@@ -171,6 +156,8 @@
E2334AF922E9D2070098A085 /* LaunchScreen.storyboard */,
E2334AFC22E9D2070098A085 /* Info.plist */,
E2334AFD22E9D2070098A085 /* main.m */,
+ D751D19E97EF4EDD7588FEBE /* DemoVC.m */,
+ D751DDEC114E037231257E64 /* DemoVC.h */,
);
path = Example;
sourceTree = "";
@@ -301,11 +288,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- E2F447F42383924B00073C7F /* ScrollerDemo.js in Resources */,
- E2BF7BF7237E8E9F001B0EDC /* ListDemo.js in Resources */,
- E21DC9D42302870000660C5C /* Snake.js in Resources */,
- E21DC9D52302870000660C5C /* Counter.js in Resources */,
E2334AFB22E9D2070098A085 /* LaunchScreen.storyboard in Resources */,
+ E2F4481723839AC500073C7F /* demo in Resources */,
E2334AF822E9D2070098A085 /* Assets.xcassets in Resources */,
E2334AF622E9D2060098A085 /* Main.storyboard in Resources */,
);
@@ -439,6 +423,7 @@
E2334AF322E9D2060098A085 /* ViewController.m in Sources */,
E2334AFE22E9D2070098A085 /* main.m in Sources */,
E2334AF022E9D2060098A085 /* AppDelegate.m in Sources */,
+ D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/iOS/Example/Example/AppDelegate.m b/iOS/Example/Example/AppDelegate.m
index 9314c36c..28002f7c 100644
--- a/iOS/Example/Example/AppDelegate.m
+++ b/iOS/Example/Example/AppDelegate.m
@@ -7,9 +7,11 @@
//
#import "AppDelegate.h"
+#import "ViewController.h"
@interface AppDelegate ()
-
+@property(nonatomic, strong) UIViewController *rootVC;
+@property(nonatomic, strong) UINavigationController *navigationController;
@end
@implementation AppDelegate
@@ -17,6 +19,14 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ self.rootVC = [[ViewController alloc] init];
+
+ self.window.rootViewController = self.rootVC;
+ self.navigationController = [[UINavigationController
+ alloc] initWithRootViewController:self.rootVC];
+ [self.window addSubview:self.navigationController.view];
+ [self.window makeKeyAndVisible];
return YES;
}
diff --git a/iOS/Example/Example/DemoVC.h b/iOS/Example/Example/DemoVC.h
new file mode 100644
index 00000000..ea808936
--- /dev/null
+++ b/iOS/Example/Example/DemoVC.h
@@ -0,0 +1,12 @@
+//
+// Created by pengfei.zhou on 2019/11/19.
+// Copyright (c) 2019 pengfei.zhou. All rights reserved.
+//
+
+#import
+#import
+
+
+@interface DemoVC : UIViewController
+- (instancetype)initWithPath:(NSString *)filePath;
+@end
\ No newline at end of file
diff --git a/iOS/Example/Example/DemoVC.m b/iOS/Example/Example/DemoVC.m
new file mode 100644
index 00000000..62f687f6
--- /dev/null
+++ b/iOS/Example/Example/DemoVC.m
@@ -0,0 +1,45 @@
+//
+// Created by pengfei.zhou on 2019/11/19.
+// Copyright (c) 2019 pengfei.zhou. All rights reserved.
+//
+
+#import "DemoVC.h"
+#import "DoricContext.h"
+#import "DoricLayouts.h"
+#import "DoricExtensions.h"
+#import "DoricRootNode.h"
+#import "DoricLocalServer.h"
+
+@interface DemoVC ()
+@property(nonatomic, copy) NSString *filePath;
+@property(nonatomic, strong) DoricContext *doricContext;
+//@property(nonatomic, strong) DoricLocalServer *localServer;
+@end
+
+@implementation DemoVC
+- (instancetype)initWithPath:(NSString *)filePath {
+ if (self = [self init]) {
+ _filePath = filePath;
+ }
+ return self;
+}
+
+- (void)viewDidLoad {
+ NSString *jsContent = [NSString stringWithContentsOfFile:self.filePath encoding:NSUTF8StringEncoding error:nil];
+ self.doricContext = [[DoricContext alloc] initWithScript:jsContent source:self.filePath];
+ [self.doricContext.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) {
+ it.backgroundColor = [UIColor whiteColor];
+ it.layoutConfig = [[DoricLayoutConfig alloc]
+ initWithWidth:DoricLayoutAtMost
+ height:DoricLayoutAtMost
+ margin:DoricMarginMake(0, 88, 0, 0)
+ ];
+ [self.view addSubview:it];
+ }]];
+ [self.doricContext initContextWithWidth:self.view.width height:self.view.height];
+// [self.doricContext.driver connectDevKit:@"ws://192.168.11.38:7777"];
+// self.localServer = [[DoricLocalServer alloc] init];
+// [self.localServer startWithPort:8910];
+}
+
+@end
\ No newline at end of file
diff --git a/iOS/Example/Example/ViewController.m b/iOS/Example/Example/ViewController.m
index 25917f3a..7e0d5185 100644
--- a/iOS/Example/Example/ViewController.m
+++ b/iOS/Example/Example/ViewController.m
@@ -7,38 +7,53 @@
//
#import "ViewController.h"
-#import "UIView+Doric.h"
-#import "DoricUtil.h"
-#import "DoricContext.h"
-#import "DoricNativePlugin.h"
-#import "DoricRootNode.h"
-#import "DoricLocalServer.h"
-#import "DoricLayouts.h"
-#import "DoricExtensions.h"
+#import "Doric.h"
+#import "DemoVC.h"
-@interface ViewController ()
-@property(nonatomic, strong) DoricContext *doricContext;
-@property(nonatomic, strong) DoricLocalServer *localServer;
+@interface ViewController ()
+@property(nonatomic, copy) NSArray *demoFilePaths;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
-
- NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"ScrollerDemo" ofType:@"js"];
- NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
- self.doricContext = [[DoricContext alloc] initWithScript:jsContent source:@"test.js"];
- [self.doricContext.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) {
- it.layoutConfig = [[DoricLayoutConfig alloc] initWithWidth:DoricLayoutAtMost height:DoricLayoutAtMost];
- [self.view addSubview:it];
+ NSString *path = [[NSBundle mainBundle] bundlePath];
+ NSString *demoPath = [path stringByAppendingPathComponent:@"demo"];
+ NSFileManager *mgr = [NSFileManager defaultManager];
+ self.demoFilePaths = [[mgr subpathsAtPath:demoPath] filter:^BOOL(NSString *obj) {
+ return ![obj containsString:@".map"];
+ }];
+ [self.view addSubview:[[UITableView new] also:^(UITableView *it) {
+ it.width = self.view.width;
+ it.height = self.view.height;
+ it.left = it.top = 0;
+ it.dataSource = self;
+ it.delegate = self;
}]];
- [self.doricContext initContextWithWidth:self.view.width height:self.view.height];
- [self.doricContext.driver connectDevKit:@"ws://192.168.11.38:7777"];
- self.localServer = [[DoricLocalServer alloc] init];
- [self.localServer startWithPort:8910];
- NSLog(@"00112233");
}
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ return self.demoFilePaths.count;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ NSString *path = self.demoFilePaths[(NSUInteger) indexPath.row];
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
+ if (cell == nil) {
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"];
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
+ }
+ cell.textLabel.text = path;
+ return cell;
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+ NSString *path = [[NSBundle mainBundle] bundlePath];
+ NSString *demoPath = [path stringByAppendingPathComponent:@"demo"];
+ NSString *fullPath = [demoPath stringByAppendingPathComponent:self.demoFilePaths[(NSUInteger) indexPath.row]];
+ DemoVC *demoVC = [[DemoVC alloc] initWithPath:fullPath];
+ [self.navigationController pushViewController:demoVC animated:NO];
+}
@end
diff --git a/iOS/Example/Example/demo b/iOS/Example/Example/demo
new file mode 120000
index 00000000..7506393d
--- /dev/null
+++ b/iOS/Example/Example/demo
@@ -0,0 +1 @@
+../../../demo/bundle/src/
\ No newline at end of file
diff --git a/iOS/Pod/Classes/Doric.h b/iOS/Pod/Classes/Doric.h
new file mode 100644
index 00000000..9a2236dc
--- /dev/null
+++ b/iOS/Pod/Classes/Doric.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright [2019] [Doric.Pub]
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#import "DoricContext.h"
+#import "DoricLayouts.h"
+#import "DoricExtensions.h"
+#import "DoricViewNode.h"
+#import "DoricRootNode.h"
+#import "UIView+Doric.h"
diff --git a/iOS/Pod/Classes/Util/DoricExtensions.h b/iOS/Pod/Classes/Util/DoricExtensions.h
index aba09103..aad626fd 100644
--- a/iOS/Pod/Classes/Util/DoricExtensions.h
+++ b/iOS/Pod/Classes/Util/DoricExtensions.h
@@ -27,3 +27,21 @@
- (void)let:(void (^)(id it))block;
@end
+
+@interface NSArray (Doric)
+- (void)forEachIndexed:(void (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx))block;
+
+- (NSArray *)mapIndexed:(id (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx))block;
+
+- (NSArray *)flatMapIndexed:(NSArray *(NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx))block;
+
+- (NSArray *)filterIndexed:(BOOL (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx))block;
+
+- (void)forEach:(void (NS_NOESCAPE ^)(ObjectType obj))block;
+
+- (NSArray *)map:(id (NS_NOESCAPE ^)(ObjectType obj))block;
+
+- (NSArray *)flatMap:(NSArray *(NS_NOESCAPE ^)(ObjectType obj))block;
+
+- (NSArray *)filter:(BOOL (NS_NOESCAPE ^)(ObjectType obj))block;
+@end
\ No newline at end of file
diff --git a/iOS/Pod/Classes/Util/DoricExtensions.m b/iOS/Pod/Classes/Util/DoricExtensions.m
index b3b92987..e0f44c47 100644
--- a/iOS/Pod/Classes/Util/DoricExtensions.m
+++ b/iOS/Pod/Classes/Util/DoricExtensions.m
@@ -33,3 +33,70 @@ - (void)let:(void (^)(id it))block {
block(self);
}
@end
+
+@implementation NSArray (Doric)
+- (void)forEachIndexed:(void (NS_NOESCAPE ^)(id obj, NSUInteger idx))block {
+ [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+ block(obj, idx);
+ }];
+}
+
+- (NSArray *)mapIndexed:(id (NS_NOESCAPE ^)(id obj, NSUInteger idx))block {
+ NSMutableArray *temp = [NSMutableArray new];
+ [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+ [temp addObject:block(obj, idx)];
+ }];
+ return [temp copy];
+}
+
+- (NSArray *)flatMapIndexed:(NSArray *(NS_NOESCAPE ^)(id obj, NSUInteger idx))block {
+ NSMutableArray *temp = [NSMutableArray new];
+ [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+ [temp addObjectsFromArray:block(obj, idx)];
+ }];
+ return [temp copy];
+}
+
+- (NSArray *)filterIndexed:(BOOL (NS_NOESCAPE ^)(id obj, NSUInteger idx))block {
+ NSMutableArray *temp = [NSMutableArray new];
+ [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+ if (block(obj, idx)) {
+ [temp addObject:obj];
+ }
+ }];
+ return [temp copy];
+}
+
+- (void)forEach:(void (NS_NOESCAPE ^)(id obj))block {
+ for (id obj in self) {
+ block(obj);
+ }
+}
+
+- (NSArray *)map:(id (NS_NOESCAPE ^)(id obj))block {
+ NSMutableArray *temp = [NSMutableArray new];
+ for (id obj in self) {
+ [temp addObject:block(obj)];
+ }
+ return [temp copy];
+}
+
+- (NSArray *)flatMap:(NSArray *(NS_NOESCAPE ^)(id obj))block {
+ NSMutableArray *temp = [NSMutableArray new];
+ for (id obj in self) {
+ [temp addObjectsFromArray:block(obj)];
+ }
+ return [temp copy];
+}
+
+- (NSArray *)filter:(BOOL (NS_NOESCAPE ^)(id obj))block {
+ NSMutableArray *temp = [NSMutableArray new];
+ for (id obj in self) {
+ if (block(obj)) {
+ [temp addObject:obj];
+ }
+ }
+ return [temp copy];
+}
+
+@end