From 1d7e1be051324202ecae01fe2234c0837893fed6 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 28 Jan 2019 14:25:29 -0500 Subject: [PATCH] Convenience for load screen re-link framework --- ...CoreUINavigationControllerViewController.h | 3 ++ ...CoreUINavigationControllerViewController.m | 6 +++ .../MVMCoreUISplitViewController.h | 6 ++- .../MVMCoreUISplitViewController.m | 45 +++-------------- MVMCoreUI/Session/MVMCoreUISession.h | 3 ++ MVMCoreUI/Session/MVMCoreUISession.m | 49 +++++++++++++++++++ 6 files changed, 71 insertions(+), 41 deletions(-) diff --git a/MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.h b/MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.h index 3ec6d4c7..2fe06d1e 100644 --- a/MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.h +++ b/MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.h @@ -18,6 +18,9 @@ NS_ASSUME_NONNULL_BEGIN // Returns a navigation controller with the mvm styling. Also sets the navigation controller in the appropriate handlers. + (nullable instancetype)setupNavigationController; +// Returns a navigation controller with the mvm styling. Also sets the navigation controller in the appropriate handlers. Adds the default loading overlay screen as well. ++ (nullable instancetype)setupWithNavigationControllerAsMainController; + // Separator at the bottom of the navigation bar used for styling. @property (nullable, weak, nonatomic) SeparatorView *separatorView; @end diff --git a/MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.m b/MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.m index fc3f4310..f0143315 100644 --- a/MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.m +++ b/MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.m @@ -43,4 +43,10 @@ return navigationController; } ++ (nullable instancetype)setupWithNavigationControllerAsMainController { + MVMCoreUINavigationControllerViewController *navigationController = [self setupNavigationController]; + [[MVMCoreUISession sharedGlobal] setupAsStandardLoadViewDelegate:navigationController]; + return navigationController; +} + @end diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h index 6e59dde6..a5e5b6a9 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h @@ -9,7 +9,6 @@ #import @import MVMCore.MVMCoreActionDelegateProtocol; -@import MVMCore.MVMCoreLoadingOverlayDelegateProtocol; #import #import @@ -23,7 +22,7 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { MFTwoDrawer }; -@interface MVMCoreUISplitViewController : UIViewController +@interface MVMCoreUISplitViewController : UIViewController // Reference to the panels. @property (nullable, weak, nonatomic, readonly) UIViewController *leftPanel; @@ -51,6 +50,9 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { // Returns a split controller with the mvm styling. Also sets the appropriate handlers. + (nullable instancetype)setup; +// Returns a split controller with the mvm styling. Also sets the appropriate handlers. Also sets up the default load screen ++ (nullable instancetype)setupAsMainController; + #pragma mark - Panel Functions // Sets if the left panel accessible for the view controller. Will show or hide the button. diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index 50b50a84..bd150f59 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -9,7 +9,6 @@ #import "MVMCoreUISplitViewController.h" @import MVMCore.MVMCoreNavigationHandler; @import MVMCore.MVMCoreDispatchUtility; -@import MVMCore.MVMCoreViewControllerProtocol; @import MVMCore.MVMCoreViewManagerProtocol; @import MVMCore.MVMCoreObject; @import MVMCore.MVMCoreActionUtility; @@ -18,7 +17,6 @@ #import "NSLayoutConstraint+MFConvenience.h" #import "MFViewController.h" #import "MFFonts.h" -#import "MFLoadingViewController.h" #import #import "SeparatorView.h" #import "MVMCoreUISession.h" @@ -50,8 +48,6 @@ @property (weak, nonatomic) IBOutlet UIProgressView *bottomProgressBar; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomProgressBarHeightConstraint; -@property (weak, nonatomic) MFLoadingViewController *loadingViewController; - @property (nonatomic, strong) UIGestureRecognizer *tapToDismissGesture; @property (nullable, readwrite, weak, nonatomic) NSObject *explictlyShowingPanel; @@ -88,6 +84,12 @@ CGFloat const PanelAnimationDuration = 0.2; return splitViewController; } ++ (nullable instancetype)setupAsMainController { + MVMCoreUISplitViewController *splitViewController = [self setup]; + [[MVMCoreUISession sharedGlobal] setupAsStandardLoadViewDelegate:splitViewController]; + return splitViewController; +} + #pragma mark - Main Subclassables - (MFNumberOfDrawers)numberOfDrawersShouldShow:(NSNumber *)forWidth { @@ -932,39 +934,4 @@ CGFloat const PanelAnimationDuration = 0.2; } } -#pragma mark - MVMCoreLoadingOverlayDelegateProtocol - -- (nonnull UIViewController *)getLoadingViewController { - - if (self.loadingViewController) { - return self.loadingViewController; - } else { - MFLoadingViewController *loadingViewController = [[MFLoadingViewController alloc] init]; - UIView *view = loadingViewController.view; - view.hidden = YES; - self.loadingViewController = loadingViewController; - - // Adds the overlay to the screen. - UIView *viewToPresentOn = self.view; - - [self addChildViewController:loadingViewController]; - [viewToPresentOn addSubview:view]; - [loadingViewController didMoveToParentViewController:self]; - - // Sets the constraints for autolayout - [view setTranslatesAutoresizingMaskIntoConstraints:NO]; - [NSLayoutConstraint constraintPinSubviewToSuperview:view]; - return loadingViewController; - } -} - -- (void)beginningLoading { - // Disables the UI when loading - self.view.userInteractionEnabled = NO; -} - -- (void)finishedLoading { - self.view.userInteractionEnabled = YES; -} - @end diff --git a/MVMCoreUI/Session/MVMCoreUISession.h b/MVMCoreUI/Session/MVMCoreUISession.h index 4589e12e..505f7008 100644 --- a/MVMCoreUI/Session/MVMCoreUISession.h +++ b/MVMCoreUI/Session/MVMCoreUISession.h @@ -29,6 +29,9 @@ NS_ASSUME_NONNULL_BEGIN // Allows a global overload of the title view of navigation item. - (nullable UIView *)titleViewForController:(nonnull MFViewController *)controller; +// Sets up the session as delegate for standard load view controller. Pass the view controller that will be used to present and will be disabled when load view is presented. +- (void)setupAsStandardLoadViewDelegate:(nonnull UIViewController *)mainViewController; + @end NS_ASSUME_NONNULL_END diff --git a/MVMCoreUI/Session/MVMCoreUISession.m b/MVMCoreUI/Session/MVMCoreUISession.m index afe99b76..238a7b2d 100644 --- a/MVMCoreUI/Session/MVMCoreUISession.m +++ b/MVMCoreUI/Session/MVMCoreUISession.m @@ -7,6 +7,16 @@ // #import "MVMCoreUISession.h" +#import "MFLoadingViewController.h" +#import "NSLayoutConstraint+MFConvenience.h" +@import MVMCore.MVMCoreObject; + +@interface MVMCoreUISession () + +@property (weak, nonatomic, nullable) UIViewController *mainViewController; +@property (weak, nonatomic, nullable) MFLoadingViewController *loadingViewController; + +@end @implementation MVMCoreUISession @@ -14,4 +24,43 @@ return nil; } +- (void)setupAsStandardLoadViewDelegate:(nonnull UIViewController *)mainViewController { + self.mainViewController = mainViewController; + [MVMCoreObject sharedInstance].loadingProtocol = self; +} + +#pragma mark - MVMCoreLoadingOverlayDelegateProtocol + +- (nonnull UIViewController *)getLoadingViewController { + + if (self.loadingViewController) { + return self.loadingViewController; + } else { + MFLoadingViewController *loadingViewController = [[MFLoadingViewController alloc] init]; + UIView *view = loadingViewController.view; + view.hidden = YES; + self.loadingViewController = loadingViewController; + + // Adds the overlay to the screen. + UIView *viewToPresentOn = self.mainViewController.view; + [self.mainViewController addChildViewController:loadingViewController]; + [viewToPresentOn addSubview:view]; + [loadingViewController didMoveToParentViewController:self.mainViewController]; + + // Sets the constraints for autolayout + [view setTranslatesAutoresizingMaskIntoConstraints:NO]; + [NSLayoutConstraint constraintPinSubviewToSuperview:view]; + return loadingViewController; + } +} + +- (void)beginningLoading { + // Disables the UI when loading + self.mainViewController.view.userInteractionEnabled = NO; +} + +- (void)finishedLoading { + self.mainViewController.view.userInteractionEnabled = YES; +} + @end