addressing intrinsic content issue
This commit is contained in:
parent
b36299b695
commit
5c23e80429
@ -38,13 +38,7 @@ public typealias ActionBlock = () -> ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
public var getRange: NSRange {
|
public var getRange: NSRange {
|
||||||
return NSRange(location: 0, length: text?.count ?? 0)
|
NSRange(location: 0, length: text?.count ?? 0)
|
||||||
}
|
|
||||||
|
|
||||||
open override var text: String? {
|
|
||||||
didSet {
|
|
||||||
// TODO....????
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -102,6 +96,10 @@ public typealias ActionBlock = () -> ()
|
|||||||
accessibilityCustomActions = []
|
accessibilityCustomActions = []
|
||||||
accessibilityTraits = .staticText
|
accessibilityTraits = .staticText
|
||||||
|
|
||||||
|
// if #available(iOS 14.0, *) {
|
||||||
|
// lineBreakStrategy = .init()
|
||||||
|
// }
|
||||||
|
|
||||||
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(textLinkTapped))
|
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(textLinkTapped))
|
||||||
tapGesture.numberOfTapsRequired = 1
|
tapGesture.numberOfTapsRequired = 1
|
||||||
addGestureRecognizer(tapGesture)
|
addGestureRecognizer(tapGesture)
|
||||||
@ -918,64 +916,7 @@ extension Label {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Label {
|
|
||||||
|
|
||||||
open func getSeparatedLines() -> [Any] {
|
|
||||||
|
|
||||||
if lineBreakMode != .byWordWrapping {
|
|
||||||
lineBreakMode = .byWordWrapping
|
|
||||||
}
|
|
||||||
|
|
||||||
var lines = [Any]() /* capacity: 10 */
|
|
||||||
let wordSeparators = CharacterSet.whitespacesAndNewlines
|
|
||||||
var currentLine: String? = self.text
|
|
||||||
let textLength: Int = (self.text?.count ?? 0)
|
|
||||||
var rCurrentLine = NSRange(location: 0, length: textLength)
|
|
||||||
var rWhitespace = NSRange(location: 0, length: 0)
|
|
||||||
var rRemainingText = NSRange(location: 0, length: textLength)
|
|
||||||
var done: Bool = false
|
|
||||||
|
|
||||||
while !done {
|
|
||||||
// determine the next whitespace word separator position
|
|
||||||
rWhitespace.location = rWhitespace.location + rWhitespace.length
|
|
||||||
rWhitespace.length = textLength - rWhitespace.location
|
|
||||||
rWhitespace = (self.text! as NSString).rangeOfCharacter(from: wordSeparators, options: .caseInsensitive, range: rWhitespace)
|
|
||||||
if rWhitespace.location == NSNotFound {
|
|
||||||
rWhitespace.location = textLength
|
|
||||||
done = true
|
|
||||||
}
|
|
||||||
let rTest = NSRange(location: rRemainingText.location, length: rWhitespace.location - rRemainingText.location)
|
|
||||||
let textTest: String = (self.text! as NSString).substring(with: rTest)
|
|
||||||
let fontAttributes: [String: Any]? = [NSAttributedString.Key.font.rawValue: font]
|
|
||||||
let maxWidth = (textTest as NSString).size(withAttributes: [NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): font]).width
|
|
||||||
if maxWidth > self.bounds.size.width {
|
|
||||||
lines.append(currentLine?.trimmingCharacters(in: wordSeparators) ?? "")
|
|
||||||
rRemainingText.location = rCurrentLine.location + rCurrentLine.length
|
|
||||||
rRemainingText.length = textLength - rRemainingText.location
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
rCurrentLine = rTest
|
|
||||||
currentLine = textTest
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.append(currentLine?.trimmingCharacters(in: wordSeparators) ?? "")
|
|
||||||
|
|
||||||
return lines
|
|
||||||
}
|
|
||||||
|
|
||||||
open var lastLineWidth: CGFloat {
|
|
||||||
|
|
||||||
let lines: [Any] = self.getSeparatedLines()
|
|
||||||
|
|
||||||
if !lines.isEmpty {
|
|
||||||
let lastLine: String = (lines.last as? String)!
|
|
||||||
let fontAttributes = [NSAttributedString.Key.font.rawValue: font]
|
|
||||||
return (lastLine as NSString).size(withAttributes: [NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): font]).width
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: -
|
// MARK: -
|
||||||
extension UITapGestureRecognizer {
|
extension UITapGestureRecognizer {
|
||||||
|
|||||||
@ -42,14 +42,4 @@ import UIKit
|
|||||||
else { return 80 }
|
else { return 80 }
|
||||||
return height
|
return height
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Figure out height.....
|
|
||||||
open override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize {
|
|
||||||
guard let molecule = molecule as? HeadlineBody else { return super.frame.size }
|
|
||||||
let cell = self
|
|
||||||
cell.frame = CGRect(x: 0, y: 0, width: targetSize.width, height: CGFloat(MAXFLOAT))
|
|
||||||
cell.layoutIfNeeded()
|
|
||||||
|
|
||||||
return CGSize(width: molecule.bounds.width + cell.contentView.directionalLayoutMargins.leading + cell.contentView.directionalLayoutMargins.trailing, height: molecule.bounds.height + cell.contentView.directionalLayoutMargins.top + cell.contentView.directionalLayoutMargins.bottom)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,19 +19,15 @@ open class HeadlineBody: View {
|
|||||||
// MARK: - Constraints
|
// MARK: - Constraints
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
var spaceBetweenLabelsConstant = PaddingOne
|
var spaceBetweenLabelsConstant = Padding.One
|
||||||
var spaceBetweenLabels: NSLayoutConstraint?
|
var spaceBetweenLabels: NSLayoutConstraint?
|
||||||
var leftConstraintTitle: NSLayoutConstraint?
|
|
||||||
var rightConstraintTitle: NSLayoutConstraint?
|
|
||||||
var leftConstraintMessage: NSLayoutConstraint?
|
|
||||||
var rightConstraintMessage: NSLayoutConstraint?
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Methods
|
// MARK: - Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
func hasText() -> Bool {
|
func hasText() -> Bool {
|
||||||
return headlineLabel.hasText || messageLabel.hasText
|
headlineLabel.hasText || messageLabel.hasText
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Styling
|
// MARK: - Styling
|
||||||
@ -57,13 +53,13 @@ open class HeadlineBody: View {
|
|||||||
func styleLandingPageHeader() {
|
func styleLandingPageHeader() {
|
||||||
headlineLabel.setFontStyle(.Title2XLarge)
|
headlineLabel.setFontStyle(.Title2XLarge)
|
||||||
messageLabel.setFontStyle(.RegularBodySmall)
|
messageLabel.setFontStyle(.RegularBodySmall)
|
||||||
spaceBetweenLabelsConstant = PaddingTwo
|
spaceBetweenLabelsConstant = Padding.Two
|
||||||
}
|
}
|
||||||
|
|
||||||
func stylePageHeader() {
|
func stylePageHeader() {
|
||||||
headlineLabel.setFontStyle(.BoldTitleLarge)
|
headlineLabel.setFontStyle(.BoldTitleLarge)
|
||||||
messageLabel.setFontStyle(.RegularBodySmall)
|
messageLabel.setFontStyle(.RegularBodySmall)
|
||||||
spaceBetweenLabelsConstant = PaddingOne
|
spaceBetweenLabelsConstant = Padding.Two
|
||||||
}
|
}
|
||||||
|
|
||||||
func styleListItem() {
|
func styleListItem() {
|
||||||
@ -86,48 +82,38 @@ open class HeadlineBody: View {
|
|||||||
super.setupView()
|
super.setupView()
|
||||||
|
|
||||||
backgroundColor = .clear
|
backgroundColor = .clear
|
||||||
clipsToBounds = true
|
isAccessibilityElement = false
|
||||||
|
shouldGroupAccessibilityChildren = true
|
||||||
|
accessibilityElements = [headlineLabel, messageLabel]
|
||||||
|
|
||||||
let view = MVMCoreUICommonViewsUtility.commonView()
|
addSubview(headlineLabel)
|
||||||
addSubview(view)
|
addSubview(messageLabel)
|
||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: view)
|
|
||||||
|
|
||||||
view.isAccessibilityElement = false
|
headlineLabel.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
view.shouldGroupAccessibilityChildren = true
|
messageLabel.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
view.accessibilityElements = [headlineLabel, messageLabel]
|
|
||||||
|
|
||||||
view.addSubview(headlineLabel)
|
headlineLabel.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
||||||
view.addSubview(messageLabel)
|
|
||||||
|
|
||||||
headlineLabel.setContentHuggingPriority(.required, for: .vertical)
|
|
||||||
messageLabel.setContentHuggingPriority(.required, for: .vertical)
|
|
||||||
view.setContentHuggingPriority(.required, for: .vertical)
|
|
||||||
|
|
||||||
headlineLabel.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
|
|
||||||
|
|
||||||
spaceBetweenLabels = messageLabel.topAnchor.constraint(equalTo: headlineLabel.bottomAnchor, constant: spaceBetweenLabelsConstant)
|
spaceBetweenLabels = messageLabel.topAnchor.constraint(equalTo: headlineLabel.bottomAnchor, constant: spaceBetweenLabelsConstant)
|
||||||
spaceBetweenLabels?.isActive = true
|
spaceBetweenLabels?.isActive = true
|
||||||
|
|
||||||
leftConstraintTitle = headlineLabel.leftAnchor.constraint(equalTo: view.leftAnchor)
|
NSLayoutConstraint.activate([
|
||||||
leftConstraintTitle?.isActive = true
|
headlineLabel.leadingAnchor.constraint(equalTo: leadingAnchor),
|
||||||
|
trailingAnchor.constraint(equalTo: headlineLabel.trailingAnchor),
|
||||||
rightConstraintTitle = view.rightAnchor.constraint(equalTo: headlineLabel.rightAnchor)
|
messageLabel.leadingAnchor.constraint(equalTo: leadingAnchor),
|
||||||
rightConstraintTitle?.isActive = true
|
trailingAnchor.constraint(equalTo: messageLabel.trailingAnchor),
|
||||||
|
bottomAnchor.constraint(equalTo: messageLabel.bottomAnchor)
|
||||||
leftConstraintMessage = messageLabel.leftAnchor.constraint(equalTo: view.leftAnchor)
|
])
|
||||||
leftConstraintMessage?.isActive = true
|
|
||||||
|
|
||||||
rightConstraintMessage = view.rightAnchor.constraint(equalTo: messageLabel.rightAnchor)
|
|
||||||
rightConstraintMessage?.isActive = true
|
|
||||||
|
|
||||||
view.bottomAnchor.constraint(equalTo: messageLabel.bottomAnchor).isActive = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateView(_ size: CGFloat) {
|
open override func updateView(_ size: CGFloat) {
|
||||||
super.updateView(size)
|
super.updateView(size)
|
||||||
|
setSpacing()
|
||||||
headlineLabel.updateView(size)
|
headlineLabel.updateView(size)
|
||||||
messageLabel.updateView(size)
|
messageLabel.updateView(size)
|
||||||
setSpacing()
|
let padding = MFStyler.defaultHorizontalPadding(forSize: size) * 2
|
||||||
|
let maximumTextWidth = (size - (padding + Padding.Four))
|
||||||
|
messageLabel.preferredMaxLayoutWidth = maximumTextWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -146,19 +132,18 @@ open class HeadlineBody: View {
|
|||||||
// MARK: - MoleculeViewProtocol
|
// MARK: - MoleculeViewProtocol
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
public override class func estimatedHeight(with model: MoleculeModelProtocol,
|
||||||
return 58
|
_ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { 58 }
|
||||||
}
|
|
||||||
|
|
||||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
public 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 headlineBodyModel = model as? HeadlineBodyModel else { return }
|
guard let model = model as? HeadlineBodyModel else { return }
|
||||||
|
|
||||||
style(with: headlineBodyModel.style)
|
style(with: model.style)
|
||||||
|
|
||||||
headlineLabel.setOptional(with: headlineBodyModel.headline, delegateObject, additionalData)
|
headlineLabel.setOptional(with: model.headline, delegateObject, additionalData)
|
||||||
messageLabel.setOptional(with: headlineBodyModel.body, delegateObject, additionalData)
|
messageLabel.setOptional(with: model.body, delegateObject, additionalData)
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user