Bläddra i källkod

setRoot instead of startApp, events registry

Daniel Zlotin 8 år sedan
förälder
incheckning
2210f491e9

+ 1
- 1
ios/RNNBridgeModule.m Visa fil

@@ -12,7 +12,7 @@ RCT_EXPORT_MODULE();
12 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 17
 	UIApplication.sharedApplication.delegate.window.rootViewController = [[RNNControllerFactory new] createRootViewController:layout];
18 18
 	[UIApplication.sharedApplication.delegate.window makeKeyAndVisible];

+ 1
- 1
playground/e2e/app.test.js Visa fil

@@ -12,7 +12,7 @@ describe('app', () => {
12 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 16
     elementByLabel('Switch to tab based app with side menus').tap();
17 17
     // expect(elementByLabel('This is a tab screen')).toBeVisible();
18 18
   });

+ 2
- 2
playground/src/app.js Visa fil

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

+ 2
- 2
playground/src/containers/WelcomeScreen.js Visa fil

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

+ 4
- 4
src/Navigation.js Visa fil

@@ -19,12 +19,12 @@ class Navigation {
19 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 Visa fil

@@ -20,17 +20,15 @@ describe('Navigation', () => {
20 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 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 Visa fil

@@ -5,7 +5,7 @@ export default class NativeCommandsSender {
5 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 Visa fil

@@ -3,7 +3,7 @@ describe('NativeCommandsSender', () => {
3 3
 
4 4
   beforeEach(() => {
5 5
     mockNativeModule = {
6
-      startApp: jest.fn()
6
+      setRoot: jest.fn()
7 7
     };
8 8
     require('react-native').NativeModules.RNNBridgeModule = mockNativeModule;
9 9
     const NativeCommandsSender = require('./NativeCommandsSender').default;
@@ -11,7 +11,7 @@ describe('NativeCommandsSender', () => {
11 11
   });
12 12
 
13 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 Visa fil

@@ -6,7 +6,7 @@ export default class Commands {
6 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 Visa fil

@@ -1,7 +1,7 @@
1 1
 describe('Commands', () => {
2 2
   let uut;
3 3
   const mockCommandsSender = {
4
-    startApp: jest.fn()
4
+    setRoot: jest.fn()
5 5
   };
6 6
   const mockIdProvider = {
7 7
     generate: (prefix) => `${prefix}UNIQUE_ID`
@@ -12,15 +12,15 @@ describe('Commands', () => {
12 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 18
         container: {
19 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 24
         type: 'ContainerStack',
25 25
         id: 'ContainerStackUNIQUE_ID',
26 26
         children: [