Skip to content

Commit 63bdf3e

Browse files
author
talkol
committed
resolves issue #34 and referenced in issue #26
1 parent 99a25ae commit 63bdf3e

13 files changed

+61
-37
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ var { ControllerRegistry } = Controllers;
302302
ControllerRegistry.registerController('MoviesApp', () => MoviesApp);
303303
```
304304

305-
* **setRootController(controllerId, animationType = 'none')** - start the app with a root controller
305+
* **setRootController(controllerId, animationType = 'none', passProps = {})** - start the app with a root controller
306306

307307
```js
308308
// example without animation
@@ -312,6 +312,10 @@ ControllerRegistry.setRootController('MoviesApp');
312312
// example with animation, useful for changing your app root during runtime (from a different controller)
313313
// animationType: 'none', 'slide-down', 'fade'
314314
ControllerRegistry.setRootController('LoginApp', 'slide-down');
315+
316+
// example with props
317+
// these props will be passed to all top components in the layout hierarchy (eg. all tabs, side menus, etc.)
318+
ControllerRegistry.setRootController('MoviesApp', 'none', { greeting: 'hello world' });
315319
```
316320

317321
#### `Modal`
@@ -321,7 +325,7 @@ var Controllers = require('react-native-controllers');
321325
var { Modal } = Controllers;
322326
```
323327

324-
* **showController(controllerId, animationType = 'slide-up')** - display a controller modally
328+
* **showController(controllerId, animationType = 'slide-up', passProps = {})** - display a controller modally
325329

326330
```js
327331
// example with default slide up animation
@@ -331,6 +335,10 @@ Modal.showController('MoviesApp');
331335
// example without animation
332336
// animationType: 'none', 'slide-up'
333337
Modal.showController('LoginApp', 'none');
338+
339+
// example with props
340+
Modal.showController('MoviesApp', 'slide-up', { greeting: 'hello world' });
341+
334342
```
335343

336344
* **dismissController(animationType = 'slide-down')** - dismiss the current modal controller

