Browse Source

pass props to external components

yogevbd 6 years ago
parent
commit
8406f4d384

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

20
     await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
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
     await elementById(testIDs.PUSH_BUTTON).tap();
24
     await elementById(testIDs.PUSH_BUTTON).tap();
25
     await expect(elementByLabel('Pushed Screen')).toBeVisible();
25
     await expect(elementByLabel('Pushed Screen')).toBeVisible();
26
 
26
 
40
     await expect(elementByLabel('Pushed Screen')).toBeNotVisible();
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
     await elementById(testIDs.PUSH_BUTTON).tap();
44
     await elementById(testIDs.PUSH_BUTTON).tap();
45
     await expect(elementByLabel('Pushed Screen')).toBeVisible();
45
     await expect(elementByLabel('Pushed Screen')).toBeVisible();
46
 
46
 

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

69
     await expect(elementByLabel('Screen 1')).toBeVisible();
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
     await elementById(testIDs.PUSH_EXTERNAL_COMPONENT_BUTTON).tap();
73
     await elementById(testIDs.PUSH_EXTERNAL_COMPONENT_BUTTON).tap();
74
     await expect(elementByLabel('This is an external component')).toBeVisible();
74
     await expect(elementByLabel('This is an external component')).toBeVisible();
75
     await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
75
     await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();

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

1
 #import <Foundation/Foundation.h>
1
 #import <Foundation/Foundation.h>
2
 #import <React/RCTBridge.h>
2
 #import <React/RCTBridge.h>
3
+#import "ReactNativeNavigation.h"
3
 
4
 
4
 @interface RNNBridgeManager : NSObject <RCTBridgeDelegate>
5
 @interface RNNBridgeManager : NSObject <RCTBridgeDelegate>
5
 
6
 
6
 - (instancetype)initWithJsCodeLocation:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions;
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
 @property (readonly, nonatomic, strong) RCTBridge *bridge;
11
 @property (readonly, nonatomic, strong) RCTBridge *bridge;
11
 
12
 

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

104
 
104
 
105
 - (UIViewController<RNNRootViewProtocol> *)createExternalComponent:(RNNLayoutNode*)node {
105
 - (UIViewController<RNNRootViewProtocol> *)createExternalComponent:(RNNLayoutNode*)node {
106
 	NSString* name = node.data[@"name"];
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
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:_defaultOptionsDict];
110
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:_defaultOptionsDict];
110
 	[options mergeWith:node.data[@"options"]];
111
 	[options mergeWith:node.data[@"options"]];
111
 	
112
 	

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

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

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

1
 #import "RNNCustomViewController.h"
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
 - (void)viewDidLoad {
14
 - (void)viewDidLoad {
6
     [super viewDidLoad];
15
     [super viewDidLoad];
8
 }
17
 }
9
 
18
 
10
 - (void)addTestLabel {
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
 	label.center = self.view.center;
23
 	label.center = self.view.center;
13
-	label.text = @"Test label";
24
+	label.text = _text;
14
 	label.accessibilityIdentifier = @"TestLabel";
25
 	label.accessibilityIdentifier = @"TestLabel";
15
 	[self.view addSubview:label];
26
 	[self.view addSubview:label];
16
 }
27
 }

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

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

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

77
 	[_externalComponentCreators setObject:[callback copy] forKey:name];
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
 	RNNExternalViewCreator creator = [_externalComponentCreators objectForKey:name];
81
 	RNNExternalViewCreator creator = [_externalComponentCreators objectForKey:name];
82
-	return creator();
82
+	return creator(props);
83
 }
83
 }
84
 
84
 
85
 @end
85
 @end

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

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

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

22
 	NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
22
 	NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
23
 	[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
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
 	/*