Merge branch 'feature/status_bar_fixes' into 'feature/develop_mvp_3'
Status Bar changes for 3.0 See merge request BPHV_MIPS/mvm_core_ui!813
This commit is contained in:
commit
5b3b3246ec
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
// Navigation bar update functions
|
||||
public extension MVMCoreUISplitViewController {
|
||||
@ -117,6 +118,29 @@ public extension MVMCoreUISplitViewController {
|
||||
navigationController.isDisplayed(viewController: viewController),
|
||||
let model = navigationController.getNavigationModel(from: viewController) else { return }
|
||||
setNavigationBar(for: viewController, navigationController: navigationController, navigationItemModel: model)
|
||||
guard !(topAlertView?.overridingStatusBar() ?? false) else { return }
|
||||
setStatusBarForCurrentViewController()
|
||||
}
|
||||
|
||||
/// Returns the bar style for the background color. Light if on a dark background, otherwise default.
|
||||
func getStatusBarStyle(for backgroundColor: UIColor?) -> UIStatusBarStyle {
|
||||
var greyScale: CGFloat = 0
|
||||
if backgroundColor?.getWhite(&greyScale, alpha: nil) == true,
|
||||
greyScale < 0.5 { return .lightContent }
|
||||
return .default
|
||||
}
|
||||
|
||||
/// Updates the status bar background color and style.
|
||||
@objc func setStatusBarForCurrentViewController() {
|
||||
let viewController = getCurrentViewController() as? MVMCoreUIDetailViewProtocol
|
||||
let backgroundColor = viewController?.defaultStatusBarBackgroundColor?() ??
|
||||
navigationController?.navigationBar.standardAppearance.backgroundColor ??
|
||||
statusBarView?.backgroundColor
|
||||
|
||||
let style = viewController?.defaultStatusBarStyle?() ??
|
||||
getStatusBarStyle(for: backgroundColor)
|
||||
|
||||
setStatusBarBackgroundColor(backgroundColor, style: style)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -44,6 +44,9 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) {
|
||||
// Reference to the top alert view
|
||||
@property (nullable, weak, nonatomic) MVMCoreUITopAlertView *topAlertView;
|
||||
|
||||
// Reference to the status bar view
|
||||
@property (nullable, weak, nonatomic) UIView *statusBarView;
|
||||
|
||||
// References to the current navigation item settings.
|
||||
@property (nonatomic, readonly) BOOL leftPanelIsAccessible;
|
||||
@property (nonatomic, readonly) BOOL rightPanelIsAccessible;
|
||||
@ -122,10 +125,6 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) {
|
||||
+ (CGFloat)getApplicationViewWidth;
|
||||
+ (CGFloat)getApplicationViewMaxSize;
|
||||
|
||||
// return subviewcontrollers' prefer status bar style
|
||||
- (UIStatusBarStyle)getDefaultStatusBarStyle;
|
||||
- (nullable UIColor *)getDefaultStatusBarBackgroundColor;
|
||||
|
||||
/// Returns true if a panel is showing.
|
||||
- (BOOL)isAPanelShowing;
|
||||
|
||||
@ -166,4 +165,15 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) {
|
||||
/// Updates if the tab bar is showing or not.
|
||||
- (void)updateTabBarShowing:(BOOL)showing;
|
||||
|
||||
#pragma mark - Status Bar
|
||||
|
||||
/// Updates the status bar with the given style and background color
|
||||
- (void)setStatusBarBackgroundColor:(nullable UIColor *)backgroundColor style:(UIStatusBarStyle)style;
|
||||
|
||||
/// Shows the view under the status bar.
|
||||
- (void)expandStatusBarView;
|
||||
|
||||
/// Hides the view under the status bar.
|
||||
- (void)collapseStatusBarView;
|
||||
|
||||
@end
|
||||
|
||||
@ -63,6 +63,10 @@ typedef NS_OPTIONS(NSInteger, MFExtendedDrawer) {
|
||||
@property (weak, nonatomic, readwrite) UIViewController *navigationItemViewController;
|
||||
@property (strong, nonatomic) NSNumber *transitionWidth;
|
||||
|
||||
@property (nonatomic) UIStatusBarStyle statusBarStyle;
|
||||
@property (strong, nonatomic) NSLayoutConstraint *statusBarHeightConstraint;
|
||||
@property (strong, nonatomic) NSLayoutConstraint *statusBarBottomConstraint;
|
||||
|
||||
// Dismisses any panel
|
||||
- (void)dismissPanels:(id)sender;
|
||||
|
||||
@ -841,6 +845,38 @@ CGFloat const PanelAnimationDuration = 0.2;
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Status Bar
|
||||
|
||||
- (void)setStatusBarBackgroundColor:(UIColor *)backgroundColor style:(UIStatusBarStyle)style {
|
||||
self.statusBarView.backgroundColor = backgroundColor;
|
||||
self.statusBarStyle = style;
|
||||
|
||||
// Triggers preferredStatusBarStyle
|
||||
[self.parentViewController setNeedsStatusBarAppearanceUpdate];
|
||||
}
|
||||
|
||||
- (UIStatusBarStyle)preferredStatusBarStyle {
|
||||
return self.statusBarStyle;
|
||||
}
|
||||
|
||||
- (void)expandStatusBarView {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
weakSelf.statusBarBottomConstraint.active = YES;
|
||||
weakSelf.statusBarHeightConstraint.active = NO;
|
||||
[weakSelf.view layoutIfNeeded];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)collapseStatusBarView {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
weakSelf.statusBarBottomConstraint.active = NO;
|
||||
weakSelf.statusBarHeightConstraint.active = YES;
|
||||
[weakSelf.view layoutIfNeeded];
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - View Cyle
|
||||
|
||||
- (void)loadView {
|
||||
@ -849,6 +885,17 @@ CGFloat const PanelAnimationDuration = 0.2;
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
self.view = view;
|
||||
|
||||
// Status bar
|
||||
UIView *statusBarView = [MVMCoreUICommonViewsUtility commonView];
|
||||
statusBarView.backgroundColor = [UIColor whiteColor];
|
||||
[self.view addSubview:statusBarView];
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[statusBarView]-0-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(statusBarView)]];
|
||||
id topGuide = view.safeAreaLayoutGuide;
|
||||
self.statusBarBottomConstraint = [NSLayoutConstraint constraintWithItem:statusBarView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:topGuide attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
|
||||
self.statusBarBottomConstraint.active = YES;
|
||||
self.statusBarHeightConstraint = [statusBarView.heightAnchor constraintEqualToConstant:0];
|
||||
self.statusBarView = statusBarView;
|
||||
|
||||
// Top Alert
|
||||
MVMCoreUITopAlertView *topAlertView = nil;
|
||||
if ([[CoreUIObject sharedInstance].globalTopAlertDelegate respondsToSelector:@selector(getTopAlertView)]) {
|
||||
@ -894,9 +941,9 @@ CGFloat const PanelAnimationDuration = 0.2;
|
||||
self.bottomProgressBarHeightConstraint = bottomProgressHeight;
|
||||
|
||||
if (topAlertView) {
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[topAlertView]-0-[mainView]-0-[progressView]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(topAlertView, mainView, progressView)]];
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[statusBarView]-0-[topAlertView]-0-[mainView]-0-[progressView]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(statusBarView,topAlertView, mainView, progressView)]];
|
||||
} else {
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[mainView]-0-[progressView]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(mainView, progressView)]];
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[statusBarView]-0-[mainView]-0-[progressView]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(statusBarView,mainView, progressView)]];
|
||||
}
|
||||
|
||||
// Add tabbar if we have it.
|
||||
@ -924,7 +971,6 @@ CGFloat const PanelAnimationDuration = 0.2;
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
[self.topAlertView pinATopViewController:self];
|
||||
|
||||
// Creates the back button
|
||||
self.backButton = [[UIBarButtonItem alloc] initWithImage:[self imageForBackButton] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)];
|
||||
@ -1008,36 +1054,6 @@ CGFloat const PanelAnimationDuration = 0.2;
|
||||
}
|
||||
}
|
||||
|
||||
- (UIStatusBarStyle)preferredStatusBarStyle {
|
||||
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 <MVMCoreUIDetailViewProtocol> *)viewController) defaultStatusBarStyle]) {
|
||||
return [((UIViewController <MVMCoreUIDetailViewProtocol> *)viewController) defaultStatusBarStyle];
|
||||
}
|
||||
return UIStatusBarStyleDefault;
|
||||
}
|
||||
|
||||
- (UIColor *)getDefaultStatusBarBackgroundColor {
|
||||
UIViewController *viewController = [self getCurrentDetailViewController];
|
||||
if ([viewController conformsToProtocol:@protocol(MVMCoreUIDetailViewProtocol)]
|
||||
&& [viewController respondsToSelector:@selector(defaultStatusBarBackgroundColor)]
|
||||
&& [((UIViewController <MVMCoreUIDetailViewProtocol> *)viewController) defaultStatusBarBackgroundColor]) {
|
||||
return [((UIViewController <MVMCoreUIDetailViewProtocol> *)viewController) defaultStatusBarBackgroundColor];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)isAPanelShowing {
|
||||
return fabs(self.mainViewLeading.constant) > 1;
|
||||
}
|
||||
|
||||
@ -13,16 +13,19 @@
|
||||
|
||||
@optional
|
||||
|
||||
// Show based on the object
|
||||
/// Show based on the object
|
||||
- (void)showWithTopAlertObject:(nullable MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nonnull id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate completionHandler:(void (^ __nullable)(BOOL finished))completionHandler;
|
||||
|
||||
// Hides
|
||||
/// Removes the notification
|
||||
- (void)hideAlertView:(BOOL)forceful completionHandler:(void (^ __nullable)(BOOL finished))completionHandler;
|
||||
|
||||
// Collapses the notification if it has a short top message. Otherwise removes notification.
|
||||
/// Collapses the notification if it has a short top message. Otherwise removes notification.
|
||||
- (void)collapseNotification;
|
||||
|
||||
/// Updates the existing top alert with the new object
|
||||
- (void)updateTopAlertWith:(nullable MVMCoreTopAlertObject *)topAlertObject;
|
||||
|
||||
/// Returns if the top alert is currently utilizing the status bar.
|
||||
- (BOOL)overridingStatusBar;
|
||||
|
||||
@end
|
||||
|
||||
@ -109,7 +109,7 @@ public extension MVMCoreUITopAlertView {
|
||||
// Update status bar.
|
||||
guard let statusBarDelegate = molecule as? StatusBarUI else { return }
|
||||
let statusBarUI = statusBarDelegate.getStatusBarUI()
|
||||
self.setStatusBarColor(statusBarUI.color, statusBarStyle: statusBarUI.style)
|
||||
MVMCoreUISplitViewController.main()?.setStatusBarBackgroundColor(statusBarUI.color, style: statusBarUI.style)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -19,8 +19,6 @@
|
||||
|
||||
@interface MVMCoreUITopAlertView : UIView <MVMCoreViewProtocol, MVMCoreTopAlertViewProtocol, MVMCoreLoadDelegateProtocol, MVMCoreActionDelegateProtocol, MVMCorePresentationDelegateProtocol, ButtonDelegateProtocol>
|
||||
|
||||
@property (nonatomic, readonly) UIStatusBarStyle statusBarStyle;
|
||||
|
||||
// Delegate for the top alert view
|
||||
@property (nonatomic, nullable, weak) id <MVMCoreTopAlertAnimationDelegateProtocol> animationDelegate;
|
||||
|
||||
@ -36,16 +34,6 @@
|
||||
// Returns a TopAlertView with the mvm styling. Also sets the property in the session.
|
||||
+ (nullable instancetype)setupTopAlertView;
|
||||
|
||||
// Pins the status bar view at the top of the passed in view controller.
|
||||
- (void)pinATopViewController:(nonnull UIViewController *)viewController;
|
||||
|
||||
// For controlling the status bar view
|
||||
- (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 UIView *)topAlertViewForTopAlertObject:(nullable MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nonnull id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate statusBarColor:(UIColor *_Nullable *_Nullable)statusBarColor statusBarStyle:(UIStatusBarStyle *_Nullable)statusBarStyle;
|
||||
|
||||
@ -55,7 +43,4 @@
|
||||
/// Get the content color based on the type
|
||||
- (nonnull UIColor *)getContentColorForType:(nullable NSString *)type;
|
||||
|
||||
// Set the status bar color. Used for updating the status bar when the view changes.
|
||||
- (void)setStatusBarColor:(nullable UIColor *)statusBarColor statusBarStyle:(UIStatusBarStyle)style;
|
||||
|
||||
@end
|
||||
|
||||
@ -33,12 +33,6 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
|
||||
|
||||
@interface MVMCoreUITopAlertView ()
|
||||
|
||||
@property (nonatomic, readwrite) UIStatusBarStyle statusBarStyle;
|
||||
@property (weak, nonatomic) UIView *statusBarView;
|
||||
@property (strong, nonatomic) NSLayoutConstraint *statusBarHeightConstraint;
|
||||
@property (strong, nonatomic) NSLayoutConstraint *statusBarBottomConstraint;
|
||||
|
||||
@property (weak, nonatomic) UIView *alertView;
|
||||
@property (weak, nullable, nonatomic, readwrite) UIView *currentAlert;
|
||||
@property (strong, nonatomic) NSLayoutConstraint *height;
|
||||
|
||||
@ -48,6 +42,8 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
|
||||
/// Used if we delayed the collapse due to accessibility.
|
||||
@property (copy, nonatomic) void (^ hideCompletionHandler)(BOOL finished);
|
||||
|
||||
@property (nonatomic) BOOL currentAlertOverridingStatusBar;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MVMCoreUITopAlertView
|
||||
@ -88,34 +84,11 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
|
||||
}
|
||||
|
||||
- (void)setupView {
|
||||
if (!self.statusBarView) {
|
||||
self.clipsToBounds = YES;
|
||||
|
||||
UIView *statusBarView = [MVMCoreUICommonViewsUtility commonView];
|
||||
UIView *alertView = [MVMCoreUICommonViewsUtility commonView];
|
||||
[self addSubview:alertView];
|
||||
[self addSubview:statusBarView];
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[statusBarView]-0-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(statusBarView)]];
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[alertView]-0-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(alertView)]];
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[statusBarView]-0-[alertView]-0-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(statusBarView,alertView)]];
|
||||
self.statusBarHeightConstraint = [statusBarView.heightAnchor constraintEqualToConstant:0];
|
||||
self.statusBarHeightConstraint.active = YES;
|
||||
self.height = [alertView.heightAnchor constraintEqualToConstant:0];
|
||||
self.height.active = YES;
|
||||
self.alertView = alertView;
|
||||
self.statusBarView = statusBarView;
|
||||
|
||||
[self setStatusBarColor:[UIColor whiteColor] statusBarStyle:UIStatusBarStyleDefault];
|
||||
|
||||
[self registerWithNotificationCenter];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)pinATopViewController:(UIViewController *)viewController {
|
||||
self.statusBarHeightConstraint.active = NO;
|
||||
id topGuide = viewController.view.safeAreaLayoutGuide;
|
||||
self.statusBarBottomConstraint = [NSLayoutConstraint constraintWithItem:self.statusBarView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:topGuide attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
|
||||
self.statusBarBottomConstraint.active = YES;
|
||||
if (self.height) { return; }
|
||||
self.clipsToBounds = YES;
|
||||
self.height = [self.heightAnchor constraintEqualToConstant:0];
|
||||
self.height.active = YES;
|
||||
[self registerWithNotificationCenter];
|
||||
}
|
||||
|
||||
- (void)updateView:(CGFloat)size {
|
||||
@ -159,38 +132,6 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showWithTopAlertObject:(nullable MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nonnull id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate completionHandler:(void (^ __nullable)(BOOL finished))completionHandler {
|
||||
|
||||
self.animationDelegate = animationDelegate;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
self.topAlertObject = topAlertObject;
|
||||
self.topAlertClearspotView = nil;
|
||||
|
||||
UIColor *statusBarColor = nil;
|
||||
UIStatusBarStyle statusBarStyle = UIStatusBarStyleDefault;
|
||||
UIView *view = [self topAlertViewForTopAlertObject:topAlertObject animationDelegate:animationDelegate statusBarColor:&statusBarColor statusBarStyle:&statusBarStyle];
|
||||
if ([view conformsToProtocol:@protocol(MVMCoreViewProtocol)]) {
|
||||
[((UIView <MVMCoreViewProtocol>*)view) updateView:CGRectGetWidth(self.bounds)];
|
||||
}
|
||||
if (!statusBarColor) {
|
||||
statusBarColor = [UIColor whiteColor];
|
||||
}
|
||||
[self setStatusBarColor:statusBarColor statusBarStyle:statusBarStyle];
|
||||
[self showAlertView:view topAlertObject:topAlertObject completionHandler:completionHandler];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)updateTopAlertWith:(MVMCoreTopAlertObject *)topAlertObject {
|
||||
[self updateMoleculeWith:topAlertObject];
|
||||
}
|
||||
|
||||
- (void)setStatusBarColor:(nullable UIColor *)statusBarColor statusBarStyle:(UIStatusBarStyle)style {
|
||||
self.statusBarView.backgroundColor = statusBarColor;
|
||||
self.statusBarStyle = style;
|
||||
[[MVMCoreUISession sharedGlobal].splitViewController.parentViewController setNeedsStatusBarAppearanceUpdate];
|
||||
}
|
||||
|
||||
- (void)updateAccessibilityForTopAlert:(nullable UIView *)view {
|
||||
// Update accessibility with top alert
|
||||
if ([view isKindOfClass:[MVMCoreUITopAlertBaseView class]]) {
|
||||
@ -212,7 +153,7 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
|
||||
if (weakSelf.currentAlert.superview) {
|
||||
[weakSelf.currentAlert removeFromSuperview];
|
||||
}
|
||||
[weakSelf.alertView addSubview:view];
|
||||
[weakSelf addSubview:view];
|
||||
[NSLayoutConstraint constraintPinSubviewToSuperview:view];
|
||||
weakSelf.currentAlert = view;
|
||||
|
||||
@ -241,6 +182,40 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
|
||||
[[MVMCoreNavigationHandler sharedNavigationHandler] addNavigationOperation:operation];
|
||||
}
|
||||
|
||||
|
||||
/// If the voice over user leaves top alert focus, hide.
|
||||
- (void)accessibilityFocusChanged:(NSNotification *)notification {
|
||||
if (notification.userInfo[UIAccessibilityFocusedElementKey] && ![MVMCoreUIUtility viewContainsAccessiblityFocus:self]) {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIAccessibilityElementFocusedNotification object:nil];
|
||||
[self hideAlertView:YES completionHandler:self.hideCompletionHandler];
|
||||
self.hideCompletionHandler = nil;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - MVMCoreTopAlertViewProtocol
|
||||
|
||||
- (void)showWithTopAlertObject:(nullable MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nonnull id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate completionHandler:(void (^ __nullable)(BOOL finished))completionHandler {
|
||||
|
||||
self.animationDelegate = animationDelegate;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
self.topAlertObject = topAlertObject;
|
||||
self.topAlertClearspotView = nil;
|
||||
|
||||
UIColor *statusBarColor = nil;
|
||||
UIStatusBarStyle statusBarStyle = UIStatusBarStyleDefault;
|
||||
UIView *view = [self topAlertViewForTopAlertObject:topAlertObject animationDelegate:animationDelegate statusBarColor:&statusBarColor statusBarStyle:&statusBarStyle];
|
||||
if ([view conformsToProtocol:@protocol(MVMCoreViewProtocol)]) {
|
||||
[((UIView <MVMCoreViewProtocol>*)view) updateView:CGRectGetWidth(self.bounds)];
|
||||
}
|
||||
if (statusBarColor) {
|
||||
self.currentAlertOverridingStatusBar = YES;
|
||||
[[MVMCoreUISplitViewController mainSplitViewController] setStatusBarBackgroundColor:statusBarColor style:statusBarStyle];
|
||||
}
|
||||
[self showAlertView:view topAlertObject:topAlertObject completionHandler:completionHandler];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)hideAlertView:(BOOL)forceful completionHandler:(void (^ __nullable)(BOOL finished))completionHandler {
|
||||
// If accessible and focused, do not collapse until unfocused.
|
||||
if (!forceful && [MVMCoreUIUtility viewContainsAccessiblityFocus:self]) {
|
||||
@ -278,9 +253,12 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
|
||||
completionHandler(finished);
|
||||
}
|
||||
weakSelf.topAlertObject = nil;
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
[weakSelf setStatusBarColor:[UIColor whiteColor] statusBarStyle:UIStatusBarStyleDefault];
|
||||
}];
|
||||
if (weakSelf.currentAlertOverridingStatusBar) {
|
||||
weakSelf.currentAlertOverridingStatusBar = NO;
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
[[MVMCoreUISplitViewController mainSplitViewController] setStatusBarForCurrentViewController];
|
||||
}];
|
||||
}
|
||||
}];
|
||||
}];
|
||||
}];
|
||||
@ -288,6 +266,11 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
|
||||
[[MVMCoreNavigationHandler sharedNavigationHandler] addNavigationOperation:operation];
|
||||
}
|
||||
|
||||
|
||||
- (void)updateTopAlertWith:(MVMCoreTopAlertObject *)topAlertObject {
|
||||
[self updateMoleculeWith:topAlertObject];
|
||||
}
|
||||
|
||||
- (void)collapseNotification {
|
||||
if (self.currentAlert) {
|
||||
if ([self.currentAlert isKindOfClass:[MVMCoreUITopAlertExpandableView class]] && ((MVMCoreUITopAlertExpandableView *)self.currentAlert).shortView.label.text.length > 0) {
|
||||
@ -301,45 +284,8 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
|
||||
}
|
||||
}
|
||||
|
||||
- (void)expandStatusBarView {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
weakSelf.statusBarBottomConstraint.active = YES;
|
||||
weakSelf.statusBarHeightConstraint.active = NO;
|
||||
[weakSelf.superview layoutIfNeeded];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)collapseStatusBarView {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
weakSelf.statusBarBottomConstraint.active = NO;
|
||||
weakSelf.statusBarHeightConstraint.active = YES;
|
||||
[weakSelf.superview layoutIfNeeded];
|
||||
}];
|
||||
}
|
||||
|
||||
- (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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If the voice over user leaves top alert focus, hide.
|
||||
- (void)accessibilityFocusChanged:(NSNotification *)notification {
|
||||
if (notification.userInfo[UIAccessibilityFocusedElementKey] && ![MVMCoreUIUtility viewContainsAccessiblityFocus:self]) {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIAccessibilityElementFocusedNotification object:nil];
|
||||
[self hideAlertView:YES completionHandler:self.hideCompletionHandler];
|
||||
self.hideCompletionHandler = nil;
|
||||
}
|
||||
- (BOOL)overridingStatusBar {
|
||||
return self.currentAlertOverridingStatusBar;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user