From 91890011d873756b8a1342a2c321fb0112a71ed0 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 16 May 2019 16:44:52 -0400 Subject: [PATCH] Panel protocol for override panel --- MVMCoreUI/BaseControllers/MFViewController.m | 1 + .../MVMCoreUIDetailViewProtocol.h | 6 + .../MVMCoreUIPanelProtocol.h | 8 +- .../MVMCoreUISplitViewController.h | 5 +- .../MVMCoreUISplitViewController.m | 178 ++++++++++++------ 5 files changed, 136 insertions(+), 62 deletions(-) diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index b6f71412..b9ce00de 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -297,6 +297,7 @@ if (navigationController == [MVMCoreUISplitViewController mainSplitViewController].navigationController) { // Update icons if main navigation controller. + [[MVMCoreUISession sharedGlobal].splitViewController setupPanels]; [self setMasterShouldBeAccessible:self.masterShouldBeAccessible]; [self setSupportShouldBeAccessible:self.supportShouldBeAccessible]; [self showBottomProgressBar]; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h index acb56ad1..038769fb 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h @@ -21,6 +21,12 @@ NS_ASSUME_NONNULL_BEGIN - (void)panelWillDisappear:(nonnull NSObject *)panel; - (void)panelDidDisappear:(nonnull NSObject *)panel; +/// Can override the left panel. +- (nullable UIViewController *)overrideLeftPanel; + +/// Can override the right panel. +- (nullable UIViewController *)overrideRightPanel; + // Called when the back button is pressed. Overwrite for special functionality. - (void)backButtonPressed; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h index f90391d3..4537e791 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h @@ -6,7 +6,7 @@ // Copyright © 2017 Verizon Wireless. All rights reserved. // -#import +#import @protocol MVMCoreUIPanelProtocol #pragma mark - life cycle @@ -33,6 +33,12 @@ - (void)showArrow; - (void)hideArrow; +/// The width to use if the panel is automatically extended when the screen is big enough. +- (CGFloat)panelExtendedWidth; + +/// The maximum width of the panel. +- (CGFloat)panelMaxWidth; + // Gets called when we are restarting or clearing a session. - (void)clearData; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h index 0d4c9ea4..cf27dc78 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h @@ -80,6 +80,9 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { // contains speicaly logic to set the icon color - (void)setNavigationIconColor:(nullable UIColor *)color; +/// Updates the panels that are used. +- (void)setupPanels; + #pragma mark - Bottom Progress Bar - (void)setBottomProgressBarProgress:(float)progress; @@ -114,7 +117,7 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { // Can subclass to set threshold for when the drawers are permanently extended. Default is 1000 for the left panel and 2000 for both. - (MFNumberOfDrawers)numberOfDrawersShouldShow:(nullable NSNumber *)forWidth; -// subclass to return panels +// subclass to return default global panels. kept alive after creation. - (nullable UIViewController *)createLeftPanelViewController; - (nullable UIViewController *)createRightPanelViewController; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index bdfd6ecd..73382510 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -27,6 +27,12 @@ @interface MVMCoreUISplitViewController () +typedef NS_OPTIONS(NSInteger, MFExtendedDrawer) { + MFExtendedDrawerNone = 0, + MFExtendedDrawerRight, + MFExtendedDrawerLeft +}; + @property (weak, nonatomic) UIView *leftView; @property (weak, nonatomic) UIView *mainView; @property (weak, nonatomic) UIView *rightView; @@ -38,6 +44,10 @@ @property (weak, nonatomic) UIView *leftPanelSeparator; @property (weak, nonatomic) UIView *rightPanelSeparator; +// For keeping +@property (strong, nonatomic, readwrite) UIViewController *globalLeftPanel; +@property (strong, nonatomic, readwrite) UIViewController *globalRightPanel; + @property (weak, nonatomic, readwrite) UIViewController *leftPanel; @property (weak, nonatomic, readwrite) UIViewController *rightPanel; @property (weak, nonatomic, readwrite) MVMCoreUINavigationController *navigationController; @@ -51,13 +61,7 @@ @property (nonatomic, strong) UIGestureRecognizer *tapToDismissGesture; @property (nullable, readwrite, weak, nonatomic) NSObject *explictlyShowingPanel; -@property (nullable, weak, nonatomic) NSObject *prioritizedExtendedPanel; - -typedef NS_OPTIONS(NSInteger, MFExtendedDrawer) { - MFExtendedDrawerNone = 0, - MFExtendedDrawerRight, - MFExtendedDrawerLeft -}; +@property (nonatomic) MFExtendedDrawer prioritizedExtendedPanel; @property (nonatomic) MFExtendedDrawer extendedDrawers; @property (nonatomic, readwrite) BOOL leftPanelIsAccessible; @@ -119,18 +123,30 @@ CGFloat const PanelAnimationDuration = 0.2; } - (CGFloat)leftPanelExtendedWidth { + if ([self.leftPanel respondsToSelector:@selector(panelExtendedWidth)]) { + return [self.leftPanel panelExtendedWidth]; + } return 320; } - (CGFloat)leftPanelMaxWidth { + if ([self.leftPanel respondsToSelector:@selector(panelMaxWidth)]) { + return [self.leftPanel panelMaxWidth]; + } return 415; } - (CGFloat)rightPanelExtendedWidth { + if ([self.rightPanel respondsToSelector:@selector(panelExtendedWidth)]) { + return [self.rightPanel panelExtendedWidth]; + } return 320; } - (CGFloat)rightPanelMaxWidth { + if ([self.rightPanel respondsToSelector:@selector(panelMaxWidth)]) { + return [self.rightPanel panelMaxWidth]; + } return 500; } @@ -217,7 +233,7 @@ CGFloat const PanelAnimationDuration = 0.2; return NO; } else { // left is extended if the right panel isn't prioritized. - return self.prioritizedExtendedPanel != self.rightPanel; + return self.prioritizedExtendedPanel != MFExtendedDrawerRight; } } } @@ -420,7 +436,7 @@ CGFloat const PanelAnimationDuration = 0.2; return NO; } else { // Extend right if the left panel isn't prioritized. - return self.prioritizedExtendedPanel != self.leftPanel; + return self.prioritizedExtendedPanel != MFExtendedDrawerLeft; } } } @@ -656,6 +672,94 @@ CGFloat const PanelAnimationDuration = 0.2; } } +- (void)addPanel:(nonnull UIViewController *)panel { + UIView *view = panel.view; + [self addChildViewController:panel]; + [self.view addSubview:view]; + [panel didMoveToParentViewController:self]; +} + +- (void)removePanel:(nullable UIViewController *)panel { + [panel willMoveToParentViewController:nil]; + [panel.view removeFromSuperview]; + [panel removeFromParentViewController]; +} + +- (void)setupLeftPanel { + UIViewController *panel = nil; + UIViewController *currentViewController = [self getCurrentDetailViewController]; + if ([currentViewController respondsToSelector:@selector(overrideLeftPanel)]) { + panel = [((UIViewController *)currentViewController) overrideLeftPanel]; + } else { + panel = self.globalLeftPanel; + self.leftPanelButton = nil; + } + + if (!panel) { + [self removePanel:self.leftPanel]; + } else if (panel && panel != self.leftPanel) { + [self removePanel:self.leftPanel]; + [self addPanel:panel]; + self.leftView = panel.view; + self.leftPanel = panel; + NSLayoutConstraint *leftPanelWidth = [NSLayoutConstraint constraintWithItem:self.leftView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:270]; + leftPanelWidth.active = YES; + self.leftPanelWidth = leftPanelWidth; + [NSLayoutConstraint constraintWithItem:self.mainView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.leftView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES; + [NSLayoutConstraint constraintWithItem:self.leftView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES; + [NSLayoutConstraint constraintWithItem:self.leftView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES; + + if ([panel respondsToSelector:@selector(buttonForPanel)]) { + self.leftPanelButton = [panel buttonForPanel]; + } else if ([panel respondsToSelector:@selector(imageForButtonForPanel)]) { + self.leftPanelButton = [[UIBarButtonItem alloc] initWithImage:[panel imageForButtonForPanel] style:UIBarButtonItemStylePlain target:self action:@selector(leftPanelButtonPressed:)]; + } else { + self.leftPanelButton = nil; + } + } +} + +- (void)setupRightPanel { + UIViewController *panel = nil; + UIViewController *currentViewController = [self getCurrentDetailViewController]; + if ([currentViewController respondsToSelector:@selector(overrideRightPanel)]) { + panel = [((UIViewController *)currentViewController) overrideRightPanel]; + } else { + panel = self.globalRightPanel; + } + + if (!panel) { + [self removePanel:self.rightPanel]; + self.rightPanelButton = nil; + } else if (panel && panel != self.rightPanel) { + [self removePanel:self.rightPanel]; + [self addPanel:panel]; + self.rightView = panel.view; + self.rightPanel = panel; + NSLayoutConstraint *rightPanelWidth = [NSLayoutConstraint constraintWithItem:self.rightView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:270]; + rightPanelWidth.active = YES; + self.rightPanelWidth = rightPanelWidth; + [NSLayoutConstraint constraintWithItem:self.rightView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES; + [NSLayoutConstraint constraintWithItem:self.rightView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES; + [NSLayoutConstraint constraintWithItem:self.rightView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES; + + if ([panel respondsToSelector:@selector(buttonForPanel)]) { + self.rightPanelButton = [panel buttonForPanel]; + } else if ([panel respondsToSelector:@selector(imageForButtonForPanel)]) { + self.rightPanelButton = [[UIBarButtonItem alloc] initWithImage:[panel imageForButtonForPanel] style:UIBarButtonItemStylePlain target:self action:@selector(rightPanelButtonPressed:)]; + } else { + self.rightPanelButton = nil; + } + } +} + +- (void)setupPanels { + [self setupLeftPanel]; + [self setupRightPanel]; + self.explictlyShowingPanel = nil; + [self.view layoutIfNeeded]; +} + #pragma mark - Bottom Progress Bar - (void)setBottomProgressBarProgress:(float)progress { @@ -744,62 +848,16 @@ CGFloat const PanelAnimationDuration = 0.2; [NSLayoutConstraint constraintWithItem:coverView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES; [NSLayoutConstraint constraintWithItem:coverView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES; - // Left Panel - UIViewController *leftPanel = [self createLeftPanelViewController]; - if (leftPanel) { - UIView *leftView = leftPanel.view; - [self addChildViewController:leftPanel]; - [self.view addSubview:leftView]; - [leftPanel didMoveToParentViewController:self]; - self.leftView = leftView; - self.leftPanel = leftPanel; - NSLayoutConstraint *leftPanelWidth = [NSLayoutConstraint constraintWithItem:leftView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:270]; - leftPanelWidth.active = YES; - self.leftPanelWidth = leftPanelWidth; - [NSLayoutConstraint constraintWithItem:mainView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:leftView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES; - [NSLayoutConstraint constraintWithItem:leftView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES; - [NSLayoutConstraint constraintWithItem:leftView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES; - } - - // Right Panel - UIViewController *rightPanel = [self createRightPanelViewController]; - if (rightPanel) { - UIView *rightView = rightPanel.view; - [self addChildViewController:rightPanel]; - [self.view addSubview:rightView]; - [rightPanel didMoveToParentViewController:self]; - self.rightView = rightView; - self.rightPanel = rightPanel; - NSLayoutConstraint *rightPanelWidth = [NSLayoutConstraint constraintWithItem:rightView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:270]; - rightPanelWidth.active = YES; - self.rightPanelWidth = rightPanelWidth; - [NSLayoutConstraint constraintWithItem:rightView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES; - [NSLayoutConstraint constraintWithItem:rightView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES; - [NSLayoutConstraint constraintWithItem:rightView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES; - } + // Create panels + self.globalLeftPanel = [self createLeftPanelViewController]; + self.globalRightPanel = [self createRightPanelViewController]; + [self setupPanels]; } - (void)viewDidLoad { [super viewDidLoad]; [self.topAlertView pinATopViewController:self]; - // Do any additional setup after loading the view. - if (self.leftPanel) { - if ([self.leftPanel respondsToSelector:@selector(buttonForPanel)]) { - self.leftPanelButton = [self.leftPanel buttonForPanel]; - } else { - self.leftPanelButton = [[UIBarButtonItem alloc] initWithImage:[self.leftPanel imageForButtonForPanel] style:UIBarButtonItemStylePlain target:self action:@selector(leftPanelButtonPressed:)]; - } - } - - if (self.rightPanel) { - if ([self.rightPanel respondsToSelector:@selector(buttonForPanel)]) { - self.rightPanelButton = [self.rightPanel buttonForPanel]; - } else { - self.rightPanelButton = [[UIBarButtonItem alloc] initWithImage:[self.rightPanel imageForButtonForPanel] style:UIBarButtonItemStylePlain target:self action:@selector(rightPanelButtonPressed:)]; - } - } - // Creates the back button self.backButton = [[UIBarButtonItem alloc] initWithImage:[self imageForBackButton] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)]; self.backButton.imageInsets = UIEdgeInsetsMake(0, 4, 0, -8); @@ -811,7 +869,7 @@ CGFloat const PanelAnimationDuration = 0.2; } self.extendedDrawers = MFExtendedDrawerLeft | MFExtendedDrawerRight; - self.prioritizedExtendedPanel = self.leftPanel; + self.prioritizedExtendedPanel = MFExtendedDrawerLeft; self.view.backgroundColor = [UIColor blackColor]; }