Merge branch 'feature/copy_link_text' into 'develop'
New Action share See merge request BPHV_MIPS/mvm_core_ui!267
This commit is contained in:
commit
d96ceb0063
@ -36,6 +36,10 @@ import UIKit
|
|||||||
context?.strokePath()
|
context?.strokePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - ModelMoleculeViewProtocol
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
super.setWithModel(model, delegateObject, additionalData)
|
super.setWithModel(model, delegateObject, additionalData)
|
||||||
guard let model = model as? LinkModel else { return }
|
guard let model = model as? LinkModel else { return }
|
||||||
|
|||||||
@ -9,7 +9,12 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public class LinkModel: ButtonModelProtocol, MoleculeModelProtocol {
|
public class LinkModel: ButtonModelProtocol, MoleculeModelProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public static var identifier: String = "link"
|
public static var identifier: String = "link"
|
||||||
|
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var title: String
|
public var title: String
|
||||||
public var action: ActionModelProtocol
|
public var action: ActionModelProtocol
|
||||||
@ -17,12 +22,21 @@ public class LinkModel: ButtonModelProtocol, MoleculeModelProtocol {
|
|||||||
public var textColor = Color(uiColor: .mvmBlack)
|
public var textColor = Color(uiColor: .mvmBlack)
|
||||||
public var disabledColor = Color(uiColor: .mvmCoolGray6)
|
public var disabledColor = Color(uiColor: .mvmCoolGray6)
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Initializer
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public init(title: String, action: ActionModelProtocol) {
|
public init(title: String, action: ActionModelProtocol) {
|
||||||
self.title = title
|
self.title = title
|
||||||
self.action = action
|
self.action = action
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Keys
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case moleculeName
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
case title
|
case title
|
||||||
case action
|
case action
|
||||||
@ -31,11 +45,16 @@ public class LinkModel: ButtonModelProtocol, MoleculeModelProtocol {
|
|||||||
case disabledColor
|
case disabledColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Codec
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
title = try typeContainer.decode(String.self, forKey: .title)
|
title = try typeContainer.decode(String.self, forKey: .title)
|
||||||
action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
|
action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
|
||||||
|
|
||||||
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
|
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
}
|
}
|
||||||
@ -54,6 +73,7 @@ public class LinkModel: ButtonModelProtocol, MoleculeModelProtocol {
|
|||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encodeModel(action, forKey: .action)
|
try container.encodeModel(action, forKey: .action)
|
||||||
try container.encode(enabled, forKey: .enabled)
|
try container.encode(enabled, forKey: .enabled)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encode(textColor, forKey: .textColor)
|
try container.encode(textColor, forKey: .textColor)
|
||||||
try container.encode(disabledColor, forKey: .disabledColor)
|
try container.encode(disabledColor, forKey: .disabledColor)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ public typealias ButtonAction = (Button) -> ()
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
open var model: MoleculeModelProtocol?
|
open var model: MoleculeModelProtocol?
|
||||||
open var actionModel: ActionModelProtocol?
|
open var actionModel: ActionModelProtocol?
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ public typealias ButtonAction = (Button) -> ()
|
|||||||
addTarget(self, action: #selector(callActionBlock(_:)), for: event)
|
addTarget(self, action: #selector(callActionBlock(_:)), for: event)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func callActionBlock(_ sender: Button) {
|
@objc func callActionBlock(_ sender: Button) {
|
||||||
buttonAction?(self)
|
buttonAction?(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,11 +89,13 @@ public typealias ButtonAction = (Button) -> ()
|
|||||||
// MARK:- ModelMoleculeViewProtocol
|
// MARK:- ModelMoleculeViewProtocol
|
||||||
open func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
open func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
self.model = model
|
self.model = model
|
||||||
|
|
||||||
if let backgroundColor = model?.backgroundColor {
|
if let backgroundColor = model?.backgroundColor {
|
||||||
self.backgroundColor = backgroundColor.uiColor
|
self.backgroundColor = backgroundColor.uiColor
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let model = model as? ButtonModelProtocol else { return }
|
guard let model = model as? ButtonModelProtocol else { return }
|
||||||
|
|
||||||
isEnabled = model.enabled
|
isEnabled = model.enabled
|
||||||
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData)
|
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData)
|
||||||
}
|
}
|
||||||
@ -113,7 +116,7 @@ public typealias ButtonAction = (Button) -> ()
|
|||||||
// MARK: - MVMCoreViewProtocol
|
// MARK: - MVMCoreViewProtocol
|
||||||
extension Button: MVMCoreViewProtocol {
|
extension Button: MVMCoreViewProtocol {
|
||||||
|
|
||||||
open func updateView(_ size: CGFloat) {}
|
open func updateView(_ size: CGFloat) { }
|
||||||
|
|
||||||
/// Will be called only once.
|
/// Will be called only once.
|
||||||
open func setupView() {
|
open func setupView() {
|
||||||
@ -126,6 +129,7 @@ extension Button: MVMCoreViewProtocol {
|
|||||||
|
|
||||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||||
extension Button: MVMCoreUIMoleculeViewProtocol {
|
extension Button: MVMCoreUIMoleculeViewProtocol {
|
||||||
|
|
||||||
open func reset() {
|
open func reset() {
|
||||||
backgroundColor = .clear
|
backgroundColor = .clear
|
||||||
}
|
}
|
||||||
@ -133,6 +137,7 @@ extension Button: MVMCoreUIMoleculeViewProtocol {
|
|||||||
|
|
||||||
// MARK: AppleGuidelinesProtocol
|
// MARK: AppleGuidelinesProtocol
|
||||||
extension Button: AppleGuidelinesProtocol {
|
extension Button: AppleGuidelinesProtocol {
|
||||||
|
|
||||||
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||||
return Self.acceptablyOutsideBounds(point: point, bounds: bounds)
|
return Self.acceptablyOutsideBounds(point: point, bounds: bounds)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import Foundation
|
|||||||
|
|
||||||
public protocol MoleculeModelProtocol: Model {
|
public protocol MoleculeModelProtocol: Model {
|
||||||
var moleculeName: String? { get }
|
var moleculeName: String? { get }
|
||||||
var backgroundColor: Color? { get set}
|
var backgroundColor: Color? { get set }
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension MoleculeModelProtocol {
|
public extension MoleculeModelProtocol {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user