diff --git a/MVMCoreUI/BaseControllers/MFScrollingViewController.m b/MVMCoreUI/BaseControllers/MFScrollingViewController.m index f6e2c4d3..5486b54a 100644 --- a/MVMCoreUI/BaseControllers/MFScrollingViewController.m +++ b/MVMCoreUI/BaseControllers/MFScrollingViewController.m @@ -93,7 +93,7 @@ static NSTimeInterval const HandScrollAnimationTiming = 7.f; BOOL automaticInset = NO; if (@available(iOS 11.0, *)) { - automaticInset = self.scrollView.contentInsetAdjustmentBehavior == UIScrollViewContentInsetAdjustmentAutomatic; + automaticInset = self.navigationController && self.scrollView.contentInsetAdjustmentBehavior == UIScrollViewContentInsetAdjustmentAutomatic; } // Takes into account the navigation bar. diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index c378391a..0c3b3f3d 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -308,6 +308,8 @@ || self.manager || self.loadObject.requestParameters.tabWasPressed); } + } else { + [[MVMCoreUISession sharedGlobal].splitViewController.parentViewController setNeedsStatusBarAppearanceUpdate]; } } @@ -498,6 +500,15 @@ } } +//this method is needed for getting status bar style from present viewcotnroller +- (UIStatusBarStyle)preferredStatusBarStyle { + if ([self respondsToSelector:@selector(defaultStatusBarStyle)]) { + return [self defaultStatusBarStyle]; + } else { + return UIStatusBarStyleDefault; + } +} + - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h index 0c5a865d..acb56ad1 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h @@ -30,6 +30,10 @@ NS_ASSUME_NONNULL_BEGIN // View Controller can override this method and do custom action instead of opening the left panel - (BOOL)isOverridingLeftButton; +//return desired status bar style based on different View Controller +- (UIStatusBarStyle)defaultStatusBarStyle; +- (nullable UIColor *)defaultStatusBarBackgroundColor; + @end NS_ASSUME_NONNULL_END diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h index 2ef7fa25..0d4c9ea4 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h @@ -105,6 +105,10 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { + (CGFloat)getApplicationViewWidth; + (CGFloat)getApplicationViewMaxSize; +// return subviewcontrollers' prefer status bar style +- (UIStatusBarStyle)getDefaultStatusBarStyle; +- (nullable UIColor *)getDefaultStatusBarBackgroundColor; + #pragma mark - Main Subclassables // Can subclass to set threshold for when the drawers are permanently extended. Default is 1000 for the left panel and 2000 for both. diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index d70bdb6e..bdfd6ecd 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -877,7 +877,33 @@ CGFloat const PanelAnimationDuration = 0.2; } - (UIStatusBarStyle)preferredStatusBarStyle { - return self.topAlertView.statusBarStyle; + if (self.topAlertView.topAlertObject) { + return self.topAlertView.statusBarStyle; + } else { + UIStatusBarStyle style = [self getDefaultStatusBarStyle]; + [self.topAlertView resetDefaultBackgroundColor:[self getDefaultStatusBarBackgroundColor] basedOnStatusBarStyle:style]; + return style; + } +} + +- (UIStatusBarStyle)getDefaultStatusBarStyle { + UIViewController *viewController = [self getCurrentDetailViewController]; + if ([viewController conformsToProtocol:@protocol(MVMCoreUIDetailViewProtocol)] + && [viewController respondsToSelector:@selector(defaultStatusBarStyle)] + && [((UIViewController *)viewController) defaultStatusBarStyle]) { + return [((UIViewController *)viewController) defaultStatusBarStyle]; + } + return UIStatusBarStyleDefault; +} + +- (UIColor *)getDefaultStatusBarBackgroundColor { + UIViewController *viewController = [self getCurrentDetailViewController]; + if ([viewController conformsToProtocol:@protocol(MVMCoreUIDetailViewProtocol)] + && [viewController respondsToSelector:@selector(defaultStatusBarBackgroundColor)] + && [((UIViewController *)viewController) defaultStatusBarBackgroundColor]) { + return [((UIViewController *)viewController) defaultStatusBarBackgroundColor]; + } + return nil; } #pragma mark - Getters diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.h b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.h index 46d56cb6..5f49eb13 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.h +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.h @@ -41,6 +41,9 @@ - (void)expandStatusBarView; - (void)collapseStatusBarView; +/// reset status bar background color, when backgroundColor is nil corresponding background color will be set based on style +- (void)resetDefaultBackgroundColor:(nullable UIColor *)backgroundColor basedOnStatusBarStyle:(UIStatusBarStyle)style; + // Can be subclassed for custom views. - (nonnull MVMCoreUITopAlertBaseView *)topAlertViewForTopAlertObject:(nullable MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nonnull id )animationDelegate statusBarColor:(UIColor *_Nullable *_Nullable)statusBarColor; diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m index 735f28d9..b65f7423 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m @@ -189,7 +189,6 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed."; [weakSelf.superview layoutIfNeeded]; } completion:^(BOOL finished) { [weakSelf.animationDelegate topAlertViewFinishAnimation]; - [weakSelf setStatusBarColor:[UIColor whiteColor] statusBarStyle:UIStatusBarStyleDefault]; UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil); UIView *view = weakSelf.currentAlert; @@ -204,6 +203,9 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed."; [operation markAsFinished]; completionHandler(finished); weakSelf.topAlertObject = nil; + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + [weakSelf setStatusBarColor:[UIColor whiteColor] statusBarStyle:UIStatusBarStyleDefault]; + }]; }]; }]; }]; @@ -242,4 +244,18 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed."; }]; } +- (void)resetDefaultBackgroundColor:(UIColor *)backgroundColor basedOnStatusBarStyle:(UIStatusBarStyle)style { + if (!self.topAlertObject) { + UIColor *defaultStatusBarBackgroundColor = backgroundColor; + if (!defaultStatusBarBackgroundColor) { + defaultStatusBarBackgroundColor = style == UIStatusBarStyleDefault ? [UIColor whiteColor] : [UIColor blackColor]; + } + + //color doesn't match the current default value + if (!CGColorEqualToColor(defaultStatusBarBackgroundColor.CGColor, self.statusBarView.backgroundColor.CGColor)) { + self.statusBarView.backgroundColor = defaultStatusBarBackgroundColor; + } + } +} + @end