Browse Source

V2 default options (#2489)

* default options support
* refactored navigation options
yogevbd 6 years ago
parent
commit
5578b9507a
No account linked to committer's email address

+ 16
- 0
e2e/ScreenStyle.test.js View File

110
     await expect(elementById(testIDs.FIRST_TAB_BAR_BUTTON)).toBeVisible();
110
     await expect(elementById(testIDs.FIRST_TAB_BAR_BUTTON)).toBeVisible();
111
     await expect(elementById(testIDs.SECOND_TAB_BAR_BUTTON)).toBeVisible();
111
     await expect(elementById(testIDs.SECOND_TAB_BAR_BUTTON)).toBeVisible();
112
   });
112
   });
113
+
114
+  it('default options should apply to all screens in stack', async () => {
115
+    await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
116
+    await elementById(testIDs.PUSH_DEFAULT_OPTIONS_BUTTON).tap();
117
+    await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
118
+    await elementById(testIDs.PUSH_BUTTON).tap();
119
+    await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
120
+  });
121
+
122
+  it('default options should not override static options', async () => {
123
+    await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
124
+    await elementById(testIDs.PUSH_DEFAULT_OPTIONS_BUTTON).tap();
125
+    await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
126
+    await elementById(testIDs.POP_BUTTON).tap();
127
+    await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
128
+  });
113
 });
129
 });

+ 6
- 0
lib/ios/RNNBridgeModule.m View File

30
 	}];
30
 	}];
31
 }
31
 }
32
 
32
 
33
+RCT_EXPORT_METHOD(setDefaultOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
34
+	[_commandsHandler setDefaultOptions:options completion:^{
35
+		resolve(nil);
36
+	}];
37
+}
38
+
33
 RCT_EXPORT_METHOD(push:(NSString*)componentId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
39
 RCT_EXPORT_METHOD(push:(NSString*)componentId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
34
 	[_commandsHandler push:componentId layout:layout completion:^{
40
 	[_commandsHandler push:componentId layout:layout completion:^{
35
 		resolve(componentId);
41
 		resolve(componentId);

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

12
 
12
 
13
 -(void) setOptions:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion;
13
 -(void) setOptions:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion;
14
 
14
 
15
+-(void) setDefaultOptions:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion;
16
+
15
 -(void) push:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion;
17
 -(void) push:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion;
16
 
18
 
17
 -(void) pop:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion;
19
 -(void) pop:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion;

+ 6
- 0
lib/ios/RNNCommandsHandler.m View File

51
 	}
51
 	}
52
 }
52
 }
53
 
53
 
54
+-(void) setDefaultOptions:(NSDictionary*)optionsDict completion:(RNNTransitionCompletionBlock)completion {
55
+	[self assertReady];
56
+	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:optionsDict];
57
+	[_controllerFactory setDefaultOptions:options];
58
+}
59
+
54
 -(void) push:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
60
 -(void) push:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
55
 	[self assertReady];
61
 	[self assertReady];
56
 	
62
 	

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

15
 
15
 
16
 -(UIViewController<RNNRootViewProtocol> *)createLayoutAndSaveToStore:(NSDictionary*)layout;
16
 -(UIViewController<RNNRootViewProtocol> *)createLayoutAndSaveToStore:(NSDictionary*)layout;
17
 
17
 
18
+@property (nonatomic, strong) RNNNavigationOptions* defaultOptions;
19
+
18
 @end
20
 @end

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

89
 	NSDictionary* customTransition = node.data[@"customTransition"];
89
 	NSDictionary* customTransition = node.data[@"customTransition"];
90
 	RNNAnimator* animator = [[RNNAnimator alloc] initWithAnimationsDictionary:customTransition];
90
 	RNNAnimator* animator = [[RNNAnimator alloc] initWithAnimationsDictionary:customTransition];
91
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:node.data[@"options"]];
91
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:node.data[@"options"]];
92
+	options.defaultOptions = _defaultOptions;
92
 	NSString* componentId = node.nodeId;
93
 	NSString* componentId = node.nodeId;
93
 	RNNRootViewController* component = [[RNNRootViewController alloc] initWithName:name withOptions:options withComponentId:componentId rootViewCreator:_creator eventEmitter:_eventEmitter animator:animator];
94
 	RNNRootViewController* component = [[RNNRootViewController alloc] initWithName:name withOptions:options withComponentId:componentId rootViewCreator:_creator eventEmitter:_eventEmitter animator:animator];
94
 	CGSize availableSize = UIApplication.sharedApplication.delegate.window.bounds.size;
