소스 검색

navigation controllers

Daniel Zlotin 8 년 전
부모
커밋
c68be6575c

+ 15
- 3
ios/RNNControllerFactory.m 파일 보기

@@ -8,10 +8,22 @@
8 8
 
9 9
 +(UIViewController *)createRootViewController:(NSDictionary *)layout
10 10
 {
11
-    NSString* containerName = layout[@"container"][@"name"];
12
-    NSString* containerId = layout[@"container"][@"id"];
11
+    if ([layout[@"type"] isEqualToString:@"ContainerStack"]) {
12
+        UINavigationController* stack = [[UINavigationController alloc] init];
13
+        
14
+        NSString* containerName = [layout[@"children"] objectAtIndex:0][@"data"][@"name"];
15
+        NSString* containerId = [layout[@"children"] objectAtIndex:0][@"id"];
16
+        
17
+        [stack setViewControllers:@[[RNNControllerFactory create:containerName containerId:containerId]] animated:false];
18
+        
19
+        return stack;
20
+    }
13 21
     
14
-    return [RNNControllerFactory create:containerName containerId:containerId];
22
+//    NSString* containerName = layout[@"container"][@"name"];
23
+//    NSString* containerId = layout[@"container"][@"id"];
24
+    
25
+//    return [RNNControllerFactory create:containerName containerId:containerId];
26
+    return nil;
15 27
 }
16 28
 
17 29
 +(UIViewController*)create:(NSString*)containerName containerId:(NSString*)containerId

+ 1
- 1
scripts/test.android.js 파일 보기

@@ -1,7 +1,7 @@
1 1
 const exec = require('shell-utils').exec;
2 2
 
3 3
 function run() {
4
-  if (process.env.TRAVIS) {
4
+  if (process.env.CI) {
5 5
     exec.execSync(`./scripts/installAndroidSDK.sh`);
6 6
   }
7 7
   exec.execSync(`cd android && ./gradlew clean testDebugUnitTest`);

+ 2
- 2
src/commands/Commands.js 파일 보기

@@ -6,7 +6,7 @@ export default class Commands {
6 6
     this.layoutTreeParser = new LayoutTreeParser(uniqueIdProvider);
7 7
   }
8 8
 
9
-  startApp(params) {
10
-    this.nativeCommandsSender.startApp(this.layoutTreeParser.parse(params));
9
+  startApp(simpleApi) {
10
+    this.nativeCommandsSender.startApp(this.layoutTreeParser.parseSimpleApi(simpleApi));
11 11
   }
12 12
 }

+ 12
- 4
src/commands/Commands.test.js 파일 보기

@@ -21,10 +21,18 @@ describe('Commands', () => {
21 21
       });
22 22
       expect(mockCommandsSender.startApp).toHaveBeenCalledTimes(1);
23 23
       expect(mockCommandsSender.startApp).toHaveBeenCalledWith({
24
-        container: {
25
-          name: 'com.example.MyScreen',
26
-          id: 'containerUNIQUE_ID'
27
-        }
24
+        type: 'ContainerStack',
25
+        id: 'ContainerStackUNIQUE_ID',
26
+        children: [
27
+          {
28
+            type: 'Container',
29
+            id: 'ContainerUNIQUE_ID',
30
+            children: [],
31
+            data: {
32
+              name: 'com.example.MyScreen'
33
+            }
34
+          }
35
+        ]
28 36
       });
29 37
     });
30 38
   });

+ 39
- 16
src/commands/LayoutTreeParser.js 파일 보기

@@ -5,22 +5,45 @@ export default class LayoutTreeParser {
5 5
     this.uniqueIdProvider = uniqueIdProvider;
6 6
   }
7 7
 
8
-  parse(params) {
9
-    const layout = _.cloneDeep(params);
10
-    if (layout.container) {
11
-      layout.container.id = this.uniqueIdProvider.generate(`container`);
12
-    }
13
-    if (layout.sideMenu) {
14
-      if (layout.sideMenu.left) {
15
-        layout.sideMenu.left.id = this.uniqueIdProvider.generate(`container`);
16
-      }
17
-      if (layout.sideMenu.right) {
18
-        layout.sideMenu.right.id = this.uniqueIdProvider.generate(`container`);
19
-      }
20
-    }
21
-    if (layout.tabs) {
22
-      _.forEach(layout.tabs, (t) => t.container.id = this.uniqueIdProvider.generate(`container`));
23
-    }
8
+  parseSimpleApi(params) {
9
+    const layout = this.createContainerStackWithContainer(params.container);
10
+
11
+    //const layout = _.cloneDeep(params);
12
+    //if (layout.container) {
13
+    //  this.generateIdFor(layout.container);
14
+    //}
15
+    //if (layout.sideMenu) {
16
+    //  if (layout.sideMenu.left) {
17
+    //    this.generateIdFor(layout.sideMenu.left);
18
+    //  }
19
+    //  if (layout.sideMenu.right) {
20
+    //    this.generateIdFor(layout.sideMenu.right);
21
+    //  }
22
+    //}
23
+    //if (layout.tabs) {
24
+    //  _.forEach(layout.tabs, this.generateIdFor);
25
+    //}
24 26
     return layout;
25 27
   }
28
+
29
+  createContainerStackWithContainer(container) {
30
+    return {
31
+      type: 'ContainerStack',
32
+      id: this.uniqueIdProvider.generate(`ContainerStack`),
33
+      children: [
34
+        this.createContainer(container)
35
+      ]
36
+    };
37
+  }
38
+
39
+  createContainer(container) {
40
+    return {
41
+      data: {
42
+        ...container
43
+      },
44
+      type: 'Container',
45
+      id: this.uniqueIdProvider.generate(`Container`),
46
+      children: []
47
+    };
48
+  }
26 49
 }

