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:
Pfeil, Scott Robert 2020-02-19 12:39:02 -05:00
commit d96ceb0063
4 changed files with 32 additions and 3 deletions

View File

@ -36,6 +36,10 @@ import UIKit
context?.strokePath()
}
//--------------------------------------------------
// MARK: - ModelMoleculeViewProtocol
//--------------------------------------------------
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.setWithModel(model, delegateObject, additionalData)
guard let model = model as? LinkModel else { return }

View File

@ -9,7 +9,12 @@
import UIKit
public class LinkModel: ButtonModelProtocol, MoleculeModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "link"
public var backgroundColor: Color?
public var title: String
public var action: ActionModelProtocol
@ -17,12 +22,21 @@ public class LinkModel: ButtonModelProtocol, MoleculeModelProtocol {
public var textColor = Color(uiColor: .mvmBlack)
public var disabledColor = Color(uiColor: .mvmCoolGray6)
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public init(title: String, action: ActionModelProtocol) {
self.title = title
self.action = action
}
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey {
case moleculeName
case backgroundColor
case title
case action
@ -31,11 +45,16 @@ public class LinkModel: ButtonModelProtocol, MoleculeModelProtocol {
case disabledColor
}
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
title = try typeContainer.decode(String.self, forKey: .title)
action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
self.enabled = enabled
}
@ -54,6 +73,7 @@ public class LinkModel: ButtonModelProtocol, MoleculeModelProtocol {
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeModel(action, forKey: .action)
try container.encode(enabled, forKey: .enabled)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(textColor, forKey: .textColor)
try container.encode(disabledColor, forKey: .disabledColor)
}

View File

@ -12,6 +12,7 @@ public typealias ButtonAction = (Button) -> ()
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
open var model: MoleculeModelProtocol?
open var actionModel: ActionModelProtocol?
@ -67,7 +68,7 @@ public typealias ButtonAction = (Button) -> ()
addTarget(self, action: #selector(callActionBlock(_:)), for: event)
}
@objc private func callActionBlock(_ sender: Button) {
@objc func callActionBlock(_ sender: Button) {
buttonAction?(self)
}
@ -88,11 +89,13 @@ public typealias ButtonAction = (Button) -> ()
// MARK:- ModelMoleculeViewProtocol
open func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
self.model = model
if let backgroundColor = model?.backgroundColor {
self.backgroundColor = backgroundColor.uiColor
}
guard let model = model as? ButtonModelProtocol else { return }
isEnabled = model.enabled
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData)
}
@ -113,7 +116,7 @@ public typealias ButtonAction = (Button) -> ()
// MARK: - MVMCoreViewProtocol
extension Button: MVMCoreViewProtocol {
open func updateView(_ size: CGFloat) {}
open func updateView(_ size: CGFloat) { }
/// Will be called only once.
open func setupView() {
@ -126,6 +129,7 @@ extension Button: MVMCoreViewProtocol {
// MARK: - MVMCoreUIMoleculeViewProtocol
extension Button: MVMCoreUIMoleculeViewProtocol {
open func reset() {
backgroundColor = .clear
}
@ -133,6 +137,7 @@ extension Button: MVMCoreUIMoleculeViewProtocol {
// MARK: AppleGuidelinesProtocol
extension Button: AppleGuidelinesProtocol {
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
return Self.acceptablyOutsideBounds(point: point, bounds: bounds)
}

View File

@ -3,7 +3,7 @@ import Foundation
public protocol MoleculeModelProtocol: Model {
var moleculeName: String? { get }
var backgroundColor: Color? { get set}
var backgroundColor: Color? { get set }
}
public extension MoleculeModelProtocol {