95
 	CGSize availableSize = UIApplication.sharedApplication.delegate.window.bounds.size;

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

19
 @property (nonatomic, strong) RNNTopTabOptions* topTab;
19
 @property (nonatomic, strong) RNNTopTabOptions* topTab;
20
 @property (nonatomic, strong) RNNSideMenuOptions* sideMenu;
20
 @property (nonatomic, strong) RNNSideMenuOptions* sideMenu;
21
 
21
 
22
+@property (nonatomic, strong) RNNNavigationOptions* defaultOptions;
23
+
22
 @property (nonatomic, strong) NSNumber* statusBarHidden;
24
 @property (nonatomic, strong) NSNumber* statusBarHidden;
23
 @property (nonatomic, strong) NSNumber* screenBackgroundColor;
25
 @property (nonatomic, strong) NSNumber* screenBackgroundColor;
24
 @property (nonatomic, strong) NSMutableDictionary* originalTopBarImages;
26
 @property (nonatomic, strong) NSMutableDictionary* originalTopBarImages;

+ 6
- 1
lib/ios/RNNNavigationOptions.m View File

46
 }
46
 }
47
 
47
 
48
 -(void)applyOn:(UIViewController*)viewController {
48
 -(void)applyOn:(UIViewController*)viewController {
49
+	[_defaultOptions applyOn:viewController];
50
+	
49
 	[self.topBar applyOn:viewController];
51
 	[self.topBar applyOn:viewController];
50
 	[self.bottomTabs applyOn:viewController];
52
 	[self.bottomTabs applyOn:viewController];
51
 	[self.topTab applyOn:viewController];
53
 	[self.topTab applyOn:viewController];
52
 	[self.bottomTab applyOn:viewController];
54
 	[self.bottomTab applyOn:viewController];
53
 	[self.sideMenu applyOn:viewController];
55
 	[self.sideMenu applyOn:viewController];
54
-	
56
+	[self applyOtherOptionsOn:viewController];
57
+}
58
+
59
+- (void)applyOtherOptionsOn:(UIViewController*)viewController {
55
 	if (self.popGesture) {
60
 	if (self.popGesture) {
56
 		viewController.navigationController.interactivePopGestureRecognizer.enabled = [self.popGesture boolValue];
61
 		viewController.navigationController.interactivePopGestureRecognizer.enabled = [self.popGesture boolValue];
57
 	}
62
 	}

+ 8
- 4
lib/ios/RNNOptions.h View File

1
 #import <Foundation/Foundation.h>
1
 #import <Foundation/Foundation.h>
2
 #import <UIKit/UIKit.h>
2
 #import <UIKit/UIKit.h>
3
 #import <React/RCTConvert.h>
3
 #import <React/RCTConvert.h>
4
+
5
+@class RNNOptions;
6
+
4
 @protocol RNNOptionsProtocol <NSObject>
7
 @protocol RNNOptionsProtocol <NSObject>
5
 
8
 
6
 @optional
9
 @optional
7
--(void)resetOptions;
8
--(void)applyOn:(UIViewController*)viewController;
10
+- (void)resetOptions;
11
+- (void)applyOn:(UIViewController *)viewController;
9
 
12
 
10
 @end
13
 @end
11
 
14
 
12
 @interface RNNOptions : NSObject <RNNOptionsProtocol>
15
 @interface RNNOptions : NSObject <RNNOptionsProtocol>
13
 
16
 
14
--(instancetype)initWithDict:(NSDictionary*)dict;
15
--(void)mergeWith:(NSDictionary*)otherOptions;
17
+- (instancetype)initWithDict:(NSDictionary*)dict;
18
+- (void)mergeWith:(NSDictionary*)otherOptions;
19
+- (void)applyOn:(UIViewController *)viewController defaultOptions:(RNNOptions*)defaultOptions;
16
 
20
 
17
 @end
21
 @end

+ 5
- 0
lib/ios/RNNOptions.m View File

9
 	return self;
9
 	return self;
10
 }
10
 }
11
 
11
 