+ 102
- 11
src/commands/LayoutTreeParser.test.js 파일 보기

@@ -4,25 +4,116 @@ describe('LayoutTreeParser', () => {
4 4
   let uut;
5 5
 
6 6
   beforeEach(() => {
7
-    const uniqueIdProvider = {generate: (p) => `${p}UNIQUE_ID`};
7
+    const uniqueIdProvider = {generate: (prefix) => `${prefix}+UNIQUE_ID`};
8 8
     const LayoutTreeParser = require('./LayoutTreeParser').default;
9 9
     uut = new LayoutTreeParser(uniqueIdProvider);
10 10
   });
11 11
 
12
-  it('returns a deep clone', () => {
13
-    const input = {inner: {foo: {bar: 1}}};
14
-    expect(uut.parse(input)).not.toBe(input);
15
-    expect(uut.parse(input).inner).not.toBe(input.inner);
16
-    expect(uut.parse(input).inner.foo).not.toBe(input.inner.foo);
12
+  it('parses single screen', () => {
13
+    expect(uut.parseSimpleApi(SimpleLayouts.singleScreenApp))
14
+      .toEqual({
15
+        type: 'ContainerStack',
16
+        id: 'ContainerStack+UNIQUE_ID',
17
+        children: [
18
+          {
19
+            type: 'Container',
20
+            id: 'Container+UNIQUE_ID',
21
+            data: {
22
+              name: 'com.example.MyScreen'
23
+            },
24
+            children: []
25
+          }
26
+        ]
27
+      });
17 28
   });
18 29
 
19
-  it('adds uniqueId to containers', () => {
30
+  it('parses single screen with props', () => {
31
+    expect(uut.parseSimpleApi(SimpleLayouts.singleScreenWithAditionalParams))
32
+      .toEqual({
33
+        type: 'ContainerStack',
34
+        id: 'ContainerStack+UNIQUE_ID',
35
+        children: [
36
+          {
37
+            type: 'Container',
38
+            id: 'Container+UNIQUE_ID',
39
+            children: [],
40
+            data: {
41
+              name: 'com.example.MyScreen',
42
+              passProps: {
43
+                foo: {
44
+                  number: 1,
45
+                  string: 'Hello!'
46
+                },
47
+                bar: SimpleLayouts.passedFunction
48
+              },
49
+              style: {},
50
+              buttons: {}
51
+            }
52
+          }
53
+        ]
54
+      });
55
+  });
56
+
57
+  xit('parses tab based', () => {
58
+    expect(uut.parseSimpleApi(SimpleLayouts.tabBasedApp))
59
+      .toEqual({
60
+        type: 'Tabs',
61
+        id: 'Tabs+UNIQUE_ID',
62
+        children: [
63
+          {
64
+            container: {
65
+              name: 'com.example.FirstTab'
66
+            }
67
+          },
68
+          {
69
+            container: {
70
+              name: 'com.example.SecondTab'
71
+            }
72
+          },
73
+          {
74
+            container: {
75
+              name: 'com.example.FirstTab'
76
+            }
77
+          }
78
+        ]
79
+      });
80
+  });
81
+
82
+  xit('adds uniqueId to containers', () => {
20 83
     const input = {container: {}};
21
-    expect(uut.parse(input)).toEqual({container: {id: 'containerUNIQUE_ID'}});
84
+    expect(uut.parse(input)).toEqual({container: {id: 'Container+UNIQUE_ID'}});
22 85
   });
23 86
 
24
-  it('parses simple structures', () => {
25
-    uut.parse(SimpleLayouts.singleScreenApp);
26
-    //TODO
87
+  xit('parses side menus', () => {
88
+    //const result2 = {
89
+    //  type: 'Menus',
90
+    //  id: 'MenusUNIQUE_ID',
91
+    //  children: [
92
+    //    {
93
+    //      type: 'Container',
94
+    //      id: 'ContainerUNIQUE_ID',
95
+    //      name: 'com.example.LeftSideMenu',
96
+    //      children: []
97
+    //    },
98
+    //    {
99
+    //      type: 'ContainerStack',
100
+    //      id: 'ContainerStackUNIQUE_ID',
101
+    //      children: [
102
+    //        {
103
+    //          type: 'Container',
104
+    //          id: 'ContainerUNIQUE_ID',
105
+    //          name: 'com.example.WelcomeScreen',
106
+    //          children: []
107
+    //        }
108
+    //      ]
109
+    //    },
110
+    //    {
111
+    //      type: 'Container',
112
+    //      id: 'ContainerUNIQUE_ID',
113
+    //      name: 'com.example.RightSideMenu',
114
+    //      children: []
115
+    //    }
116
+    //  ]
117
+    //};
27 118
   });
28 119
 });

+ 18
- 1
src/commands/SimpleLayouts.js 파일 보기

@@ -4,6 +4,23 @@ export const singleScreenApp = {
4 4
   }
5 5
 };
6 6
 
7
+export const passedFunction = () => 'Hello from a function';
8
+
9
+export const singleScreenWithAditionalParams = {
10
+  container: {
11
+    name: 'com.example.MyScreen',
12
+    passProps: {
13
+      foo: {
14
+        number: 1,
15
+        string: 'Hello!'
16
+      },
17
+      bar: passedFunction
18
+    },
19
+    style: {},
20
+    buttons: {}
21
+  }
22
+};
23
+
7 24
 export const tabBasedApp = {
8 25
   tabs: [
9 26
     {
@@ -62,7 +79,7 @@ export const singleWithBothMenus = {
62 79
   }
63 80
 };
64 81
 
65
-export const tabBasedWithSideMenu = {
82
+export const tabBasedWithBothSideMenus = {
66 83
   tabs: [
67 84
     {
68 85
       container: {