Merge branch 'develop' into feature/star
This commit is contained in:
commit
efd286b279
@ -11,11 +11,11 @@ import UIKit
|
|||||||
open class MoleculeContainer: Container {
|
open class MoleculeContainer: Container {
|
||||||
|
|
||||||
/// Can be overriden to change how the molecule is added to the hierarchy.
|
/// Can be overriden to change how the molecule is added to the hierarchy.
|
||||||
public func addMolecule(_ molecule: UIView) {
|
open func addMolecule(_ molecule: UIView) {
|
||||||
addAndContain(molecule)
|
addAndContain(molecule)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
if let casteModel = model as? MoleculeContainerModelProtocol {
|
if let casteModel = model as? MoleculeContainerModelProtocol {
|
||||||
if view != nil {
|
if view != nil {
|
||||||
(view as? MoleculeViewProtocol)?.set(with: casteModel.molecule, delegateObject, additionalData)
|
(view as? MoleculeViewProtocol)?.set(with: casteModel.molecule, delegateObject, additionalData)
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
open class MoleculeContainerModel: ContainerModel, MoleculeContainerModelProtocol, MoleculeModelProtocol {
|
open class MoleculeContainerModel: ContainerModel, MoleculeContainerModelProtocol, MoleculeModelProtocol {
|
||||||
public class var identifier: String {
|
open class var identifier: String {
|
||||||
return "container"
|
return "container"
|
||||||
}
|
}
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
@ -41,7 +41,7 @@ open class MoleculeContainerModel: ContainerModel, MoleculeContainerModelProtoco
|
|||||||
try super.init(from: decoder)
|
try super.init(from: decoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func encode(to encoder: Encoder) throws {
|
open override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public class CollapsableNotificationModel: NotificationModel {
|
open class CollapsableNotificationModel: NotificationModel {
|
||||||
public class override var identifier: String {
|
public class override var identifier: String {
|
||||||
return "collapsableNotification"
|
return "collapsableNotification"
|
||||||
}
|
}
|
||||||
@ -19,12 +19,12 @@ public class CollapsableNotificationModel: NotificationModel {
|
|||||||
public var initiallyCollapsed = false
|
public var initiallyCollapsed = false
|
||||||
public var pages: [String]?
|
public var pages: [String]?
|
||||||
|
|
||||||
init(with topLabel: LabelModel, headline: LabelModel) {
|
public init(with topLabel: LabelModel, headline: LabelModel) {
|
||||||
self.topLabel = topLabel
|
self.topLabel = topLabel
|
||||||
super.init(with: headline)
|
super.init(with: headline)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func setDefault() {
|
open override func setDefault() {
|
||||||
super.setDefault()
|
super.setDefault()
|
||||||
if topLabel.textColor == nil {
|
if topLabel.textColor == nil {
|
||||||
topLabel.textColor = Color(uiColor: .white)
|
topLabel.textColor = Color(uiColor: .white)
|
||||||
@ -61,7 +61,7 @@ public class CollapsableNotificationModel: NotificationModel {
|
|||||||
try super.init(from: decoder)
|
try super.init(from: decoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func encode(to encoder: Encoder) throws {
|
open override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public class NotificationModel: MoleculeModelProtocol {
|
open class NotificationModel: MoleculeModelProtocol {
|
||||||
public class var identifier: String {
|
public class var identifier: String {
|
||||||
return "notification"
|
return "notification"
|
||||||
}
|
}
|
||||||
@ -18,11 +18,11 @@ public class NotificationModel: MoleculeModelProtocol {
|
|||||||
public var button: ButtonModel?
|
public var button: ButtonModel?
|
||||||
public var closeButton: NotificationXButtonModel?
|
public var closeButton: NotificationXButtonModel?
|
||||||
|
|
||||||
init(with headline: LabelModel) {
|
public init(with headline: LabelModel) {
|
||||||
self.headline = headline
|
self.headline = headline
|
||||||
}
|
}
|
||||||
|
|
||||||
func setDefault() {
|
open func setDefault() {
|
||||||
if backgroundColor == nil {
|
if backgroundColor == nil {
|
||||||
backgroundColor = Color(uiColor: .mvmGreen())
|
backgroundColor = Color(uiColor: .mvmGreen())
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ public class NotificationModel: MoleculeModelProtocol {
|
|||||||
setDefault()
|
setDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
open func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
- (BOOL)panelAvailable;
|
- (BOOL)panelAvailable;
|
||||||
|
|
||||||
// Notified when it is appearing and disappearing. Called by the container.
|
// Notified when it is appearing and disappearing. Called by the container.
|
||||||
- (void)willOpenWithActionInformation:(nullable NSDictionary *)actionInformation;
|
- (void)willOpenWithActionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData;
|
||||||
- (void)willAppear:(BOOL)animated;
|
- (void)willAppear:(BOOL)animated;
|
||||||
- (void)didAppear:(BOOL)animated;
|
- (void)didAppear:(BOOL)animated;
|
||||||
- (void)willDisappear:(BOOL)animated;
|
- (void)willDisappear:(BOOL)animated;
|
||||||
|
|||||||
@ -21,14 +21,17 @@ public extension MVMCoreUITopAlertView {
|
|||||||
NotificationCenter.default.addObserver(self, selector: #selector(viewControllerChanged(notification:)), name: NSNotification.Name(rawValue: MVMCoreNotificationViewControllerChanged), object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(viewControllerChanged(notification:)), name: NSNotification.Name(rawValue: MVMCoreNotificationViewControllerChanged), object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func getDelegateObject() -> MVMCoreUIDelegateObject {
|
||||||
|
// TODO: Top alert view is current delegate. Should move to current view controller eventually?
|
||||||
|
return MVMCoreUIDelegateObject.create(withDelegateForAll: self)
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks for new top alert json
|
/// Checks for new top alert json
|
||||||
@objc func responseJSONUpdated(notification: Notification) {
|
@objc func responseJSONUpdated(notification: Notification) {
|
||||||
guard let responseJSON = (notification.userInfo?[String(describing: MVMCoreLoadObject.self)] as? MVMCoreLoadObject)?.responseJSON,
|
guard let responseJSON = (notification.userInfo?[String(describing: MVMCoreLoadObject.self)] as? MVMCoreLoadObject)?.responseJSON,
|
||||||
let json = responseJSON.optionalDictionaryForKey("TopNotification") else { return }
|
let json = responseJSON.optionalDictionaryForKey("TopNotification"),
|
||||||
|
let model = decodeTopNotification(with: json, delegateObject: getDelegateObject()) else { return }
|
||||||
// TODO: Top alert view is current delegate. Should move to current view controller eventually?
|
showTopAlert(with: model)
|
||||||
let delegateObject = MVMCoreUIDelegateObject.create(withDelegateForAll: self)
|
|
||||||
showTopAlert(with: json, delegateObject: delegateObject)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// When a detail page changes, check top alerts.
|
/// When a detail page changes, check top alerts.
|
||||||
@ -37,24 +40,55 @@ public extension MVMCoreUITopAlertView {
|
|||||||
MVMCoreAlertHandler.shared()?.checkPagesDependency(for: controller.pageType)
|
MVMCoreAlertHandler.shared()?.checkPagesDependency(for: controller.pageType)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shows the top alert with the json payload.
|
/// Decodes the json into a TopNotificationModel
|
||||||
func showTopAlert(with json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) {
|
func decodeTopNotification(with json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) -> TopNotificationModel? {
|
||||||
do {
|
do {
|
||||||
let model = try TopNotificationModel.decode(json: json, delegateObject: delegateObject)
|
return try TopNotificationModel.decode(json: json, delegateObject: delegateObject)
|
||||||
showTopAlert(with: model, delegateObject: delegateObject)
|
|
||||||
} catch {
|
} catch {
|
||||||
if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "\(self)") {
|
if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "\(self)") {
|
||||||
MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject)
|
MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shows the top alert with the model.
|
/// Shows the top alert with the model.
|
||||||
func showTopAlert(with model: TopNotificationModel, delegateObject: MVMCoreUIDelegateObject?) {
|
func showTopAlert(with model: TopNotificationModel) {
|
||||||
let object = model.createTopAlertObject()
|
let object = model.createTopAlertObject()
|
||||||
MVMCoreAlertHandler.shared()?.showTopAlert(with: object)
|
MVMCoreAlertHandler.shared()?.showTopAlert(with: object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates the current top alert molecule with the new object
|
||||||
|
@objc func updateMolecule(with topAlertObject: MVMCoreTopAlertObject) {
|
||||||
|
guard topAlertObject.type == self.topAlertObject?.type else { return }
|
||||||
|
let delegateObject = getDelegateObject()
|
||||||
|
guard let newJson = topAlertObject.json,
|
||||||
|
let newModel = decodeTopNotification(with: newJson, delegateObject: delegateObject),
|
||||||
|
let newModelName = MoleculeObjectMapping.shared()?.getMoleculeClass(newModel.molecule)?.nameForReuse(with: newModel.molecule, delegateObject),
|
||||||
|
let currentJson = self.topAlertObject?.json,
|
||||||
|
let currentModel = decodeTopNotification(with: currentJson, delegateObject: delegateObject),
|
||||||
|
let currentModelName = MoleculeObjectMapping.shared()?.getMoleculeClass(currentModel.molecule)?.nameForReuse(with: currentModel.molecule, delegateObject),
|
||||||
|
newModelName == currentModelName,
|
||||||
|
let molecule = currentAlert as? MoleculeViewProtocol else {
|
||||||
|
// Log that we couldn't update.
|
||||||
|
if let errorObject = MVMCoreErrorObject(title: nil, message: nil, messageToLog: nil, code: ErrorCode.parsingJSON.rawValue, domain: ErrorDomainNative, location: "TopNotification update \(String(describing: topAlertObject.type))") {
|
||||||
|
MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
||||||
|
// Update molecule
|
||||||
|
molecule.reset()
|
||||||
|
molecule.set(with: newModel.molecule, delegateObject, nil)
|
||||||
|
(molecule as? MVMCoreViewProtocol)?.updateView(self.bounds.width)
|
||||||
|
|
||||||
|
// Update status bar.
|
||||||
|
guard let statusBarDelegate = molecule as? StatusBarUI else { return }
|
||||||
|
let statusBarUI = statusBarDelegate.getStatusBarUI()
|
||||||
|
self.setStatusBarColor(statusBarUI.color, statusBarStyle: statusBarUI.style)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the top alert molecule to use and status bar color legacy style.
|
/// Returns the top alert molecule to use and status bar color legacy style.
|
||||||
@objc func molecule(for topAlertObject: MVMCoreTopAlertObject, statusBarColor: AutoreleasingUnsafeMutablePointer<UIColor?>?, statusBarStyle: UnsafeMutablePointer<UIStatusBarStyle>?) -> UIView? {
|
@objc func molecule(for topAlertObject: MVMCoreTopAlertObject, statusBarColor: AutoreleasingUnsafeMutablePointer<UIColor?>?, statusBarStyle: UnsafeMutablePointer<UIStatusBarStyle>?) -> UIView? {
|
||||||
do {
|
do {
|
||||||
|
|||||||
@ -27,6 +27,9 @@
|
|||||||
// Current top alert object
|
// Current top alert object
|
||||||
@property (strong, nullable, nonatomic) MVMCoreTopAlertObject *topAlertObject;
|
@property (strong, nullable, nonatomic) MVMCoreTopAlertObject *topAlertObject;
|
||||||
|
|
||||||
|
/// Current top alert view.
|
||||||
|
@property (weak, nullable, nonatomic, readonly) UIView *currentAlert;
|
||||||
|
|
||||||
// Returns the top alert view
|
// Returns the top alert view
|
||||||
+ (nullable instancetype)sharedGlobal;
|
+ (nullable instancetype)sharedGlobal;
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
|
|||||||
@property (strong, nonatomic) NSLayoutConstraint *statusBarBottomConstraint;
|
@property (strong, nonatomic) NSLayoutConstraint *statusBarBottomConstraint;
|
||||||
|
|
||||||
@property (weak, nonatomic) UIView *alertView;
|
@property (weak, nonatomic) UIView *alertView;
|
||||||
@property (weak, nonatomic) UIView *currentAlert;
|
@property (weak, nullable, nonatomic, readwrite) UIView *currentAlert;
|
||||||
@property (strong, nonatomic) NSLayoutConstraint *height;
|
@property (strong, nonatomic) NSLayoutConstraint *height;
|
||||||
|
|
||||||
@property (weak, nonatomic) MVMCoreUITopAlertExpandableView *topAlertClearspotView;
|
@property (weak, nonatomic) MVMCoreUITopAlertExpandableView *topAlertClearspotView;
|
||||||
@ -181,6 +181,10 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)updateTopAlertWith:(MVMCoreTopAlertObject *)topAlertObject {
|
||||||
|
[self updateMoleculeWith:topAlertObject];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setStatusBarColor:(nullable UIColor *)statusBarColor statusBarStyle:(UIStatusBarStyle)style {
|
- (void)setStatusBarColor:(nullable UIColor *)statusBarColor statusBarStyle:(UIStatusBarStyle)style {
|
||||||
self.statusBarView.backgroundColor = statusBarColor;
|
self.statusBarView.backgroundColor = statusBarColor;
|
||||||
self.statusBarStyle = style;
|
self.statusBarStyle = style;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user