Merge branch 'feature/notification_style' into 'develop'
style for notification See merge request BPHV_MIPS/mvm_core_ui!711
This commit is contained in:
commit
8c3cfeedeb
@ -8,6 +8,21 @@
|
|||||||
|
|
||||||
|
|
||||||
open class NotificationModel: MoleculeModelProtocol {
|
open class NotificationModel: MoleculeModelProtocol {
|
||||||
|
|
||||||
|
/**
|
||||||
|
The style of the notification:
|
||||||
|
- success, green background, white content
|
||||||
|
- error, orange background, black content
|
||||||
|
- \warning, yellow background, black content
|
||||||
|
- information, blue background, white content
|
||||||
|
*/
|
||||||
|
public enum Style: String, Codable {
|
||||||
|
case success
|
||||||
|
case error
|
||||||
|
case warning
|
||||||
|
case information
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -19,6 +34,7 @@ open class NotificationModel: MoleculeModelProtocol {
|
|||||||
public var body: LabelModel?
|
public var body: LabelModel?
|
||||||
public var button: ButtonModel?
|
public var button: ButtonModel?
|
||||||
public var closeButton: NotificationXButtonModel?
|
public var closeButton: NotificationXButtonModel?
|
||||||
|
public var style: NotificationModel.Style = .success
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializer
|
// MARK: - Initializer
|
||||||
@ -34,20 +50,63 @@ open class NotificationModel: MoleculeModelProtocol {
|
|||||||
|
|
||||||
open func setDefault() {
|
open func setDefault() {
|
||||||
if backgroundColor == nil {
|
if backgroundColor == nil {
|
||||||
backgroundColor = Color(uiColor: .mvmGreen)
|
switch style {
|
||||||
|
case .error:
|
||||||
|
backgroundColor = Color(uiColor: .mvmOrange)
|
||||||
|
case .warning:
|
||||||
|
backgroundColor = Color(uiColor: .mvmYellow)
|
||||||
|
case .information:
|
||||||
|
backgroundColor = Color(uiColor: .mvmBlue)
|
||||||
|
default:
|
||||||
|
backgroundColor = Color(uiColor: .mvmGreen)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if headline.textColor == nil {
|
if headline.textColor == nil {
|
||||||
headline.textColor = Color(uiColor: .mvmWhite)
|
switch style {
|
||||||
|
case .error, .warning:
|
||||||
|
headline.textColor = Color(uiColor: .mvmBlack)
|
||||||
|
default:
|
||||||
|
headline.textColor = Color(uiColor: .mvmWhite)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if body?.textColor == nil {
|
if body?.textColor == nil {
|
||||||
body?.textColor = Color(uiColor: .mvmWhite)
|
switch style {
|
||||||
|
case .error, .warning:
|
||||||
|
body?.textColor = Color(uiColor: .mvmBlack)
|
||||||
|
default:
|
||||||
|
body?.textColor = Color(uiColor: .mvmWhite)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button?.size = .tiny
|
||||||
|
if button?.enabledTextColor == nil {
|
||||||
|
switch style {
|
||||||
|
case .error, .warning:
|
||||||
|
button?.enabledTextColor = Color(uiColor: .mvmBlack)
|
||||||
|
default:
|
||||||
|
button?.enabledTextColor = Color(uiColor: .mvmWhite)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if button?.enabledBorderColor == nil {
|
||||||
|
switch style {
|
||||||
|
case .error, .warning:
|
||||||
|
button?.enabledBorderColor = Color(uiColor: .mvmBlack)
|
||||||
|
default:
|
||||||
|
button?.enabledBorderColor = Color(uiColor: .mvmWhite)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if button?.style == nil {
|
if button?.style == nil {
|
||||||
button?.style = .secondary
|
button?.style = .secondary
|
||||||
}
|
}
|
||||||
button?.size = .tiny
|
|
||||||
button?.enabledTextColor = Color(uiColor: .mvmWhite)
|
if closeButton?.color == nil {
|
||||||
button?.enabledBorderColor = Color(uiColor: .mvmWhite)
|
switch style {
|
||||||
|
case .error, .warning:
|
||||||
|
closeButton?.color = Color(uiColor: .mvmBlack)
|
||||||
|
default:
|
||||||
|
closeButton?.color = Color(uiColor: .mvmWhite)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -62,6 +121,7 @@ open class NotificationModel: MoleculeModelProtocol {
|
|||||||
case body
|
case body
|
||||||
case button
|
case button
|
||||||
case closeButton
|
case closeButton
|
||||||
|
case style
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -76,6 +136,9 @@ open class NotificationModel: MoleculeModelProtocol {
|
|||||||
body = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .body)
|
body = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .body)
|
||||||
button = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .button)
|
button = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .button)
|
||||||
closeButton = try typeContainer.decodeIfPresent(NotificationXButtonModel.self, forKey: .closeButton)
|
closeButton = try typeContainer.decodeIfPresent(NotificationXButtonModel.self, forKey: .closeButton)
|
||||||
|
if let style = try typeContainer.decodeIfPresent(NotificationModel.Style.self, forKey: .style) {
|
||||||
|
self.style = style
|
||||||
|
}
|
||||||
setDefault()
|
setDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,5 +151,6 @@ open class NotificationModel: MoleculeModelProtocol {
|
|||||||
try container.encodeIfPresent(body, forKey: .body)
|
try container.encodeIfPresent(body, forKey: .body)
|
||||||
try container.encodeIfPresent(button, forKey: .button)
|
try container.encodeIfPresent(button, forKey: .button)
|
||||||
try container.encodeIfPresent(closeButton, forKey: .closeButton)
|
try container.encodeIfPresent(closeButton, forKey: .closeButton)
|
||||||
|
try container.encode(style, forKey: .style)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,7 @@ import Foundation
|
|||||||
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
|
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
|
||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
guard let model = model as? NotificationXButtonModel else { return }
|
guard let model = model as? NotificationXButtonModel else { return }
|
||||||
tintColor = model.color.uiColor
|
tintColor = model.color?.uiColor ?? .white
|
||||||
|
|
||||||
// TODO: Temporary, consider action for dismissing top alert
|
// TODO: Temporary, consider action for dismissing top alert
|
||||||
if model.action.actionType == ActionNoopModel.identifier {
|
if model.action.actionType == ActionNoopModel.identifier {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import Foundation
|
|||||||
public class NotificationXButtonModel: ButtonModelProtocol, MoleculeModelProtocol {
|
public class NotificationXButtonModel: ButtonModelProtocol, MoleculeModelProtocol {
|
||||||
public static var identifier: String = "notificationXButton"
|
public static var identifier: String = "notificationXButton"
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var color = Color(uiColor: .white)
|
public var color: Color?
|
||||||
public var action: ActionModelProtocol = ActionNoopModel()
|
public var action: ActionModelProtocol = ActionNoopModel()
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
@ -24,7 +24,7 @@ public class NotificationXButtonModel: ButtonModelProtocol, MoleculeModelProtoco
|
|||||||
|
|
||||||
public required init(from decoder: Decoder) throws {
|
public required init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) ?? Color(uiColor: .white)
|
color = try typeContainer.decodeIfPresent(Color.self, forKey: .color)
|
||||||
if let action: ActionModelProtocol = try typeContainer.decodeModelIfPresent(codingKey: .action) {
|
if let action: ActionModelProtocol = try typeContainer.decodeModelIfPresent(codingKey: .action) {
|
||||||
self.action = action
|
self.action = action
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ public class NotificationXButtonModel: ButtonModelProtocol, MoleculeModelProtoco
|
|||||||
public func encode(to encoder: Encoder) throws {
|
public 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.encode(color, forKey: .color)
|
try container.encodeIfPresent(color, forKey: .color)
|
||||||
try container.encodeModel(action, forKey: .action)
|
try container.encodeModel(action, forKey: .action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user