diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index b61c3aa1..f9a0cdb3 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -301,6 +301,8 @@ D2092357244FA1EF0044AD09 /* ThreeLayerModelBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2092356244FA1EF0044AD09 /* ThreeLayerModelBase.swift */; }; D20923592450ECE00044AD09 /* TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20923582450ECE00044AD09 /* TableView.swift */; }; D20A9A5E2243D3E300ADE781 /* TwoButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */; }; + D20C7009250BF99B0095B21C /* TopNotificationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20C7008250BF99B0095B21C /* TopNotificationModel.swift */; }; + D20C700B250BFDE40095B21C /* MVMCoreUITopAlertView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20C700A250BFDE40095B21C /* MVMCoreUITopAlertView+Extension.swift */; }; D20FB165241A5D75004AFC3A /* NavigationItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20FB164241A5D75004AFC3A /* NavigationItemModel.swift */; }; D213347723843825008E41B3 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = D213347623843825008E41B3 /* Line.swift */; }; D21B7F602437C5BC00051ABF /* MoleculeStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D21B7F5E2437C5BC00051ABF /* MoleculeStackView.swift */; }; @@ -782,6 +784,8 @@ D2092356244FA1EF0044AD09 /* ThreeLayerModelBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerModelBase.swift; sourceTree = ""; }; D20923582450ECE00044AD09 /* TableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableView.swift; sourceTree = ""; }; D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoButtonView.swift; sourceTree = ""; }; + D20C7008250BF99B0095B21C /* TopNotificationModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopNotificationModel.swift; sourceTree = ""; }; + D20C700A250BFDE40095B21C /* MVMCoreUITopAlertView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreUITopAlertView+Extension.swift"; sourceTree = ""; }; D20FB164241A5D75004AFC3A /* NavigationItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationItemModel.swift; sourceTree = ""; }; D213347623843825008E41B3 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = ""; }; D21B7F5E2437C5BC00051ABF /* MoleculeStackView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeStackView.swift; sourceTree = ""; }; @@ -1258,6 +1262,14 @@ path = FourColumn; sourceTree = ""; }; + D20C7007250BF9440095B21C /* Atomic */ = { + isa = PBXGroup; + children = ( + D20C7008250BF99B0095B21C /* TopNotificationModel.swift */, + ); + path = Atomic; + sourceTree = ""; + }; D20FFFB42451E32100A31DA2 /* Device */ = { isa = PBXGroup; children = ( @@ -1757,6 +1769,8 @@ D29DF11E21E6851E003B2FB9 /* TopAlert */ = { isa = PBXGroup; children = ( + D20C7007250BF9440095B21C /* Atomic */, + D20C700A250BFDE40095B21C /* MVMCoreUITopAlertView+Extension.swift */, D29DF12021E6851E003B2FB9 /* MVMCoreUITopAlertView.h */, D29DF12421E6851E003B2FB9 /* MVMCoreUITopAlertView.m */, D29DF12321E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.h */, @@ -2234,6 +2248,7 @@ D253BB8A24574CC5002DE544 /* StackModel.swift in Sources */, 011D95A924057AC7000E3791 /* FormGroupWatcherFieldProtocol.swift in Sources */, BB2BF0EA2452A9BB001D0FC2 /* ListDeviceComplexButtonSmall.swift in Sources */, + D20C700B250BFDE40095B21C /* MVMCoreUITopAlertView+Extension.swift in Sources */, D236E5B4241FEB1000C38625 /* ListTwoColumnPriceDescription.swift in Sources */, 0AA33B3A2398524F0067DD0F /* Toggle.swift in Sources */, D29DF12F21E6851E003B2FB9 /* MVMCoreUITopAlertMainView.m in Sources */, @@ -2463,6 +2478,7 @@ D253BB9E2458751F002DE544 /* BGImageMoleculeModel.swift in Sources */, AA104AC924472DC7004D2810 /* HeadersH1ButtonModel.swift in Sources */, 0ABD1371237DB0450081388D /* ItemDropdownEntryField.swift in Sources */, + D20C7009250BF99B0095B21C /* TopNotificationModel.swift in Sources */, 8D24041123E7FB9E009E23BE /* ListLeftVariableIconWithRightCaret.swift in Sources */, BB2FB3BD247E7EF200DF73CD /* Tags.swift in Sources */, AA104ADC244734EA004D2810 /* HeadersH1LandingPageHeaderModel.swift in Sources */, diff --git a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift index a08347c7..a598b113 100644 --- a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift +++ b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift @@ -232,6 +232,10 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: LockUpsPlanNames.self, viewModelClass: LockUpsPlanNamesModel.self) MoleculeObjectMapping.shared()?.register(viewClass: LockupsPlanSMLXL.self, viewModelClass: LockupsPlanSMLXLModel.self) + // MARK: - Top Notifications + MoleculeObjectMapping.shared()?.register(viewClass: MVMCoreUITopAlertMainView.self, viewModelClass: NotificationModel.self) + MoleculeObjectMapping.shared()?.register(viewClass: MVMCoreUITopAlertExpandableView.self, viewModelClass: CollapsableNotificationModel.self) + // MARK:- Helper models try? ModelRegistry.register(RuleRequiredModel.self) try? ModelRegistry.register(RuleAnyRequiredModel.self) diff --git a/MVMCoreUI/TopAlert/Atomic/TopNotificationModel.swift b/MVMCoreUI/TopAlert/Atomic/TopNotificationModel.swift new file mode 100644 index 00000000..d6900c85 --- /dev/null +++ b/MVMCoreUI/TopAlert/Atomic/TopNotificationModel.swift @@ -0,0 +1,80 @@ +// +// TopNotification.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 9/11/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +open class TopNotificationModel: Codable { + public var type: String + public var priority = Operation.QueuePriority.normal + public var molecule: MoleculeModelProtocol + public var persistent = false + public var dismissTime = 5 + public var pages: [String]? + public var analyticsData: JSONValueDictionary? + + private enum CodingKeys: String, CodingKey { + case type + case priority + case molecule + case persistent + case dismissTime + case pages + case analyticsData + } + + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + + public init(with type: String, molecule: MoleculeModelProtocol, priority: Operation.QueuePriority = .normal, persistent: Bool = false, dismissTime: Int = 5, pages: [String]? = nil, analyticsData: JSONValueDictionary? = nil) { + self.type = type + self.molecule = molecule + self.priority = priority + self.persistent = persistent + self.dismissTime = dismissTime + self.pages = pages + self.analyticsData = analyticsData + } + + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + type = try typeContainer.decode(String.self, forKey: .type) + molecule = try typeContainer.decodeModel(codingKey: .molecule) + if let priorityPercent = try typeContainer.decodeIfPresent(Float.self, forKey: .priority) { + let scale = Operation.QueuePriority.veryHigh.rawValue - Operation.QueuePriority.veryLow.rawValue + let scaledPercent = (priorityPercent / 100.0) * Float(scale) + self.priority = Operation.QueuePriority(rawValue: Operation.QueuePriority.veryLow.rawValue + Int(scaledPercent)) ?? .normal + } + if let persistent = try typeContainer.decodeIfPresent(Bool.self, forKey: .persistent) { + self.persistent = persistent + } + if let dismissTime = try typeContainer.decodeIfPresent(Int.self, forKey: .dismissTime) { + self.dismissTime = dismissTime + } + pages = try typeContainer.decodeIfPresent([String].self, forKey: .pages) + analyticsData = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .analyticsData) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(type, forKey: .type) + try container.encodeModel(molecule, forKey: .molecule) + + let scale = Operation.QueuePriority.veryHigh.rawValue - Operation.QueuePriority.veryLow.rawValue + let priorityPercent = Int((Float(priority.rawValue - Operation.QueuePriority.veryLow.rawValue) / Float(scale)) * 100.0) + try container.encode(priorityPercent, forKey: .priority) + try container.encode(persistent, forKey: .persistent) + try container.encode(dismissTime, forKey: .dismissTime) + try container.encodeIfPresent(pages, forKey: .pages) + try container.encodeIfPresent(analyticsData, forKey: .analyticsData) + } +} diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m index 55841e3f..7f03fe25 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m @@ -76,6 +76,21 @@ return self; } +- (nonnull instancetype)initWithFrame:(CGRect)frame { + if (self = [super initWithFrame:frame]) { + self.translatesAutoresizingMaskIntoConstraints = NO; + self.clipsToBounds = YES; + _collapseAutomaticallyAfterExpanded = YES; + self.viewToLayout = MVMCoreUITopAlertView.sharedGlobal.superview; + self.expanded = NO; + [self setupTopMessage:nil]; + MVMCoreUITopAlertMainView *topAlertWithButton = [[MVMCoreUITopAlertMainView alloc] initWithFrame:frame]; + [self setupTopAlertWithButton:topAlertWithButton]; + } + return self; +} + + - (nullable instancetype)initWithTopAlertObject:(nonnull MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nullable id )animationDelegate viewToLayout:(nonnull UIView *)viewTolayout { if (self = [self init]) { self.animationDelegate = animationDelegate; diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.h b/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.h index 0f75ad9c..137ac168 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.h +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.h @@ -37,6 +37,9 @@ - (void)setupButtonWithActionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData; - (void)setupButtonWithButtonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler; +// Setters for close button. +- (void)setupCloseButton:(BOOL)closeButton animationDelegate:(nullable id )animationDelegate; + #pragma mark - legacy inits // Legacy init: inits with a label and button, no close button or icon. diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m index 23beeb64..6c1da1fd 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m @@ -60,6 +60,17 @@ return self; } +- (nonnull instancetype)initWithFrame:(CGRect)frame { + if (self = [super initWithFrame:frame]) { + self.translatesAutoresizingMaskIntoConstraints = NO; + self.clipsToBounds = YES; + self.height = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:96]; + self.height.active = YES; + [self setupViewWithLabelAndImage:nil topImage:nil]; + } + return self; +} + - (nullable instancetype)initWithTopAlertObject:(nonnull MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nullable id )animationDelegate { if (self = [self init]) { UIColor *contentColor = topAlertObject.textColor ?: [[MVMCoreUITopAlertView sharedGlobal] getContentColorForType:topAlertObject.type]; diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView+Extension.swift b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView+Extension.swift new file mode 100644 index 00000000..5b4cd3b7 --- /dev/null +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView+Extension.swift @@ -0,0 +1,252 @@ +// +// MVMCoreUITopAlertView+Extension.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 9/11/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +public extension MVMCoreTopAlertObject { + static func create(with model: TopNotificationModel) -> Self { + let object = self.init() + object.persistent = model.persistent + object.type = model.type + object.topAlertDismissTime = model.dismissTime + object.queuePriority = model.priority + object.useNewStyle = true + object.json = model.toJSON() + return object + } +} + +public extension MVMCoreAlertHandler { + + /// Decodes the top alert json to a model. + static func decode(json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) throws -> TopNotificationModel { + let data = try JSONSerialization.data(withJSONObject: json) + let decoder = JSONDecoder() + if let delegateObject = delegateObject { + try decoder.add(delegateObject: delegateObject) + } + return try decoder.decode(TopNotificationModel.self, from: data) + } + + /// Shows the top alert with the json payload. + func showTopAlert(with json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) { + do { + let model = try Self.decode(json: json, delegateObject: delegateObject) + showTopAlert(with: model, delegateObject: delegateObject) + } catch { + if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "\(self)") { + MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject) + } + } + } + + /// Shows the top alert with the model. + func showTopAlert(with model: TopNotificationModel, delegateObject: MVMCoreUIDelegateObject?) { + let object = MVMCoreTopAlertObject.create(with: model) + guard let pages = model.pages else { + showTopAlert(with: object) + return + } + guard let controller = MVMCoreUISplitViewController.main()?.getCurrentDetailViewController() as? MVMCoreViewControllerProtocol, + let pageType = controller.pageType, + pages.contains(pageType) else { + showTopAlert(with: object) + // add + return + } + showTopAlert(with: object) + } +} + +protocol StatusBarUI { + func getStatusBarUI() -> (color: UIColor, style: UIStatusBarStyle) +} + +public extension MVMCoreUITopAlertView { + + /// Registers with the notification center to know when json is updated. + @objc func registerWithNotificationCenter() { + NotificationCenter.default.addObserver(self, selector: #selector(responseJSONUpdated(notification:)), name: NSNotification.Name(rawValue: NotificationResponseLoaded), object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(viewControllerChanged(notification:)), name: NSNotification.Name(rawValue: MVMCoreNotificationViewControllerChanged), object: nil) + } + + /// Checks for new top alert json + @objc func responseJSONUpdated(notification: Notification) { + var jssoonnn = (notification.userInfo?[String(describing: MVMCoreLoadObject.self)] as? MVMCoreLoadObject)?.responseJSON + /*let molecule = CollapsableNotificationModel(with: LabelModel(text: "Top"), headline: LabelModel(text: "Headline")) + //let molecule = NotificationModel(with: LabelModel(text: "Hello")) + molecule.backgroundColor = Color(uiColor: .mvmRed) + molecule.button = ButtonModel(with: "Hi", action: ActionCancelModel()) + molecule.body = LabelModel(text: "Sup") + molecule.closeButton = NotificationXButtonModel() + let model = TopNotificationModel(with: "Testing", molecule: molecule) + model.persistent = false + model.dismissTime = 10 + model.pages = nil//["settingsLanding"] + jssoonnn?.updateValue(model.toJSON()!, forKey: "TopNotification")*/ + guard let json = jssoonnn?.optionalDictionaryForKey("TopNotification") else { return } + // TODO: Top alert view is current delegate. Should move to current view controller eventually? + let delegateObject = MVMCoreUIDelegateObject.create(withDelegateForAll: self) + MVMCoreAlertHandler.shared()?.showTopAlert(with: json, delegateObject: delegateObject) + } + + @objc func viewControllerChanged(notification: Notification) { + guard let controller = MVMCoreUISplitViewController.main()?.getCurrentDetailViewController() as? MVMCoreViewControllerProtocol else { return } + MVMCoreAlertHandler.shared()?.checkPagesDependency(for: controller.pageType) + } + + @objc func molecule(for topAlertObject: MVMCoreTopAlertObject, statusBarColor: AutoreleasingUnsafeMutablePointer?, statusBarStyle: UnsafeMutablePointer?) -> MVMCoreUITopAlertBaseView? { + do { + let delegateObject = MVMCoreUIDelegateObject.create(withDelegateForAll: self) + guard let json = topAlertObject.json else { return nil } + let model = try MVMCoreAlertHandler.decode(json: json, delegateObject: delegateObject) + guard let molecule = MoleculeObjectMapping.shared()?.createMolecule(model.molecule, delegateObject: delegateObject, additionalData: nil), + let view = molecule as? MVMCoreUITopAlertBaseView else { + throw ModelRegistry.Error.decoderOther(message: "Molecule not a top alert") + } + if let casteView = view as? StatusBarUI { + let statusBarUI = casteView.getStatusBarUI() + statusBarColor?.pointee = statusBarUI.color + statusBarStyle?.pointee = statusBarUI.style + } + return view + } catch { + if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "\(self)") { + MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject) + } + return nil + } + } + /* + /// Shows the top alert with the json payload. + func showTopAlert(with json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) { + /*do { + let model = try decode(json: json, delegateObject: delegateObject) + showTopAlert(with: model, delegateObject: delegateObject) + } catch { + if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "\(self)") { + MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject) + } + }*/ + } + + /// Shows the top alert with the model. + func showTopAlert(with model: TopNotificationModel, delegateObject: MVMCoreUIDelegateObject?) { + if let molecule = MoleculeObjectMapping.shared()?.createMolecule(model.molecule, delegateObject: delegateObject, additionalData: nil) { + + } + }*/ +} + +public class NotificationXButtonModel: Codable { + public var color: Color? + public var action: ActionModelProtocol? + + private enum CodingKeys: String, CodingKey { + case color + case action + } + + public init() { + } + + public required init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) + action = try typeContainer.decodeModelIfPresent(codingKey: .action) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(color, forKey: .color) + try container.encodeModelIfPresent(action, forKey: .action) + } +} + +public class NotificationModel: MoleculeModelProtocol { + public static var identifier: String = "notification" + public var moleculeName: String = NotificationModel.identifier + public var backgroundColor: Color? + public var headline: LabelModel + public var body: LabelModel? + public var button: ButtonModel? + public var closeButton: NotificationXButtonModel? + + init(with headline: LabelModel) { + self.headline = headline + } +} + +extension MVMCoreUITopAlertMainView: MoleculeViewProtocol { + public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + guard let model = model as? NotificationModel else { return } + backgroundColor = model.backgroundColor?.uiColor ?? .mvmGreen + var actionMap = model.button?.action.toJSON() + if let title = model.button?.title { + actionMap?.updateValue(title, forKey: KeyTitle) + } + setupCloseButton(model.closeButton != nil, animationDelegate: MVMCoreUITopAlertView.sharedGlobal()?.animationDelegate) + setup(withMessage: model.headline.text, subMessage: model.body?.text, color: model.headline.textColor?.uiColor ?? .white, actionMap: actionMap, additionalData: nil) + } +} + +public class CollapsableNotificationModel: MoleculeModelProtocol { + public static var identifier: String = "collapsableNotification" + public var moleculeName: String = CollapsableNotificationModel.identifier + public var backgroundColor: Color? + public var topLabel: LabelModel + //public var topAction: ActionModelProtocol? + public var headline: LabelModel + public var body: LabelModel? + public var button: ButtonModel? + public var closeButton: NotificationXButtonModel? + public var alwaysShowCollapsedLabel = false + public var collapseTime: Int = 5 + public var initiallyCollapsed = false + //public var pages: [NSString]? + + init(with topLabel: LabelModel, headline: LabelModel) { + self.topLabel = topLabel + self.headline = headline + } +} + +extension MVMCoreUITopAlertExpandableView: MoleculeViewProtocol { + public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + guard let model = model as? CollapsableNotificationModel else { return } + backgroundColor = model.backgroundColor?.uiColor ?? .mvmGreen + collapseTime = model.collapseTime + onlyShowTopMessageWhenCollapsed = !model.alwaysShowCollapsedLabel + + var actionMap = model.button?.action.toJSON() + if let title = model.button?.title { + actionMap?.updateValue(title, forKey: KeyTitle) + } + buttonView?.setupCloseButton(model.closeButton != nil, animationDelegate: MVMCoreUITopAlertView.sharedGlobal()?.animationDelegate) + setTopMessage(model.topLabel.text, message: model.headline.text, subMessage: model.body?.text, contentColor: model.headline.textColor?.uiColor ?? .white, actionMap: actionMap, additionalData: nil) + expand(false) + //[MVMCoreUITopAlertBaseView addActionToButton:survivalMode.shortView.button actionMap:topAlertObject.buttonMap additionalData:topAlertObject.additionalData]; + // survivalMode.shortView.label.accessibilityTraits = UIAccessibilityTraitButton; + } +} + +extension MVMCoreUITopAlertExpandableView: StatusBarUI { + func getStatusBarUI() -> (color: UIColor, style: UIStatusBarStyle) { + if shortView?.label?.text?.count ?? 0 > 0 { + let color = backgroundColor ?? UIColor.mvmGreen + var greyScale: CGFloat = 0 + if shortView?.label?.textColor.getWhite(&greyScale, alpha: nil) ?? false { + return (color, greyScale > 0.5 ? .lightContent : .default) + } else { + return (color, .default) + } + } else { + return (.white, .default) + } + } +} diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m index 7efa15a3..903a24d3 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m @@ -16,6 +16,7 @@ #import "NSLayoutConstraint+MFConvenience.h" #import "MVMCoreUISession.h" #import "MVMCoreUIUtility.h" +#import @import MVMCore.MVMCoreTopAlertObject; @import MVMCore.MVMCoreLoadHandler; @import MVMCore.MVMCoreNavigationHandler; @@ -105,6 +106,8 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed."; self.statusBarView = statusBarView; [self setStatusBarColor:[UIColor whiteColor] statusBarStyle:UIStatusBarStyleDefault]; + + [self registerWithNotificationCenter]; } } @@ -122,18 +125,22 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed."; } - (nonnull MVMCoreUITopAlertBaseView *)topAlertViewForTopAlertObject:(nullable MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nonnull id )animationDelegate statusBarColor:(UIColor *_Nullable *_Nullable)statusBarColor statusBarStyle:(UIStatusBarStyle *_Nullable)statusBarStyle { - MVMCoreUITopAlertExpandableView *view = [[MVMCoreUITopAlertExpandableView alloc] initWithTopAlertObject:topAlertObject animationDelegate:animationDelegate viewToLayout:self.superview]; - if (statusBarColor && view.shortView.label.text) { - *statusBarColor = view.backgroundColor; - - if (statusBarStyle) { - CGFloat greyScale = 0; - if ([view.shortView.label.textColor getWhite:&greyScale alpha:nil]) { - *statusBarStyle = greyScale > 0.5 ? UIStatusBarStyleLightContent : UIStatusBarStyleDefault; + if (topAlertObject.json) { + return [self moleculeFor:topAlertObject statusBarColor:statusBarColor statusBarStyle:statusBarStyle]; + } else { + MVMCoreUITopAlertExpandableView *view = [[MVMCoreUITopAlertExpandableView alloc] initWithTopAlertObject:topAlertObject animationDelegate:animationDelegate viewToLayout:self.superview]; + if (statusBarColor && view.shortView.label.text) { + *statusBarColor = view.backgroundColor; + + if (statusBarStyle) { + CGFloat greyScale = 0; + if ([view.shortView.label.textColor getWhite:&greyScale alpha:nil]) { + *statusBarStyle = greyScale > 0.5 ? UIStatusBarStyleLightContent : UIStatusBarStyleDefault; + } } } + return view; } - return view; } - (nonnull UIColor *)getBackgroundColorForType:(nullable NSString *)type {