Browse Source

Refactor SplitView options and make them work with Tabs (#4612)

The bottomTab settings were not being properly applied if a SplitView
controller was nested. Part of this seems to be that the 'options' for
SplitView were in their V1 form, i.e. they did not have access to the
full topBar/bottomTab/etc.

I refactored the options to be in their own subsettings. NOTE: the
settings for splitView are not being applied currently -- they weren't
before and they still are not now.

With access to the full options now, I was able to change
RNNSplitViewController to properly override
willMoveToParentViewController to get the bottomTab icon to properly
show up.
Daniel Salinas 6 years ago
parent
commit
954e7348d7

+ 6
- 4
docs/docs/layout-types.md View File

200
     // All layout types accepted supported by device, eg. `stack`
200
     // All layout types accepted supported by device, eg. `stack`
201
   },
201
   },
202
   options: {
202
   options: {
203
-    displayMode: 'auto', // Master view display mode: `auto`, `visible`, `hidden` and `overlay`
204
-    primaryEdge: 'leading', // Master view side: `leading` or `trailing`
205
-    minWidth: 150, // Minimum width of master view
206
-    maxWidth: 300, // Maximum width of master view
203
+    splitView: {
204
+      displayMode: 'auto', // Master view display mode: `auto`, `visible`, `hidden` and `overlay`
205
+      primaryEdge: 'leading', // Master view side: `leading` or `trailing`
206
+      minWidth: 150, // Minimum width of master view
207
+      maxWidth: 300, // Maximum width of master view
208
+    },
207
   },
209
   },
208
 }
210
 }
209
 ```
211
 ```

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

10
 #import "RNNStatusBarOptions.h"
10
 #import "RNNStatusBarOptions.h"
11
 #import "RNNPreviewOptions.h"
11
 #import "RNNPreviewOptions.h"
12
 #import "RNNLayoutOptions.h"
12
 #import "RNNLayoutOptions.h"
13
+#import "RNNSplitViewOptions.h"
13
 
14
 
14
 extern const NSInteger BLUR_TOPBAR_TAG;
15
 extern const NSInteger BLUR_TOPBAR_TAG;
15
 extern const NSInteger TOP_BAR_TRANSPARENT_TAG;
16
 extern const NSInteger TOP_BAR_TRANSPARENT_TAG;
28
 @property (nonatomic, strong) RNNStatusBarOptions* statusBar;
29
 @property (nonatomic, strong) RNNStatusBarOptions* statusBar;
29
 @property (nonatomic, strong) RNNPreviewOptions* preview;
30
 @property (nonatomic, strong) RNNPreviewOptions* preview;
30
 @property (nonatomic, strong) RNNLayoutOptions* layout;
31
 @property (nonatomic, strong) RNNLayoutOptions* layout;
32
+@property (nonatomic, strong) RNNSplitViewOptions* splitView;
31
 
33
 
32
 @property (nonatomic, strong) Bool* popGesture;
34
 @property (nonatomic, strong) Bool* popGesture;
33
 @property (nonatomic, strong) Image* backgroundImage;
35
 @property (nonatomic, strong) Image* backgroundImage;

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

7
 #import "RNNRootViewController.h"
7
 #import "RNNRootViewController.h"
8
 #import "RNNSplitViewController.h"
8
 #import "RNNSplitViewController.h"
9
 #import "RNNNavigationButtons.h"
9
 #import "RNNNavigationButtons.h"
10
+#import "RNNSplitViewOptions.h"
10
 #import "UIViewController+RNNOptions.h"
11
 #import "UIViewController+RNNOptions.h"
11
 #import "UINavigationController+RNNOptions.h"
12
 #import "UINavigationController+RNNOptions.h"
12
 
13
 
21
 	self.topTabs = [[RNNTopTabsOptions alloc] initWithDict:dict[@"topTabs"]];
22
 	self.topTabs = [[RNNTopTabsOptions alloc] initWithDict:dict[@"topTabs"]];
22
 	self.topTab = [[RNNTopTabOptions alloc] initWithDict:dict[@"topTab"]];
23
 	self.topTab = [[RNNTopTabOptions alloc] initWithDict:dict[@"topTab"]];
23
 	self.sideMenu = [[RNNSideMenuOptions alloc] initWithDict:dict[@"sideMenu"]];
24
 	self.sideMenu = [[RNNSideMenuOptions alloc] initWithDict:dict[@"sideMenu"]];
25
+	self.splitView = [[RNNSplitViewOptions alloc] initWithDict:dict[@"splitView"]];
24
 	self.overlay = [[RNNOverlayOptions alloc] initWithDict:dict[@"overlay"]];
26
 	self.overlay = [[RNNOverlayOptions alloc] initWithDict:dict[@"overlay"]];
25
 	self.customTransition = [[RNNAnimationOptions alloc] initWithDict:dict[@"customTransition"]];
27
 	self.customTransition = [[RNNAnimationOptions alloc] initWithDict:dict[@"customTransition"]];
