merging
This commit is contained in:
commit
eba33717b5
@ -241,15 +241,38 @@ public typealias ActionBlock = () -> ()
|
|||||||
public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
|
|
||||||
clauses = []
|
clauses = []
|
||||||
|
text = nil
|
||||||
guard let labelModel = model as? LabelModel else {
|
|
||||||
text = ""
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
attributedText = nil
|
attributedText = nil
|
||||||
originalAttributedString = nil
|
originalAttributedString = nil
|
||||||
|
|
||||||
|
guard let labelModel = model as? LabelModel else { return }
|
||||||
|
|
||||||
text = labelModel.text
|
text = labelModel.text
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is to address a reuse issue with iOS 13 and up.
|
||||||
|
* Even if you set text & attributedText to nil, the moment you set text with a value,
|
||||||
|
* attributedText will hold a dirty value from a previously reused cell even if reset() is
|
||||||
|
* appropriately called.
|
||||||
|
* Only other reference found of issue: https://www.thetopsites.net/article/58142205.shtml
|
||||||
|
*/
|
||||||
|
if #available(iOS 13, *) {
|
||||||
|
if let attributedText = attributedText, let text = text {
|
||||||
|
let attributedString = NSMutableAttributedString(string: text)
|
||||||
|
let range = NSRange(location: 0, length: text.count)
|
||||||
|
for attribute in attributedText.attributes(at: 0, effectiveRange: nil) {
|
||||||
|
if attribute.key == .underlineStyle {
|
||||||
|
attributedString.addAttribute(.underlineStyle, value: 0, range: range)
|
||||||
|
}
|
||||||
|
if attribute.key == .strikethroughStyle {
|
||||||
|
attributedString.addAttribute(.strikethroughStyle, value: 0, range: range)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.attributedText = attributedString
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hero = labelModel.hero
|
hero = labelModel.hero
|
||||||
Label.setLabel(self, withHTML: labelModel.html)
|
Label.setLabel(self, withHTML: labelModel.html)
|
||||||
isAccessibilityElement = hasText
|
isAccessibilityElement = hasText
|
||||||
@ -257,8 +280,10 @@ public typealias ActionBlock = () -> ()
|
|||||||
switch labelModel.textAlignment {
|
switch labelModel.textAlignment {
|
||||||
case .center:
|
case .center:
|
||||||
textAlignment = .center
|
textAlignment = .center
|
||||||
|
|
||||||
case .right:
|
case .right:
|
||||||
textAlignment = .right
|
textAlignment = .right
|
||||||
|
|
||||||
default:
|
default:
|
||||||
textAlignment = .left
|
textAlignment = .left
|
||||||
}
|
}
|
||||||
@ -290,7 +315,7 @@ public typealias ActionBlock = () -> ()
|
|||||||
if let color = labelModel.textColor {
|
if let color = labelModel.textColor {
|
||||||
textColor = color.uiColor
|
textColor = color.uiColor
|
||||||
}
|
}
|
||||||
|
|
||||||
if let attributes = labelModel.attributes, let labelText = text {
|
if let attributes = labelModel.attributes, let labelText = text {
|
||||||
let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: font.updateSize(standardFontSize), NSAttributedString.Key.foregroundColor: textColor as UIColor])
|
let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: font.updateSize(standardFontSize), NSAttributedString.Key.foregroundColor: textColor as UIColor])
|
||||||
|
|
||||||
@ -360,7 +385,7 @@ public typealias ActionBlock = () -> ()
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
attributedText = attributedString
|
attributedText = attributedString
|
||||||
originalAttributedString = attributedText
|
originalAttributedString = attributedText
|
||||||
}
|
}
|
||||||
@ -504,11 +529,11 @@ public typealias ActionBlock = () -> ()
|
|||||||
textColor = .mvmBlack
|
textColor = .mvmBlack
|
||||||
setScale(scale)
|
setScale(scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - 2.0 Styling Methods
|
// MARK: - 2.0 Styling Methods
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
@objc public func styleH1(_ scale: Bool) {
|
@objc public func styleH1(_ scale: Bool) {
|
||||||
MFStyler.styleLabelH1(self, genericScaling: false)
|
MFStyler.styleLabelH1(self, genericScaling: false)
|
||||||
setScale(scale)
|
setScale(scale)
|
||||||
@ -549,6 +574,23 @@ public typealias ActionBlock = () -> ()
|
|||||||
setScale(scale)
|
setScale(scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Will remove the values contained in attributedText.
|
||||||
|
func clearAttributes() {
|
||||||
|
|
||||||
|
guard let labelText = text,
|
||||||
|
let attributes = attributedText?.attributes(at: 0, longestEffectiveRange: nil, in: NSRange(location: 0, length: labelText.count))
|
||||||
|
else { return }
|
||||||
|
|
||||||
|
let attributedString = NSMutableAttributedString(string: labelText)
|
||||||
|
|
||||||
|
for attribute in attributes {
|
||||||
|
attributedString.removeAttribute(attribute.key, range: NSRange(location: 0, length: labelText.count))
|
||||||
|
}
|
||||||
|
|
||||||
|
attributedText = attributedString
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@objc public func updateView(_ size: CGFloat) {
|
@objc public func updateView(_ size: CGFloat) {
|
||||||
scaleSize = size as NSNumber
|
scaleSize = size as NSNumber
|
||||||
|
|
||||||
@ -836,7 +878,7 @@ extension Label {
|
|||||||
|
|
||||||
/// Converts the entire text into a link. All characters will be underlined and the intrinsic bounds will respond to tap.
|
/// Converts the entire text into a link. All characters will be underlined and the intrinsic bounds will respond to tap.
|
||||||
@objc public func makeTextButton(actionBlock: @escaping ActionBlock) {
|
@objc public func makeTextButton(actionBlock: @escaping ActionBlock) {
|
||||||
|
|
||||||
setTextLinkState(range: getRange, actionBlock: actionBlock)
|
setTextLinkState(range: getRange, actionBlock: actionBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -921,7 +963,7 @@ extension Label {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc public func accessibilityCustomAction(_ action: UIAccessibilityCustomAction) {
|
@objc public func accessibilityCustomAction(_ action: UIAccessibilityCustomAction) {
|
||||||
|
|
||||||
for clause in clauses {
|
for clause in clauses {
|
||||||
if action.hash == clause.accessibilityID {
|
if action.hash == clause.accessibilityID {
|
||||||
clause.performAction()
|
clause.performAction()
|
||||||
@ -931,7 +973,7 @@ extension Label {
|
|||||||
}
|
}
|
||||||
|
|
||||||
open override func accessibilityActivate() -> Bool {
|
open override func accessibilityActivate() -> Bool {
|
||||||
|
|
||||||
guard let accessibleActions = accessibilityCustomActions else { return false }
|
guard let accessibleActions = accessibilityCustomActions else { return false }
|
||||||
|
|
||||||
for clause in clauses {
|
for clause in clauses {
|
||||||
|
|||||||
@ -6,23 +6,39 @@
|
|||||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
|
||||||
|
|
||||||
open class LabelAttributeActionModel: LabelAttributeModel {
|
open class LabelAttributeActionModel: LabelAttributeModel {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
override public class var identifier: String {
|
override public class var identifier: String {
|
||||||
return "action"
|
return "action"
|
||||||
}
|
}
|
||||||
|
|
||||||
var action: ActionModelProtocol
|
var action: ActionModelProtocol
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Initializer
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public init(_ location: Int, _ length: Int, action: ActionModelProtocol) {
|
public init(_ location: Int, _ length: Int, action: ActionModelProtocol) {
|
||||||
self.action = action
|
self.action = action
|
||||||
super.init(location, length)
|
super.init(location, length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Keys
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case action
|
case action
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// 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)
|
||||||
action = try typeContainer.decodeModel(codingKey: .action)
|
action = try typeContainer.decodeModel(codingKey: .action)
|
||||||
|
|||||||
@ -6,7 +6,6 @@
|
|||||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
|
||||||
|
|
||||||
@objcMembers public class LabelAttributeColorModel: LabelAttributeModel {
|
@objcMembers public class LabelAttributeColorModel: LabelAttributeModel {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -6,8 +6,6 @@
|
|||||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
|
||||||
|
|
||||||
|
|
||||||
@objcMembers public class LabelAttributeFontModel: LabelAttributeModel {
|
@objcMembers public class LabelAttributeFontModel: LabelAttributeModel {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -6,13 +6,12 @@
|
|||||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
|
||||||
|
|
||||||
class LabelAttributeImageModel: LabelAttributeModel {
|
class LabelAttributeImageModel: LabelAttributeModel {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
override public class var identifier: String {
|
override public class var identifier: String {
|
||||||
return "image"
|
return "image"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,6 @@
|
|||||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
@objcMembers open class LabelAttributeModel: ModelProtocol {
|
@objcMembers open class LabelAttributeModel: ModelProtocol {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -20,7 +19,7 @@ import Foundation
|
|||||||
public static var categoryCodingKey: String {
|
public static var categoryCodingKey: String {
|
||||||
return "type"
|
return "type"
|
||||||
}
|
}
|
||||||
|
|
||||||
public class var identifier: String {
|
public class var identifier: String {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@ -31,12 +30,16 @@ import Foundation
|
|||||||
|
|
||||||
var location: Int
|
var location: Int
|
||||||
var length: Int
|
var length: Int
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Initializer
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public init(_ location: Int, _ length: Int) {
|
public init(_ location: Int, _ length: Int) {
|
||||||
self.location = location
|
self.location = location
|
||||||
self.length = length
|
self.length = length
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Keys
|
// MARK: - Keys
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -6,16 +6,28 @@
|
|||||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
|
||||||
|
|
||||||
@objcMembers public class LabelAttributeStrikeThroughModel: LabelAttributeModel {
|
@objcMembers public class LabelAttributeStrikeThroughModel: LabelAttributeModel {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
override public class var identifier: String {
|
override public class var identifier: String {
|
||||||
return "strikethrough"
|
return "strikethrough"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Initializer
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
try super.init(from: decoder)
|
try super.init(from: decoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Codec
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
@objcMembers public class LabelModel: MoleculeModelProtocol {
|
@objcMembers public class LabelModel: MoleculeModelProtocol {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user