Digital PCT265 story ONEAPP-6389 - Button group size updates, title lockup like views font updates, label font updates

This commit is contained in:
Scott Pfeil 2024-03-12 13:47:48 -04:00
parent 9b831bfa35
commit 5c414a0e40
7 changed files with 53 additions and 14 deletions

View File

@ -9,17 +9,23 @@
import Foundation
import UIKit
import VDS
import Combine
@objcMembers open class ButtonGroup: VDS.ButtonGroup, VDSMoleculeViewProtocol {
open class ButtonGroup: VDS.ButtonGroup, VDSMoleculeViewProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public var model: MoleculeModelProtocol?
open var viewModel: ButtonGroupModel!
open var delegateObject: MVMCoreUIDelegateObject?
open var additionalData: [AnyHashable : Any]?
open var previousModel: ButtonGroupModel?
/// For notifying the delegate of layout updates.
private var contentSizeObservation: Cancellable?
private var previousSize: CGSize?
//--------------------------------------------------
// MARK: - MoleculeViewProtocol
//--------------------------------------------------
@ -74,6 +80,15 @@ import VDS
// force redraw
setNeedsUpdate()
}
// Notify the delegate of a size change.
previousSize = bounds.size
contentSizeObservation = contentSizePublisher.sink { [weak self] size in
guard let self = self,
!MVMCoreGetterUtility.fequal(a: Float(size.height), b: Float(self.previousSize?.height ?? Self.estimatedHeight(with: self.viewModel, self.delegateObject) ?? VDS.Button.Size.large.height)) else { return }
self.previousSize = size
self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
}
}
//--------------------------------------------------

View File

@ -31,7 +31,7 @@ open class HeaderView: Container {
(molecule as? MVMCoreViewProtocol)?.updateView(size)
}
public override func setupView() {
open override func setupView() {
super.setupView()
line.setStyle(.none)
addSubview(line)

View File

@ -7,9 +7,9 @@
//
@objcMembers public class HeaderModel: ContainerModel {
public var backgroundColor: Color?
public var line: LineModel?
open class HeaderModel: ContainerModel {
open var backgroundColor: Color?
open var line: LineModel?
private enum CodingKeys: String, CodingKey {
case line
@ -17,7 +17,7 @@
}
/// Defaults to set
public override func setDefaults() {
open override func setDefaults() {
if useHorizontalMargins == nil {
useHorizontalMargins = true
}
@ -43,7 +43,7 @@
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
}
public override func encode(to encoder: Encoder) throws {
open override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(line, forKey: .line)

View File

@ -14,7 +14,7 @@
public let stack = Stack<StackModel>(frame: .zero)
public let eyebrow = Label(fontStyle: .RegularMicro)
public let headline = Label(fontStyle: .BoldBodySmall)
public let headline = Label(fontStyle: .RegularTitleSmall)
public let body = Label(fontStyle: .RegularBodySmall, true)
public let link = Link()
@ -58,7 +58,7 @@
super.reset()
stack.reset()
eyebrow.setFontStyle(.RegularMicro)
headline.setFontStyle(.BoldBodySmall)
headline.setFontStyle(.RegularTitleSmall)
body.setFontStyle(.RegularBodySmall)
}

View File

@ -60,9 +60,9 @@ open class HeadlineBody: View {
}
public func stylePageHeader() {
headlineLabel.setFontStyle(.RegularTitleLarge)
messageLabel.setFontStyle(.RegularBodyLarge)
spaceBetweenLabelsConstant = Padding.Two
headlineLabel.setFontStyle(.RegularTitleXLarge)
messageLabel.setFontStyle(.RegularTitleMedium)
spaceBetweenLabelsConstant = Padding.Four
}
public func styleListItem() {
@ -72,8 +72,8 @@ open class HeadlineBody: View {
}
public func styleListItemDivider() {
headlineLabel.setFontStyle(.BoldTitleSmall)
messageLabel.setFontStyle(.RegularBodySmall)
headlineLabel.setFontStyle(.BoldTitleLarge)
messageLabel.setFontStyle(.RegularBodyLarge)
spaceBetweenLabelsConstant = Padding.Two
}

View File

@ -21,7 +21,9 @@ public protocol VDSMoleculeViewProtocol: MoleculeViewProtocol, MVMCoreViewProtoc
}
extension VDSMoleculeViewProtocol {
public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
self.model = model
guard let castedModel = model as? ViewModel else { return }
self.delegateObject = delegateObject
self.additionalData = additionalData

View File

@ -198,7 +198,29 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
open override func moleculeLayoutUpdated(_ molecule: MoleculeViewProtocol) {
guard let tableView = tableView else { return }
let id = molecule.model?.id
// Check for header
var inHeaderOrFooter = false
if let _ = templateModel?.header?.findFirstMolecule(by: { compareModel in id == compareModel.id }) {
showHeader(nil)
inHeaderOrFooter = true
}
// Check for footer
if let _ = templateModel?.footer?.findFirstMolecule(by: { compareModel in id == compareModel.id }) {
showFooter(nil)
inHeaderOrFooter = true
}
// If the view is in a header or footer, need to update the constraints.
if inHeaderOrFooter {
view.setNeedsUpdateConstraints()
view.updateConstraintsIfNeeded()
return
}
// If the view is in a cell, refresh the table ui.
let point = molecule.convert(molecule.bounds.origin, to: tableView)
if let indexPath = tableView.indexPathForRow(at: point), tableView.indexPathsForVisibleRows?.contains(indexPath) ?? false {
refreshTable()