From adaa9ca1f3c5fbf6e255c9ecfc489143bd9cede2 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 13 Feb 2020 10:45:00 -0500 Subject: [PATCH] Bug fixes --- .../Items => BaseClasses}/TableViewCell.swift | 23 +++++++++++++------ .../ThreeLayerTableViewController.swift | 2 ++ .../Views/Container/ContainerModel.swift | 5 ++-- .../ListItemModelProtocol.swift | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) rename MVMCoreUI/{Molecules/Items => BaseClasses}/TableViewCell.swift (96%) diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/BaseClasses/TableViewCell.swift similarity index 96% rename from MVMCoreUI/Molecules/Items/TableViewCell.swift rename to MVMCoreUI/BaseClasses/TableViewCell.swift index cd8a3cdf..fe06a05a 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/BaseClasses/TableViewCell.swift @@ -28,6 +28,8 @@ import UIKit private var heroAccessoryCenter: CGPoint? + private var initialSetupPerformed = false + // MARK: - Styling open func style(with styleString: String?) { guard let styleString = styleString else { @@ -102,12 +104,19 @@ import UIKit // MARK: - Inits public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) - setupView() + initialSetup() } public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) - setupView() + initialSetup() + } + + public func initialSetup() { + if !initialSetupPerformed { + initialSetupPerformed = true + setupView() + } } // MARK: - MFViewProtocol @@ -151,10 +160,6 @@ import UIKit self.listItemModel = model style(with: model.style) - if let backgroundColor = model.backgroundColor { - self.backgroundColor = backgroundColor.uiColor - } - // Add the caret if there is an action and it's not declared hidden. if !customAccessoryView { if let _ = model.action, !(model.hideArrow ?? false) { @@ -169,11 +174,15 @@ import UIKit addSeparatorsIfNeeded() bottomSeparatorView?.setWithModel(separator, nil, nil) } + + if let moleculeModel = model as? MoleculeModelProtocol, + let backgroundColor = moleculeModel.backgroundColor { + self.backgroundColor = backgroundColor.uiColor + } } open func reset() { molecule?.reset?() - styleStandard() backgroundColor = .white } diff --git a/MVMCoreUI/BaseControllers/ThreeLayerTableViewController.swift b/MVMCoreUI/BaseControllers/ThreeLayerTableViewController.swift index 3176df92..ae3d2fac 100644 --- a/MVMCoreUI/BaseControllers/ThreeLayerTableViewController.swift +++ b/MVMCoreUI/BaseControllers/ThreeLayerTableViewController.swift @@ -166,6 +166,8 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController { } // This extra view is needed because of the wonkiness of apple's table header. Things breaks if using autolayout. + headerView.setNeedsLayout() + headerView.layoutIfNeeded() MVMCoreUIUtility.sizeView(toFit: headerView) let tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: MVMCoreUIUtility.getWidth(), height: headerView.frame.height)) tableHeaderView.addSubview(headerView) diff --git a/MVMCoreUI/Containers/Views/Container/ContainerModel.swift b/MVMCoreUI/Containers/Views/Container/ContainerModel.swift index 1b721183..cdc6d743 100644 --- a/MVMCoreUI/Containers/Views/Container/ContainerModel.swift +++ b/MVMCoreUI/Containers/Views/Container/ContainerModel.swift @@ -48,7 +48,8 @@ public class ContainerModel: ContainerModelProtocol, Codable { try container.encodeIfPresent(ContainerHelper.getAlignmentString(for: horizontalAlignment), forKey: .horizontalAlignment) try container.encodeIfPresent(useHorizontalMargins, forKey: .useHorizontalMargins) try container.encodeIfPresent(useVerticalMargins, forKey: .useVerticalMargins) - try container.encodeIfPresent(topMarginPadding, forKey: .topMarginPadding) - try container.encodeIfPresent(bottomMarginPadding, forKey: .bottomMarginPadding) + // TODO: can add this back once we have type erasures. + //try container.encodeIfPresent(topMarginPadding, forKey: .topMarginPadding) + //try container.encodeIfPresent(bottomMarginPadding, forKey: .bottomMarginPadding) } } diff --git a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift index 020c3cbe..5d0fee08 100644 --- a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift @@ -9,7 +9,7 @@ import Foundation -public protocol ListItemModelProtocol: ContainerModelProtocol, MoleculeModelProtocol { +public protocol ListItemModelProtocol: ContainerModelProtocol { var line: LineModel? { get set } var action: ActionModelProtocol? { get set } var hideArrow: Bool? { get set }