Skip to content

Commit

Permalink
Refactor SplitView options and make them work with Tabs (#4612)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zzorba authored and guyca committed Jan 24, 2019
1 parent 639fa26 commit 954e734
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 13 deletions.
10 changes: 6 additions & 4 deletions docs/docs/layout-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ const splitView = {
// All layout types accepted supported by device, eg. `stack`
},
options: {
displayMode: 'auto', // Master view display mode: `auto`, `visible`, `hidden` and `overlay`
primaryEdge: 'leading', // Master view side: `leading` or `trailing`
minWidth: 150, // Minimum width of master view
maxWidth: 300, // Maximum width of master view
splitView: {
displayMode: 'auto', // Master view display mode: `auto`, `visible`, `hidden` and `overlay`
primaryEdge: 'leading', // Master view side: `leading` or `trailing`
minWidth: 150, // Minimum width of master view
maxWidth: 300, // Maximum width of master view
},
},
}
```
Expand Down
2 changes: 2 additions & 0 deletions lib/ios/RNNNavigationOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "RNNStatusBarOptions.h"
#import "RNNPreviewOptions.h"
#import "RNNLayoutOptions.h"
#import "RNNSplitViewOptions.h"

extern const NSInteger BLUR_TOPBAR_TAG;
extern const NSInteger TOP_BAR_TRANSPARENT_TAG;
Expand All @@ -28,6 +29,7 @@ extern const NSInteger TOP_BAR_TRANSPARENT_TAG;
@property (nonatomic, strong) RNNStatusBarOptions* statusBar;
@property (nonatomic, strong) RNNPreviewOptions* preview;
@property (nonatomic, strong) RNNLayoutOptions* layout;
@property (nonatomic, strong) RNNSplitViewOptions* splitView;

@property (nonatomic, strong) Bool* popGesture;
@property (nonatomic, strong) Image* backgroundImage;
Expand Down
2 changes: 2 additions & 0 deletions lib/ios/RNNNavigationOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#import "RNNRootViewController.h"
#import "RNNSplitViewController.h"
#import "RNNNavigationButtons.h"
#import "RNNSplitViewOptions.h"
#import "UIViewController+RNNOptions.h"
#import "UINavigationController+RNNOptions.h"

Expand All @@ -21,6 +22,7 @@ - (instancetype)initWithDict:(NSDictionary *)dict {
self.topTabs = [[RNNTopTabsOptions alloc] initWithDict:dict[@"topTabs"]];
self.topTab = [[RNNTopTabOptions alloc] initWithDict:dict[@"topTab"]];
self.sideMenu = [[RNNSideMenuOptions alloc] initWithDict:dict[@"sideMenu"]];
self.splitView = [[RNNSplitViewOptions alloc] initWithDict:dict[@"splitView"]];
self.overlay = [[RNNOverlayOptions alloc] initWithDict:dict[@"overlay"]];
self.customTransition = [[RNNAnimationOptions alloc] initWithDict:dict[@"customTransition"]];
self.animations = [[RNNTransitionsOptions alloc] initWithDict:dict[@"animations"]];
Expand Down
6 changes: 6 additions & 0 deletions lib/ios/RNNSplitViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControll
return self;
}

- (void)willMoveToParentViewController:(UIViewController *)parent {
if (parent) {
[_presenter applyOptionsOnWillMoveToParentViewController:self.resolveOptions];
}
}

- (void)onChildWillAppear {
[_presenter applyOptions:self.resolveOptions];
[((UIViewController<RNNParentProtocol> *)self.parentViewController) onChildWillAppear];
Expand Down
13 changes: 13 additions & 0 deletions lib/ios/RNNSplitViewOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@

@implementation RNNSplitViewOptions

- (instancetype)initWithDict:(NSDictionary *)dict {
self = [super init];

self.displayMode = dict[@"displayMode"];
self.primaryEdge = dict[@"primaryEdge"];
NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
f.numberStyle = NSNumberFormatterDecimalStyle;
self.minWidth = [f numberFromString:dict[@"minWidth"]];
self.maxWidth = [f numberFromString:dict[@"maxWidth"]];

return self;
}

-(void)applyOn:(UIViewController<RNNParentProtocol> *)viewController {

UISplitViewController *svc = (UISplitViewController*) viewController;
Expand Down
21 changes: 14 additions & 7 deletions lib/src/commands/LayoutTreeParser.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as _ from 'lodash';
import { LayoutTreeParser } from './LayoutTreeParser';
import { LayoutType } from './LayoutType';
import { Options } from '../interfaces/Options';
import { Layout } from '../interfaces/Layout';
import { OptionsSplitView } from '../interfaces/Options';
import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
import { mock, instance, when, anything } from 'ts-mockito';

Expand Down Expand Up @@ -185,19 +185,26 @@ const passProps = {
fnProp: () => 'Hello from a function'
};

const options = {
const options: Options = {
topBar: {
title: {
text: 'Hello1'
}
}
};

const optionsSplitView: OptionsSplitView = {
displayMode: 'auto',
primaryEdge: 'leading',
minWidth: 150,
maxWidth: 300
const optionsSplitView: Options = {
topBar: {
title: {
text: 'Hello1',
}
},
splitView: {
displayMode: 'auto',
primaryEdge: 'leading',
minWidth: 150,
maxWidth: 300
}
};

const singleComponent = {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/interfaces/Layout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Options, OptionsSplitView } from './Options';
import { Options } from './Options';

export interface LayoutComponent<P = {}> {
/**
Expand Down Expand Up @@ -110,7 +110,7 @@ export interface LayoutSplitView {
/**
* Configure split view
*/
options?: OptionsSplitView;
options?: Options;
}

export interface TopTabs {
Expand Down
4 changes: 4 additions & 0 deletions lib/src/interfaces/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,10 @@ export interface Options {
* Configure the side menu
*/
sideMenu?: OptionsSideMenu;
/**
* Configure the splitView controller
*/
splitView?: OptionsSplitView;
/**
* Configure the overlay
*/
Expand Down

0 comments on commit 954e734

Please sign in to comment.