Browse Source

pass props to external components

yogevbd 6 years ago
parent
commit
8406f4d384

+ 2
- 2
e2e/ApplicationLifecycleTest.test.js View File

@@ -20,7 +20,7 @@ describe('application lifecycle test', () => {
20 20
     await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
21 21
   });
22 22
 
23
-  it(':android: relaunch from background', async () => {
23
+  it('relaunch from background', async () => {
24 24
     await elementById(testIDs.PUSH_BUTTON).tap();
25 25
     await expect(elementByLabel('Pushed Screen')).toBeVisible();
26 26
 
@@ -40,7 +40,7 @@ describe('application lifecycle test', () => {
40 40
     await expect(elementByLabel('Pushed Screen')).toBeNotVisible();
41 41
   });
42 42
 
43
-  it(':android: device orientation does not destroy activity', async () => {
43
+  it('device orientation does not destroy activity', async () => {
44 44
     await elementById(testIDs.PUSH_BUTTON).tap();
45 45
     await expect(elementByLabel('Pushed Screen')).toBeVisible();
46 46
 

+ 1
- 1
e2e/ScreenStack.test.js View File

@@ -69,7 +69,7 @@ describe('screen stack', () => {
69 69
     await expect(elementByLabel('Screen 1')).toBeVisible();
70 70
   });
71 71
 
72
-  it(':android: push external component with options', async () => {
72
+  it('push external component with options', async () => {
73 73
     await elementById(testIDs.PUSH_EXTERNAL_COMPONENT_BUTTON).tap();
74 74
     await expect(elementByLabel('This is an external component')).toBeVisible();
75 75
     await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();

+ 2
- 1
lib/ios/RNNBridgeManager.h View File

@@ -1,11 +1,12 @@
1 1
 #import <Foundation/Foundation.h>
2 2
 #import <React/RCTBridge.h>
3
+#import "ReactNativeNavigation.h"
3 4
 
4 5
 @interface RNNBridgeManager : NSObject <RCTBridgeDelegate>
5 6
 
6 7
 - (instancetype)initWithJsCodeLocation:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions;
7 8
 
8
-- (void)registerExternalComponent:(NSString *)name callback:(UIViewController *(^)(void))callback;
9
+- (void)registerExternalComponent:(NSString *)name callback:(RNNExternalViewCreator)callback;
9 10
 
10 11
 @property (readonly, nonatomic, strong) RCTBridge *bridge;
11 12
 

+ 2
- 1
lib/ios/RNNControllerFactory.m View File

@@ -104,8 +104,9 @@
104 104
 
105 105
 - (UIViewController<RNNRootViewProtocol> *)createExternalComponent:(RNNLayoutNode*)node {
106 106
 	NSString* name = node.data[@"name"];
107
+	NSDictionary* props = node.data[@"passProps"];
107 108
 	
108
-	UIViewController* externalVC = [_store getExternalComponent:name];
109
+	UIViewController* externalVC = [_store getExternalComponent:name props:props];
109 110
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:_defaultOptionsDict];
110 111
 	[options mergeWith:node.data[@"options"]];
111 112
 	

+ 2
- 0
lib/ios/RNNCustomViewController.h View File

@@ -2,4 +2,6 @@
2 2
 
3 3
 @interface RNNCustomViewController : UIViewController
4 4
 
5
+- (instancetype)initWithProps:(NSDictionary*)props;
6
+
5 7
 @end

+ 14
- 3
lib/ios/RNNCustomViewController.m View File

@@ -1,6 +1,15 @@
1 1
 #import "RNNCustomViewController.h"
2 2
 
3
-@implementation RNNCustomViewController
3
+@implementation RNNCustomViewController {
4
+	NSString* _text;
5
+}
6
+
7
+- (instancetype)initWithProps:(NSDictionary *)props {
8
+	self = [super init];
9
+	_text = props[@"text"];
10
+	
11
+	return self;
12
+}
4 13
 
5 14
 - (void)viewDidLoad {
6 15
     [super viewDidLoad];
@@ -8,9 +17,11 @@
8 17
 }
9 18
 
10 19
 - (void)addTestLabel {
11
-	UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
20
+	UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
21
+	label.textAlignment = NSTextAlignmentCenter;
22
+	label.numberOfLines = 2;
12 23
 	label.center = self.view.center;
13
-	label.text = @"Test label";
24
+	label.text = _text;
14 25
 	label.accessibilityIdentifier = @"TestLabel";
15 26
 	[self.view addSubview:label];
16 27
 }

+ 2
- 2
lib/ios/RNNStore.h View File

@@ -2,9 +2,9 @@
2 2
 #import <Foundation/Foundation.h>
3 3
 #import <UIKit/UIKit.h>
4 4
 #import "RNNRootViewController.h"
5
+#import "ReactNativeNavigation.h"
5 6
 
6 7
 typedef void (^RNNTransitionCompletionBlock)(void);
7
-typedef UIViewController * (^RNNExternalViewCreator)(void);
8 8
 
9 9
 @interface RNNStore : NSObject
10 10
 
@@ -14,7 +14,7 @@ typedef UIViewController * (^RNNExternalViewCreator)(void);
14 14
 -(void) removeComponentByViewControllerInstance:(UIViewController*)componentInstance;
15 15
 
16 16
 - (void)registerExternalComponent:(NSString *)name callback:(RNNExternalViewCreator)callback;
17
-- (UIViewController *)getExternalComponent:(NSString *)name;
17
+- (UIViewController *)getExternalComponent:(NSString *)name props:(NSDictionary*)props;
18 18
 
19 19
 -(NSString*)componentKeyForInstance:(UIViewController*)instance;
20 20
 

+ 2
- 2
lib/ios/RNNStore.m View File

@@ -77,9 +77,9 @@
77 77
 	[_externalComponentCreators setObject:[callback copy] forKey:name];
78 78
 }
79 79
 
80
-- (UIViewController *)getExternalComponent:(NSString *)name {
80
+- (UIViewController *)getExternalComponent:(NSString *)name props:(NSDictionary*)props {
81 81
 	RNNExternalViewCreator creator = [_externalComponentCreators objectForKey:name];
82
-	return creator();
82
+	return creator(props);
83 83
 }
84 84
 
85 85
 @end

+ 1
- 1
lib/ios/ReactNativeNavigation.h View File

@@ -1,7 +1,7 @@
1 1
 #import <Foundation/Foundation.h>
2 2
 #import <UIKit/UIKit.h>
3 3
 
4
-typedef UIViewController * (^RNNExternalViewCreator)(void);
4
+typedef UIViewController * (^RNNExternalViewCreator)(NSDictionary* props);
5 5
 
6 6
 @interface ReactNativeNavigation : NSObject
7 7
 

+ 2
- 2
playground/ios/playground/AppDelegate.m View File

@@ -22,8 +22,8 @@
22 22
 	NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
23 23
 	[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
24 24
 	
25
-	[ReactNativeNavigation registerExternalComponent:@"RNNCustomComponent" callback:^UIViewController *{
26
-		return [[RNNCustomViewController alloc] init];
25
+	[ReactNativeNavigation registerExternalComponent:@"RNNCustomComponent" callback:^UIViewController *(NSDictionary *props) {
26
+		return [[RNNCustomViewController alloc] initWithProps:props];
27 27
 	}];
28 28
 	
29 29
 	/*