12
+- (void)applyOn:(UIViewController *)viewController defaultOptions:(RNNOptions *)defaultOptions {
13
+	[defaultOptions applyOn:viewController];
14
+	[self applyOn:viewController];
15
+}
16
+
12
 -(void)mergeWith:(NSDictionary *)otherOptions {
17
 -(void)mergeWith:(NSDictionary *)otherOptions {
13
 	for (id key in otherOptions) {
18
 	for (id key in otherOptions) {
14
 		[self setValue:[otherOptions objectForKey:key] forKey:key];
19
 		[self setValue:[otherOptions objectForKey:key] forKey:key];

+ 17
- 1
playground/src/screens/OptionsScreen.js View File

48
     this.onClickTopBarTransparent = this.onClickTopBarTransparent.bind(this);
48
     this.onClickTopBarTransparent = this.onClickTopBarTransparent.bind(this);
49
     this.onClickTopBarOpaque = this.onClickTopBarOpaque.bind(this);
49
     this.onClickTopBarOpaque = this.onClickTopBarOpaque.bind(this);
50
     this.onClickCustomTranstition = this.onClickCustomTranstition.bind(this);
50
     this.onClickCustomTranstition = this.onClickCustomTranstition.bind(this);
51
+    this.onClickPushDefaultOptionsScreen = this.onClickPushDefaultOptionsScreen.bind(this);
51
   }
52
   }
52
 
53
 
53
   render() {
54
   render() {
63
         <Button title="Custom Transition" onPress={this.onClickCustomTranstition} />
64
         <Button title="Custom Transition" onPress={this.onClickCustomTranstition} />
64
         <Button title="Show custom alert" testID={testIDs.SHOW_CUSTOM_ALERT_BUTTON} onPress={this.onClickAlert} />
65
         <Button title="Show custom alert" testID={testIDs.SHOW_CUSTOM_ALERT_BUTTON} onPress={this.onClickAlert} />
65
         <Button title="Show snackbar" testID={testIDs.SHOW_SNACKBAR_BUTTON} onPress={this.onClickSnackbar} />
66
         <Button title="Show snackbar" testID={testIDs.SHOW_SNACKBAR_BUTTON} onPress={this.onClickSnackbar} />
66
-        <Text style={styles.footer}>{`this.props.componentId = ${this.props.componentId}`}</Text>
67
+        <Button title="Push Default Options Screen" testID={testIDs.PUSH_DEFAULT_OPTIONS_BUTTON} onPress={this.onClickPushDefaultOptionsScreen} />
68
+        <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
67
       </View>
69
       </View>
68
     );
70
     );
69
   }
71
   }
187
       }
189
       }
188
     });
190
     });
189
   }
191
   }
192
+
193
+  onClickPushDefaultOptionsScreen() {
194
+    Navigation.setDefaultOptions({
195
+      topBar: {
196
+        hidden: true
197
+      }
198
+    });
199
+
200
+    Navigation.push(this.props.componentId, {
201
+      component: {
202
+        name: 'navigation.playground.PushedScreen'
203
+      }
204
+    });
205
+  }
190
 }
206
 }
191
 
207
 
192
 const styles = {
208
 const styles = {

+ 8
- 0
playground/src/screens/PushedScreen.js View File

9
 const testIDs = require('../testIDs');
9
 const testIDs = require('../testIDs');
10
 
10
 
11
 class PushedScreen extends Component {
11
 class PushedScreen extends Component {
12
+  static get navigationOptions() {
13
+    return {
14
+      topBar: {
15
+        testID: testIDs.TOP_BAR_ELEMENT
16
+      }
17
+    };
18
+  }
19
+
12
   constructor(props) {
20
   constructor(props) {
13
     super(props);
21
     super(props);
14
     this.onClickPush = this.onClickPush.bind(this);
22
     this.onClickPush = this.onClickPush.bind(this);

+ 1
- 0
playground/src/testIDs.js View File

7
   PUSH_LIFECYCLE_BUTTON: `PUSH_LIFECYCLE_BUTTON`,
7
   PUSH_LIFECYCLE_BUTTON: `PUSH_LIFECYCLE_BUTTON`,
8
   PUSH_BUTTON: `PUSH_BUTTON`,
8
   PUSH_BUTTON: `PUSH_BUTTON`,
9
   PUSH_OPTIONS_BUTTON: `PUSH_OPTIONS_BUTTON`,
9
   PUSH_OPTIONS_BUTTON: `PUSH_OPTIONS_BUTTON`,
10
+  PUSH_DEFAULT_OPTIONS_BUTTON: `PUSH_DEFAULT_OPTIONS_BUTTON`,
10
   BACK_HANDLER_BUTTON: `BACK_HANDLER_BUTTON`,
11
   BACK_HANDLER_BUTTON: `BACK_HANDLER_BUTTON`,
11
   SHOW_MODAL_BUTTON: `SHOW_MODAL_BUTTON`,
12
   SHOW_MODAL_BUTTON: `SHOW_MODAL_BUTTON`,
12
   SHOW_REDBOX_BUTTON: `SHOW_REDBOX_BUTTON`,
13
   SHOW_REDBOX_BUTTON: `SHOW_REDBOX_BUTTON`,