example/ModalScreen.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ var ModalScreen = React.createClass({
2828
Notice how the show modal was 100% native. This screen doesn't have any special styles applied.
2929
</Text>
3030

31+
{
32+
!this.props.greeting ? false :
33+
<Text style={{fontSize: 16, textAlign: 'center', marginHorizontal: 30, marginBottom: 20}}>
34+
{this.props.greeting}
35+
</Text>
36+
}
37+
3138
<TouchableOpacity onPress={ this.onPushClick }>
3239
<Text style={styles.button}>Push Plain Screen</Text>
3340
</TouchableOpacity>

example/MovieListScreen.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ var MovieListScreen = React.createClass({
4949
},
5050

5151
onShowModalVcClick: async function() {
52-
Modal.showController('ModalScreenTester');
52+
// defaults: Modal.showController('ModalScreenTester');
53+
// this example shows animation type and passProps
54+
Modal.showController('ModalScreenTester', 'slide-up', { greeting: 'hi there!' });
5355
},
5456

5557
onReplaceRootAnimatedClick: function() {
56-
ControllerRegistry.setRootController('ModalScreenTester', 'slide-down');
58+
// this example shows animation type and passProps
59+
ControllerRegistry.setRootController('ModalScreenTester', 'slide-down', { greeting: 'how you doin?' });
5760
},
5861

5962
render: function() {

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ var Controllers = {
8686
registerController: function (appKey, getControllerFunc) {
8787
_controllerRegistry[appKey] = getControllerFunc();
8888
},
89-
setRootController: function (appKey, animationType = 'none') {
89+
setRootController: function (appKey, animationType = 'none', passProps = {}) {
9090
var controller = _controllerRegistry[appKey];
9191
if (controller === undefined) return;
9292
var layout = controller.render();
93-
RCCManager.setRootController(layout, animationType);
93+
RCCManager.setRootController(layout, animationType, passProps);
9494
}
9595
},
9696

@@ -200,11 +200,11 @@ var Controllers = {
200200
dismissLightBox: function() {
201201
RCCManager.modalDismissLightBox();
202202
},
203-
showController: function(appKey, animationType = 'slide-down') {
203+
showController: function(appKey, animationType = 'slide-up', passProps = {}) {
204204
var controller = _controllerRegistry[appKey];
205205
if (controller === undefined) return;
206206
var layout = controller.render();
207-
RCCManager.showController(layout, animationType);
207+
RCCManager.showController(layout, animationType, passProps);
208208
},
209209
dismissController: function(animationType = 'slide-down') {
210210
RCCManager.dismissController(animationType);

ios/RCCDrawerController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
@interface RCCDrawerController : MMDrawerController
66

7-
- (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children bridge:(RCTBridge *)bridge;
7+
- (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge;
88
- (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actionParams bridge:(RCTBridge *)bridge;
99

1010
@end

ios/RCCDrawerController.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44

55
@implementation RCCDrawerController
66

7-
- (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children bridge:(RCTBridge *)bridge
7+
- (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge
88
{
99
// center
1010
if ([children count] < 1) return nil;
11-
UIViewController *centerViewController = [RCCViewController controllerWithLayout:children[0] bridge:bridge];
11+
UIViewController *centerViewController = [RCCViewController controllerWithLayout:children[0] globalProps:globalProps bridge:bridge];
1212

1313
// left
1414
UIViewController *leftViewController = nil;
1515
NSString *componentLeft = props[@"componentLeft"];
1616
NSDictionary *passPropsLeft = props[@"passPropsLeft"];
17-
if (componentLeft) leftViewController = [[RCCViewController alloc] initWithComponent:componentLeft passProps:passPropsLeft navigatorStyle:nil bridge:bridge];
17+
if (componentLeft) leftViewController = [[RCCViewController alloc] initWithComponent:componentLeft passProps:passPropsLeft navigatorStyle:nil globalProps:globalProps bridge:bridge];
1818

1919
// right
2020
UIViewController *rightViewController = nil;
2121
NSString *componentRight = props[@"componentRight"];
2222
NSDictionary *passPropsRight = props[@"passPropsRight"];
23-
if (componentRight) rightViewController = [[RCCViewController alloc] initWithComponent:componentRight passProps:passPropsRight navigatorStyle:nil bridge:bridge];
23+
if (componentRight) rightViewController = [[RCCViewController alloc] initWithComponent:componentRight passProps:passPropsRight navigatorStyle:nil globalProps:globalProps bridge:bridge];
2424

2525
self = [super initWithCenterViewController:centerViewController
2626
leftDrawerViewController:leftViewController

ios/RCCManagerModule.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ - (dispatch_queue_t)methodQueue
6565
}
6666

6767
RCT_EXPORT_METHOD(
68-
setRootController:(NSDictionary*)layout animationType:(NSString*)animationType)
68+
setRootController:(NSDictionary*)layout animationType:(NSString*)animationType globalProps:(NSDictionary*)globalProps)
6969
{
7070
// create the new controller
71-
UIViewController *controller = [RCCViewController controllerWithLayout:layout bridge:[[RCCManager sharedInstance] getBridge]];
71+
UIViewController *controller = [RCCViewController controllerWithLayout:layout globalProps:globalProps bridge:[[RCCManager sharedInstance] getBridge]];
7272
if (controller == nil) return;
7373

7474
id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
@@ -161,9 +161,9 @@ - (dispatch_queue_t)methodQueue
161161
}
162162

163163
RCT_EXPORT_METHOD(
164-
showController:(NSDictionary*)layout animationType:(NSString*)animationType resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
164+
showController:(NSDictionary*)layout animationType:(NSString*)animationType globalProps:(NSDictionary*)globalProps resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
165165
{
166-
UIViewController *controller = [RCCViewController controllerWithLayout:layout bridge:[[RCCManager sharedInstance] getBridge]];
166+
UIViewController *controller = [RCCViewController controllerWithLayout:layout globalProps:globalProps bridge:[[RCCManager sharedInstance] getBridge]];
167167
if (controller == nil)
168168
{
169169
[RCCManagerModule handleRCTPromiseRejectBlock:reject

ios/RCCNavigationController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@interface RCCNavigationController : UINavigationController
55

6-
- (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children bridge:(RCTBridge *)bridge;
6+
- (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge;
77
- (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actionParams bridge:(RCTBridge *)bridge;
88

99
@end

ios/RCCNavigationController.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ @implementation RCCNavigationController
99
NSString const *CALLBACK_ASSOCIATED_KEY = @"RCCNavigationController.CALLBACK_ASSOCIATED_KEY";
1010
NSString const *CALLBACK_ASSOCIATED_ID = @"RCCNavigationController.CALLBACK_ASSOCIATED_ID";
1111

12-
- (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children bridge:(RCTBridge *)bridge
12+
- (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge
1313
{
1414
NSString *component = props[@"component"];
1515
if (!component) return nil;
1616

1717
NSDictionary *passProps = props[@"passProps"];
1818
NSDictionary *navigatorStyle = props[@"style"];
1919

20-
RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component passProps:passProps navigatorStyle:navigatorStyle bridge:bridge];
20+
RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component passProps:passProps navigatorStyle:navigatorStyle globalProps:globalProps bridge:bridge];
2121
if (!viewController) return nil;
2222

2323
NSString *title = props[@"title"];
@@ -77,7 +77,7 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio
7777
navigatorStyle = mergedStyle;
7878
}
7979

80-
RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component passProps:passProps navigatorStyle:navigatorStyle bridge:bridge];
80+
RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component passProps:passProps navigatorStyle:navigatorStyle globalProps:nil bridge:bridge];
8181

8282
NSString *title = actionParams[@"title"];
8383
if (title) viewController.title = title;
@@ -143,7 +143,7 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio
143143
NSDictionary *passProps = actionParams[@"passProps"];
144144
NSDictionary *navigatorStyle = actionParams[@"style"];
145145

146-
RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component passProps:passProps navigatorStyle:navigatorStyle bridge:bridge];
146+
RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component passProps:passProps navigatorStyle:navigatorStyle globalProps:nil bridge:bridge];
147147

148148
NSString *title = actionParams[@"title"];
149149
if (title) viewController.title = title;

ios/RCCTabBarController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@interface RCCTabBarController : UITabBarController
55

6-
- (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children bridge:(RCTBridge *)bridge;
6+
- (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge;
77
- (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actionParams bridge:(RCTBridge *)bridge completion:(void (^)(void))completion;
88

99
@end

0 commit comments

Comments
 (0)