diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 14d2e247..42827e67 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -38,13 +38,7 @@ public typealias ActionBlock = () -> () } public var getRange: NSRange { - return NSRange(location: 0, length: text?.count ?? 0) - } - - open override var text: String? { - didSet { - // TODO....???? - } + NSRange(location: 0, length: text?.count ?? 0) } //------------------------------------------------------ @@ -102,6 +96,10 @@ public typealias ActionBlock = () -> () accessibilityCustomActions = [] accessibilityTraits = .staticText +// if #available(iOS 14.0, *) { +// lineBreakStrategy = .init() +// } + let tapGesture = UITapGestureRecognizer(target: self, action: #selector(textLinkTapped)) tapGesture.numberOfTapsRequired = 1 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: - extension UITapGestureRecognizer { diff --git a/MVMCoreUI/Atomic/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Atomic/Molecules/Items/MoleculeTableViewCell.swift index 621cbeee..92d04bed 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/MoleculeTableViewCell.swift @@ -42,14 +42,4 @@ import UIKit else { return 80 } 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) - } } diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift index d111d1c5..8144fc03 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift @@ -19,19 +19,15 @@ open class HeadlineBody: View { // MARK: - Constraints //-------------------------------------------------- - var spaceBetweenLabelsConstant = PaddingOne + var spaceBetweenLabelsConstant = Padding.One var spaceBetweenLabels: NSLayoutConstraint? - var leftConstraintTitle: NSLayoutConstraint? - var rightConstraintTitle: NSLayoutConstraint? - var leftConstraintMessage: NSLayoutConstraint? - var rightConstraintMessage: NSLayoutConstraint? //-------------------------------------------------- // MARK: - Methods //-------------------------------------------------- func hasText() -> Bool { - return headlineLabel.hasText || messageLabel.hasText + headlineLabel.hasText || messageLabel.hasText } // MARK: - Styling @@ -57,13 +53,13 @@ open class HeadlineBody: View { func styleLandingPageHeader() { headlineLabel.setFontStyle(.Title2XLarge) messageLabel.setFontStyle(.RegularBodySmall) - spaceBetweenLabelsConstant = PaddingTwo + spaceBetweenLabelsConstant = Padding.Two } func stylePageHeader() { headlineLabel.setFontStyle(.BoldTitleLarge) messageLabel.setFontStyle(.RegularBodySmall) - spaceBetweenLabelsConstant = PaddingOne + spaceBetweenLabelsConstant = Padding.Two } func styleListItem() { @@ -86,48 +82,38 @@ open class HeadlineBody: View { super.setupView() backgroundColor = .clear - clipsToBounds = true + isAccessibilityElement = false + shouldGroupAccessibilityChildren = true + accessibilityElements = [headlineLabel, messageLabel] - let view = MVMCoreUICommonViewsUtility.commonView() - addSubview(view) - NSLayoutConstraint.constraintPinSubview(toSuperview: view) + addSubview(headlineLabel) + addSubview(messageLabel) - view.isAccessibilityElement = false - view.shouldGroupAccessibilityChildren = true - view.accessibilityElements = [headlineLabel, messageLabel] + headlineLabel.setContentCompressionResistancePriority(.required, for: .vertical) + messageLabel.setContentCompressionResistancePriority(.required, for: .vertical) - view.addSubview(headlineLabel) - 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 + headlineLabel.topAnchor.constraint(equalTo: topAnchor).isActive = true spaceBetweenLabels = messageLabel.topAnchor.constraint(equalTo: headlineLabel.bottomAnchor, constant: spaceBetweenLabelsConstant) spaceBetweenLabels?.isActive = true - leftConstraintTitle = headlineLabel.leftAnchor.constraint(equalTo: view.leftAnchor) - leftConstraintTitle?.isActive = true - - rightConstraintTitle = view.rightAnchor.constraint(equalTo: headlineLabel.rightAnchor) - rightConstraintTitle?.isActive = true - - 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 + NSLayoutConstraint.activate([ + headlineLabel.leadingAnchor.constraint(equalTo: leadingAnchor), + trailingAnchor.constraint(equalTo: headlineLabel.trailingAnchor), + messageLabel.leadingAnchor.constraint(equalTo: leadingAnchor), + trailingAnchor.constraint(equalTo: messageLabel.trailingAnchor), + bottomAnchor.constraint(equalTo: messageLabel.bottomAnchor) + ]) } open override func updateView(_ size: CGFloat) { super.updateView(size) + setSpacing() headlineLabel.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 //-------------------------------------------------- - public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { - return 58 - } + public override class func estimatedHeight(with model: MoleculeModelProtocol, + _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { 58 } public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { 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) - messageLabel.setOptional(with: headlineBodyModel.body, delegateObject, additionalData) + headlineLabel.setOptional(with: model.headline, delegateObject, additionalData) + messageLabel.setOptional(with: model.body, delegateObject, additionalData) } open override func reset() {