List item updates

This commit is contained in:
Pfeil, Scott Robert 2019-12-16 13:40:04 -05:00
parent f610264327
commit 092dfd6ad0
5 changed files with 41 additions and 34 deletions

View File

@ -664,6 +664,7 @@
}
- (void)setAsMolecule {
self.translatesAutoresizingMaskIntoConstraints = false;
[self setAsStandardCustom];
}
@ -713,6 +714,10 @@
[self setWithActionMap:json delegateObject:delegateObject additionalData:additionalData];
}
- (UIStackViewAlignment)horizontalAlignment {
return UIStackViewAlignmentCenter;
}
#pragma mark - Handling Validations
- (void)setEnabledByValidity {

View File

@ -168,6 +168,20 @@ public class ContainerHelper: NSObject {
return nil
}
}
func set(with JSON: [AnyHashable: Any]?, for contained: UIView) {
if let horizontalAlignmentString = JSON?.optionalStringForKey("horizontalAlignment"), let alignment = ContainerHelper.getAlignment(for: horizontalAlignmentString) ?? (contained as? MVMCoreUIViewConstrainingProtocol)?.horizontalAlignment?() {
alignHorizontal(alignment)
} else if let alignment = (contained as? MVMCoreUIViewConstrainingProtocol)?.horizontalAlignment?() {
alignHorizontal(alignment)
}
if let verticalAlignmentString = JSON?.optionalStringForKey("verticalAlignment"), let alignment = ContainerHelper.getAlignment(for: verticalAlignmentString) ?? (contained as? MVMCoreUIViewConstrainingProtocol)?.verticalAlignment?() {
alignVertical(alignment)
} else if let alignment = (contained as? MVMCoreUIViewConstrainingProtocol)?.verticalAlignment?() {
alignVertical(alignment)
}
}
}
open class Container: View {
@ -194,6 +208,7 @@ public extension Container {
}
func addAndContain(_ view: UIView) {
view.translatesAutoresizingMaskIntoConstraints = false
addSubview(view)
containerHelper.constrainView(view)
self.view = view
@ -209,18 +224,8 @@ public extension Container {
public extension Container {
override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
if let horizontalAlignmentString = json?.optionalStringForKey("horizontalAlignment"), let alignment = ContainerHelper.getAlignment(for: horizontalAlignmentString) ?? (view as? MVMCoreUIViewConstrainingProtocol)?.horizontalAlignment?() {
containerHelper.alignHorizontal(alignment)
} else if let alignment = (view as? MVMCoreUIViewConstrainingProtocol)?.horizontalAlignment?() {
containerHelper.alignHorizontal(alignment)
}
if let verticalAlignmentString = json?.optionalStringForKey("verticalAlignment"), let alignment = ContainerHelper.getAlignment(for: verticalAlignmentString) ?? (view as? MVMCoreUIViewConstrainingProtocol)?.verticalAlignment?() {
containerHelper.alignVertical(alignment)
} else if let alignment = (view as? MVMCoreUIViewConstrainingProtocol)?.verticalAlignment?() {
containerHelper.alignVertical(alignment)
}
guard let view = view else { return }
containerHelper.set(with: json, for: view)
}
override func reset() {

View File

@ -11,11 +11,20 @@ import UIKit
@objcMembers open class MoleculeTableViewCell: TableViewCell {
// MARK: - MVMCoreUIMoleculeViewProtocol
public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?)
{
guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule) else {
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
return
}
if molecule == nil {
if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: false) {
addMolecule(moleculeView)
}
} else {
molecule?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData)
}
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
guard molecule == nil, let json = json, let moleculeJSON = json.optionalDictionaryForKey(KeyMolecule), let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) else { return }
addMolecule(moleculeView)
}
public override class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {

View File

@ -11,7 +11,8 @@ import UIKit
@objcMembers open class TableViewCell: UITableViewCell, MVMCoreUIMoleculeViewProtocol, MoleculeListCellProtocol {
open var molecule: (UIView & MVMCoreUIMoleculeViewProtocol)?
open var json: [AnyHashable: Any]?
public let containerHelper = ContainerHelper()
// In updateView, will set padding to default.
open var updateViewHorizontalDefaults = true
@ -78,14 +79,7 @@ import UIKit
/// Adds the molecule to the view.
open func addMolecule(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) {
contentView.addSubview(molecule)
let standardConstraints = (molecule as? MVMCoreUIViewConstrainingProtocol)?.useStandardConstraints?() ?? true
NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: molecule, useMargins: standardConstraints).values))
// This molecule will by default handle margins.
if let castView = molecule as? MVMCoreUIViewConstrainingProtocol {
castView.shouldSetHorizontalMargins?(false)
castView.shouldSetVerticalMargins?(false)
}
containerHelper.constrainView(molecule)
self.molecule = molecule
}
@ -176,14 +170,8 @@ import UIKit
bottomSeparatorView?.setWithJSON(separator, delegateObject: delegateObject, additionalData: additionalData)
}
guard let moleculeJSON = json.optionalDictionaryForKey(KeyMolecule) else { return }
molecule?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData)
// This molecule will by default handle margins.
if let castView = molecule as? MVMCoreUIViewConstrainingProtocol {
castView.shouldSetHorizontalMargins?(false)
castView.shouldSetVerticalMargins?(false)
}
guard let molecule = molecule else { return }
containerHelper.set(with: json, for: molecule)
}
public func reset() {

View File

@ -27,7 +27,7 @@
mapping = [@{
@"label": Label.class,
@"line": Line.class,
@"button": ButtonView.class,
@"button": PrimaryButton.class,
@"textButton": MFTextButton.class,
@"header": StandardHeaderView.class,
@"moleculeStack": MoleculeStackView.class,