Browse Source

setRoot instead of startApp, events registry

Daniel Zlotin 8 years ago
parent
commit
2210f491e9

+ 1
- 1
ios/RNNBridgeModule.m View File

12
 	return dispatch_get_main_queue();
12
 	return dispatch_get_main_queue();
13
 }
13
 }
14
 
14
 
15
-RCT_EXPORT_METHOD(startApp:(NSDictionary*)layout)
15
+RCT_EXPORT_METHOD(setRoot:(NSDictionary*)layout)
16
 {
16
 {
17
 	UIApplication.sharedApplication.delegate.window.rootViewController = [[RNNControllerFactory new] createRootViewController:layout];
17
 	UIApplication.sharedApplication.delegate.window.rootViewController = [[RNNControllerFactory new] createRootViewController:layout];
18
 	[UIApplication.sharedApplication.delegate.window makeKeyAndVisible];
18
 	[UIApplication.sharedApplication.delegate.window makeKeyAndVisible];

+ 1
- 1
playground/e2e/app.test.js View File

12
     expect(elementByLabel('This is a tab screen')).toBeVisible();
12
     expect(elementByLabel('This is a tab screen')).toBeVisible();
13
   });
13
   });
14
 
14
 
15
-  it('switch to tabs with side menus', () => {
15
+  xit('switch to tabs with side menus', () => {
16
     elementByLabel('Switch to tab based app with side menus').tap();
16
     elementByLabel('Switch to tab based app with side menus').tap();
17
     // expect(elementByLabel('This is a tab screen')).toBeVisible();
17
     // expect(elementByLabel('This is a tab screen')).toBeVisible();
18
   });
18
   });

+ 2
- 2
playground/src/app.js View File

