Explorar el Código

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 hace 5 años
padre
commit
954e7348d7

+ 6
- 4
docs/docs/layout-types.md Ver fichero

@@ -200,10 +200,12 @@ const splitView = {
200 200
     // All layout types accepted supported by device, eg. `stack`
201 201
   },
202 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 Ver fichero

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

+ 2
- 0
lib/ios/RNNNavigationOptions.m Ver fichero

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

+ 6
- 0
lib/ios/RNNSplitViewController.m Ver fichero

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

+ 13
- 0
lib/ios/RNNSplitViewOptions.m Ver fichero

@@ -3,6 +3,19 @@
3 3
 
4 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 19
 -(void)applyOn:(UIViewController<RNNParentProtocol> *)viewController {
7 20
 	
8 21
 	UISplitViewController *svc = (UISplitViewController*) viewController;

+ 14
- 7
lib/src/commands/LayoutTreeParser.test.ts Ver fichero

@@ -1,8 +1,8 @@
1 1
 import * as _ from 'lodash';
2 2
 import { LayoutTreeParser } from './LayoutTreeParser';
3 3
 import { LayoutType } from './LayoutType';
4
+import { Options } from '../interfaces/Options';
4 5
 import { Layout } from '../interfaces/Layout';
5
-import { OptionsSplitView } from '../interfaces/Options';
6 6
 import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
7 7
 import { mock, instance, when, anything } from 'ts-mockito';
8 8
 
@@ -185,7 +185,7 @@ const passProps = {
185 185
   fnProp: () => 'Hello from a function'
186 186
 };
187 187
 
188
-const options = {
188
+const options: Options = {
189 189
   topBar: {
190 190
     title: {
191 191
       text: 'Hello1'
@@ -193,11 +193,18 @@ const options = {
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 210
 const singleComponent = {

+ 2
- 2
lib/src/interfaces/Layout.ts Ver fichero

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

+ 4
- 0
lib/src/interfaces/Options.ts Ver fichero

@@ -820,6 +820,10 @@ export interface Options {
820 820
    * Configure the side menu
821 821
    */
822 822
   sideMenu?: OptionsSideMenu;
823
+  /**
824
+   * Configure the splitView controller
825
+   */
826
+  splitView?: OptionsSplitView;
823 827
   /**
824 828
    * Configure the overlay
825 829
    */