Daniel Zlotin 6 years ago
parent
commit
8b105969aa

+ 2
- 2
docs/api/ComponentRegistry.md View File

2
 
2
 
3
 ## registerComponent
3
 ## registerComponent
4
 
4
 
5
-`registerComponent(componentName: string, getComponentClassFunc: ComponentProvider): void`
5
+`registerComponent(componentName: string, getComponentClassFunc: ComponentProvider): React.ComponentType<any>`
6
 
6
 
7
-[source](https://github.com/wix/react-native-navigation/blob/v2/lib/src/components/ComponentRegistry.ts#L11)
7
+[source](https://github.com/wix/react-native-navigation/blob/v2/lib/src/components/ComponentRegistry.ts#L12)
8
 
8
 
9
 ---
9
 ---
10
 
10
 

+ 1
- 1
docs/api/Navigation.md View File

8
 
8
 
9
 ## registerComponent
9
 ## registerComponent
10
 
10
 
11
-`registerComponent(componentName: string, getComponentClassFunc: ComponentProvider): void`
11
+`registerComponent(componentName: string, getComponentClassFunc: ComponentProvider): React.ComponentType<any>`
12
 
12
 
13
 [source](https://github.com/wix/react-native-navigation/blob/v2/lib/src/Navigation.ts#L52)
13
 [source](https://github.com/wix/react-native-navigation/blob/v2/lib/src/Navigation.ts#L52)
14
 
14
 

+ 2
- 2
lib/src/Navigation.ts View File

49
    * Every navigation component in your app must be registered with a unique name.
49
    * Every navigation component in your app must be registered with a unique name.
50
    * The component itself is a traditional React component extending React.Component.
50
    * The component itself is a traditional React component extending React.Component.
51
    */
51
    */
52
-  public registerComponent(componentName: string, getComponentClassFunc: ComponentProvider) {
53
-    this.componentRegistry.registerComponent(componentName, getComponentClassFunc);
52
+  public registerComponent(componentName: string, getComponentClassFunc: ComponentProvider): React.ComponentType<any> {
53
+    return this.componentRegistry.registerComponent(componentName, getComponentClassFunc);
54
   }
54
   }
55
 
55
 
56
   /**
56
   /**

+ 6
- 0
lib/src/components/ComponentRegistry.test.tsx View File

48
     const tree = renderer.create(<Component componentId='123' />);
48
     const tree = renderer.create(<Component componentId='123' />);
49
     expect(tree.toJSON()!.children).toEqual(['Hello, World!']);
49
     expect(tree.toJSON()!.children).toEqual(['Hello, World!']);
50
   });
50
   });
51
+
52
+  it('returns the wrapped registered component', () => {
53
+    const result = uut.registerComponent('example.MyComponent.name', () => MyComponent);
54
+    expect(result).toBeDefined();
55
+    expect(result).toBe(mockRegistry.mock.calls[0][1]());
56
+  });
51
 });
57
 });

+ 3
- 1
lib/src/components/ComponentRegistry.ts View File

1
+import * as React from 'react';
1
 import { AppRegistry, ComponentProvider } from 'react-native';
2
 import { AppRegistry, ComponentProvider } from 'react-native';
2
 import { ComponentWrapper } from './ComponentWrapper';
3
 import { ComponentWrapper } from './ComponentWrapper';
3
 
4
 
8
     this.store = store;
9
     this.store = store;
9
   }
10
   }
10
 
11
 
11
-  registerComponent(componentName: string, getComponentClassFunc: ComponentProvider) {
12
+  registerComponent(componentName: string, getComponentClassFunc: ComponentProvider): React.ComponentType<any> {
12
     const OriginalComponentClass = getComponentClassFunc();
13
     const OriginalComponentClass = getComponentClassFunc();
13
     const NavigationComponent = ComponentWrapper.wrap(componentName, OriginalComponentClass, this.store);
14
     const NavigationComponent = ComponentWrapper.wrap(componentName, OriginalComponentClass, this.store);
14
     this.store.setOriginalComponentClassForName(componentName, OriginalComponentClass);
15
     this.store.setOriginalComponentClassForName(componentName, OriginalComponentClass);
15
     AppRegistry.registerComponent(componentName, () => NavigationComponent);
16
     AppRegistry.registerComponent(componentName, () => NavigationComponent);
17
+    return NavigationComponent;
16
   }
18
   }
17
 }
19
 }