5
 export function start() {
5
 export function start() {
6
   registerContainers();
6
   registerContainers();
7
 
7
 
8
-  Navigation.onAppLaunched(() => {
9
-    Navigation.startApp({
8
+  Navigation.events().onAppLaunched(() => {
9
+    Navigation.setRoot({
10
       container: {
10
       container: {
11
         name: 'com.example.WelcomeScreen'
11
         name: 'com.example.WelcomeScreen'
12
       }
12
       }

+ 2
- 2
playground/src/containers/WelcomeScreen.js View File

15
   }
15
   }
16
 
16
 
17
   onClickSwitchToTabs() {
17
   onClickSwitchToTabs() {
18
-    Navigation.startApp({
18
+    Navigation.setRoot({
19
       tabs: [
19
       tabs: [
20
         {
20
         {
21
           container: {
21
           container: {
32
   }
32
   }
33
 
33
 
34
   onClickSwitchToTabsWithSideMenus() {
34
   onClickSwitchToTabsWithSideMenus() {
35
-    Navigation.startApp({
35
+    Navigation.setRoot({
36
       tabs: [
36
       tabs: [
37
         {
37
         {
38
           container: {
38
           container: {

+ 4
- 4
src/Navigation.js View File

19
     this.containerRegistry.registerContainer(containerName, getContainerFunc);
19
     this.containerRegistry.registerContainer(containerName, getContainerFunc);
20
   }
20
   }
21
 
21
 
22
-  startApp(params) {
23
-    this.commands.startApp(params);
22
+  setRoot(params) {
23
+    this.commands.setRoot(params);
24
   }
24
   }
25
 
25
 
26
-  onAppLaunched(fn) {
27
-    this.nativeEventsReceiver.onAppLaunched(fn);
26
+  events() {
27
+    return this.nativeEventsReceiver;
28
   }
28
   }
29
 }
29
 }
30
 
30
 

+ 7
- 9
src/Navigation.test.js View File

20
     expect(Navigation.containerRegistry.registerContainer).toHaveBeenCalledWith('name', fn);
20
     expect(Navigation.containerRegistry.registerContainer).toHaveBeenCalledWith('name', fn);
21
   });
21
   });
22
 
22
 
23
-  it('startApp delegates to Commands', () => {
23
+  it('setRoot delegates to Commands', () => {
24
     const params = {};
24
     const params = {};
25
-    Navigation.startApp(params);
26
-    expect(Navigation.commands.startApp).toHaveBeenCalledTimes(1);
27
-    expect(Navigation.commands.startApp).toHaveBeenCalledWith(params);
25
+    Navigation.setRoot(params);
26
+    expect(Navigation.commands.setRoot).toHaveBeenCalledTimes(1);
27
+    expect(Navigation.commands.setRoot).toHaveBeenCalledWith(params);
28
   });
28
   });
29
 
29
 
30
-  it('onAppLaunched delegates to NativeEventsReceiver', () => {
31
-    const fn = jest.fn();
32
-    Navigation.onAppLaunched(fn);
33
-    expect(Navigation.nativeEventsReceiver.onAppLaunched).toHaveBeenCalledTimes(1);
34
-    expect(Navigation.nativeEventsReceiver.onAppLaunched).toHaveBeenCalledWith(fn);
30
+  it('events return the events registry', () => {
31
+    expect(Navigation.events()).toBeDefined();
32
+    expect(Navigation.events().onAppLaunched).toBeInstanceOf(Function);
35
   });
33
   });
36
 });
34
 });

+ 2
- 2
src/adapters/NativeCommandsSender.js View File

5
     this.nativeCommandsModule = NativeModules.RNNBridgeModule;
5
     this.nativeCommandsModule = NativeModules.RNNBridgeModule;
6
   }
6
   }
7
 
7
 
8
-  startApp(layoutTree) {
9
-    this.nativeCommandsModule.startApp(layoutTree);
8
+  setRoot(layoutTree) {
9
+    this.nativeCommandsModule.setRoot(layoutTree);
10
   }
10
   }
11
 }
11
 }

+ 3
- 3
src/adapters/NativeCommandsSender.test.js View File

3
 
3
 
4
   beforeEach(() => {
4
   beforeEach(() => {
5
     mockNativeModule = {
5
     mockNativeModule = {
6
-      startApp: jest.fn()
6
+      setRoot: jest.fn()
7
     };
7
     };
8
     require('react-native').NativeModules.RNNBridgeModule = mockNativeModule;
8
     require('react-native').NativeModules.RNNBridgeModule = mockNativeModule;
9
     const NativeCommandsSender = require('./NativeCommandsSender').default;
9
     const NativeCommandsSender = require('./NativeCommandsSender').default;
11
   });
11
   });
12
 
12
 
13
   it('delegates to native', () => {
13
   it('delegates to native', () => {
14
-    uut.startApp();
15
-    expect(mockNativeModule.startApp).toHaveBeenCalledTimes(1);
14
+    uut.setRoot();
15
+    expect(mockNativeModule.setRoot).toHaveBeenCalledTimes(1);
16
   });
16
   });
17
 });
17
 });

+ 2
- 2
src/commands/Commands.js View File

6
     this.layoutTreeParser = new LayoutTreeParser(uniqueIdProvider);
6
     this.layoutTreeParser = new LayoutTreeParser(uniqueIdProvider);
7
   }
7
   }
8
 
8
 
9
-  startApp(simpleApi) {
10
-    this.nativeCommandsSender.startApp(this.layoutTreeParser.parseFromSimpleJSON(simpleApi));
9
+  setRoot(simpleApi) {
10
+    this.nativeCommandsSender.setRoot(this.layoutTreeParser.parseFromSimpleJSON(simpleApi));
11
   }
11
   }
12
 }
12
 }

+ 6
- 6
src/commands/Commands.test.js View File

1
 describe('Commands', () => {
1
 describe('Commands', () => {
2
   let uut;
2
   let uut;
3
   const mockCommandsSender = {
3
   const mockCommandsSender = {
4
-    startApp: jest.fn()
4
+    setRoot: jest.fn()
5
   };
5
   };
6
   const mockIdProvider = {
6
   const mockIdProvider = {
7
     generate: (prefix) => `${prefix}UNIQUE_ID`
7
     generate: (prefix) => `${prefix}UNIQUE_ID`
12
     uut = new Commands(mockCommandsSender, mockIdProvider);
12
     uut = new Commands(mockCommandsSender, mockIdProvider);
13
   });
13
   });
14
 
14
 
15
-  describe('startApp', () => {
16
-    it('sends startApp to native after parsing into layoutTree', () => {
17
-      uut.startApp({
15
+  describe('setRoot', () => {
16
+    it('sends setRoot to native after parsing into layoutTree', () => {
17
+      uut.setRoot({
18
         container: {
18
         container: {
19
           name: 'com.example.MyScreen'
19
           name: 'com.example.MyScreen'
20
         }
20
         }
21
       });
21
       });
22
-      expect(mockCommandsSender.startApp).toHaveBeenCalledTimes(1);
23
-      expect(mockCommandsSender.startApp).toHaveBeenCalledWith({
22
+      expect(mockCommandsSender.setRoot).toHaveBeenCalledTimes(1);
23
+      expect(mockCommandsSender.setRoot).toHaveBeenCalledWith({
24
         type: 'ContainerStack',
24
         type: 'ContainerStack',
25
         id: 'ContainerStackUNIQUE_ID',
25
         id: 'ContainerStackUNIQUE_ID',
26
         children: [
26
         children: [