26
 	self.animations = [[RNNTransitionsOptions alloc] initWithDict:dict[@"animations"]];
28
 	self.animations = [[RNNTransitionsOptions alloc] initWithDict:dict[@"animations"]];

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

19
 	return self;
19
 	return self;
20
 }
20
 }
21
 
21
 
22
+- (void)willMoveToParentViewController:(UIViewController *)parent {
23
+	if (parent) {
24
+		[_presenter applyOptionsOnWillMoveToParentViewController:self.resolveOptions];
25
+	}
26
+}
27
+
22
 - (void)onChildWillAppear {
28
 - (void)onChildWillAppear {
23
 	[_presenter applyOptions:self.resolveOptions];
29
 	[_presenter applyOptions:self.resolveOptions];
24
 	[((UIViewController<RNNParentProtocol> *)self.parentViewController) onChildWillAppear];
30
 	[((UIViewController<RNNParentProtocol> *)self.parentViewController) onChildWillAppear];

+ 13
- 0
lib/ios/RNNSplitViewOptions.m View File

3
 
3
 
4
 @implementation RNNSplitViewOptions
4
 @implementation RNNSplitViewOptions
5
 
5
 
6
+- (instancetype)initWithDict:(NSDictionary *)dict {
7
+	self = [super init];
8
+	
9
+	self.displayMode = dict[@"displayMode"];
10
+	self.primaryEdge = dict[@"primaryEdge"];
11
+	NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
12
+	f.numberStyle = NSNumberFormatterDecimalStyle;
13
+	self.minWidth = [f numberFromString:dict[@"minWidth"]];
14
+	self.maxWidth = [f numberFromString:dict[@"maxWidth"]];
15
+	
16
+	return self;	
17
+}
18
+
6
 -(void)applyOn:(UIViewController<RNNParentProtocol> *)viewController {
19
 -(void)applyOn:(UIViewController<RNNParentProtocol> *)viewController {
7
 	
20
 	
8
 	UISplitViewController *svc = (UISplitViewController*) viewController;
21
 	UISplitViewController *svc = (UISplitViewController*) viewController;

+ 14
- 7
lib/src/commands/LayoutTreeParser.test.ts View File

1
 import * as _ from 'lodash';
1
 import * as _ from 'lodash';
2
 import { LayoutTreeParser } from './LayoutTreeParser';
2
 import { LayoutTreeParser } from './LayoutTreeParser';
3
 import { LayoutType } from './LayoutType';
3
 import { LayoutType } from './LayoutType';
4
+import { Options } from '../interfaces/Options';
4
 import { Layout } from '../interfaces/Layout';
5
 import { Layout } from '../interfaces/Layout';
5
-import { OptionsSplitView } from '../interfaces/Options';
6
 import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
6
 import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
7
 import { mock, instance, when, anything } from 'ts-mockito';
7
 import { mock, instance, when, anything } from 'ts-mockito';
8
 
8
 
185
   fnProp: () => 'Hello from a function'
185
   fnProp: () => 'Hello from a function'
186
 };
186
 };
187
 
187
 
188
-const options = {
188
+const options: Options = {
189
   topBar: {
189
   topBar: {
190
     title: {
190
     title: {
191
       text: 'Hello1'
191
       text: 'Hello1'
193
   }
193
   }
194
 };
194
 };
195
 
195
 
196
-const optionsSplitView: OptionsSplitView = {
197
-  displayMode: 'auto',
198
-  primaryEdge: 'leading',
199
-  minWidth: 150,
200
-  maxWidth: 300
196
+const optionsSplitView: Options = {
197
+  topBar: {
198
+    title: {
199
+      text: 'Hello1',
200
+    }
201
+  },
202
+  splitView: {
203
+    displayMode: 'auto',
204
+    primaryEdge: 'leading',
205
+    minWidth: 150,
206
+    maxWidth: 300
207
+  }
201
 };
208
 };
202
 
209
 
203
 const singleComponent = {
210
 const singleComponent = {

+ 2
- 2
lib/src/interfaces/Layout.ts View File

1
-import { Options, OptionsSplitView } from './Options';
1
+import { Options } from './Options';
2
 
2
 
3
 export interface LayoutComponent<P = {}> {
3
 export interface LayoutComponent<P = {}> {
4
   /**
4
   /**
110
   /**
110
   /**
111
    * Configure split view
111
    * Configure split view
112
    */
112
    */
113
-  options?: OptionsSplitView;
113
+  options?: Options;
114
 }
114
 }
115
 
115
 
116
 export interface TopTabs {
116
 export interface TopTabs {

+ 4
- 0
lib/src/interfaces/Options.ts View File

820
    * Configure the side menu
820
    * Configure the side menu
821
    */
821
    */
822
   sideMenu?: OptionsSideMenu;
822
   sideMenu?: OptionsSideMenu;
823
+  /**
824
+   * Configure the splitView controller
825
+   */
826
+  splitView?: OptionsSplitView;
823
   /**
827
   /**
824
    * Configure the overlay
828
    * Configure the overlay
825
    */
829
    */