undo view constraining removal code
fix molecule table cell fix corner labels
This commit is contained in:
parent
a204603616
commit
3d2fd02ac5
@ -352,6 +352,45 @@
|
||||
}
|
||||
|
||||
- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
|
||||
// Only treated as a container if we are constraining a molecule.
|
||||
if (!self.constrainedView) {
|
||||
[super setWithJSON:json delegateObject:delegateObject additionalData:additionalData];
|
||||
}
|
||||
if (self.shouldSetupMoleculeFromJSON) {
|
||||
NSDictionary *moleculeJSON = [json dict:KeyMolecule];
|
||||
if (self.molecule) {
|
||||
[self.molecule setWithJSON:moleculeJSON delegateObject:delegateObject additionalData:additionalData];
|
||||
} else if (moleculeJSON) {
|
||||
UIView <MVMCoreUIMoleculeViewProtocol>*molecule = [[MVMCoreUIMoleculeMappingObject sharedMappingObject] createMoleculeForJSON:moleculeJSON delegateObject:delegateObject constrainIfNeeded:true];
|
||||
if (molecule) {
|
||||
[self addMolecule:molecule];
|
||||
}
|
||||
self.molecule = molecule;
|
||||
[self setMoleculeAccessibility];
|
||||
}
|
||||
} else {
|
||||
[self.molecule setWithJSON:json delegateObject:delegateObject additionalData:additionalData];
|
||||
}
|
||||
|
||||
NSNumber *useHorizontalMargins = [json optionalNumberForKey:@"useHorizontalMargins"];
|
||||
if (useHorizontalMargins) {
|
||||
self.updateViewHorizontalDefaults = [useHorizontalMargins boolValue];
|
||||
}
|
||||
NSNumber *useVerticalMargins = [json optionalNumberForKey:@"useVerticalMargins"];
|
||||
if (useVerticalMargins) {
|
||||
self.updateViewVerticalDefaults = [useVerticalMargins boolValue];
|
||||
}
|
||||
|
||||
// Set the alignment for the stack in the containing view. The json driven value is for the axis direction alignment.
|
||||
NSString *alignment = [json string:@"horizontalAlignment"];
|
||||
if (alignment) {
|
||||
[self alignHorizontal:[ViewConstrainingView getAlignmentForString:alignment defaultAlignment:UIStackViewAlignmentFill]];
|
||||
}
|
||||
alignment = [json string:@"verticalAlignment"];
|
||||
if (alignment) {
|
||||
[self alignVertical:[ViewConstrainingView getAlignmentForString:alignment defaultAlignment:UIStackViewAlignmentFill]];
|
||||
}
|
||||
|
||||
if ([self.molecule respondsToSelector:@selector(copyBackgroundColor)] && [self.molecule performSelector:@selector(copyBackgroundColor)]) {
|
||||
self.backgroundColor = self.molecule.backgroundColor;
|
||||
}
|
||||
|
||||
@ -61,6 +61,7 @@ extension View: MVMCoreViewProtocol {
|
||||
open func setupView() {
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
insetsLayoutMarginsFromSafeArea = false
|
||||
MVMCoreUIUtility.setMarginsFor(self, leading: 0, top: 0, trailing: 0, bottom: 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -13,13 +13,12 @@ import UIKit
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
super.setWithModel(model, delegateObject, additionalData)
|
||||
|
||||
guard let model = model,
|
||||
let moleculeModel = (model as? ListItemModel)?.molecule,
|
||||
let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) else {
|
||||
return
|
||||
guard let moleculeModel = (model as? ListItemModel)?.molecule else { return }
|
||||
if molecule != nil {
|
||||
(molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, additionalData)
|
||||
} else if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) {
|
||||
addMolecule(moleculeView)
|
||||
}
|
||||
addMolecule(moleculeView)
|
||||
}
|
||||
|
||||
public override class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
|
||||
@ -8,8 +8,8 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
@objcMembers public class CornerLabels: ViewConstrainingView, ModelMoleculeViewProtocol {
|
||||
|
||||
@objcMembers public class CornerLabels: View {
|
||||
var middleView: UIView?
|
||||
let topLeftLabel = Label.commonLabelB1(true)
|
||||
let topRightLabel = Label.commonLabelB1(true)
|
||||
let bottomLeftLabel = Label.commonLabelB3(true)
|
||||
@ -38,18 +38,19 @@ import UIKit
|
||||
var topLabelToMoleculeConstraint: NSLayoutConstraint?
|
||||
var bottomLabelToMoleculeConstraint: NSLayoutConstraint?
|
||||
|
||||
public override func addMolecule(_ molecule: UIView) {
|
||||
insertSubview(molecule, at: 0)
|
||||
public func addMiddleView(_ view: UIView) {
|
||||
insertSubview(view, at: 0)
|
||||
topLabelToMoleculeConstraint?.isActive = false
|
||||
bottomLabelToMoleculeConstraint?.isActive = false
|
||||
|
||||
molecule.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor).isActive = true
|
||||
layoutMarginsGuide.rightAnchor.constraint(equalTo: molecule.rightAnchor).isActive = true
|
||||
view.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor).isActive = true
|
||||
layoutMarginsGuide.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
|
||||
|
||||
topLabelToMoleculeConstraint = molecule.topAnchor.constraint(equalTo: topLabelsView.bottomAnchor, constant: spaceAboveMolecule)
|
||||
topLabelToMoleculeConstraint = view.topAnchor.constraint(equalTo: topLabelsView.bottomAnchor, constant: spaceAboveMolecule)
|
||||
topLabelToMoleculeConstraint?.isActive = true
|
||||
bottomLabelToMoleculeConstraint = bottomLabelsView.topAnchor.constraint(equalTo: molecule.bottomAnchor, constant: spaceBelowMolecule)
|
||||
bottomLabelToMoleculeConstraint = bottomLabelsView.topAnchor.constraint(equalTo: view.bottomAnchor, constant: spaceBelowMolecule)
|
||||
bottomLabelToMoleculeConstraint?.isActive = true
|
||||
self.middleView = view
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreViewProtocol
|
||||
@ -59,12 +60,11 @@ import UIKit
|
||||
topRightLabel.updateView(size)
|
||||
bottomLeftLabel.updateView(size)
|
||||
bottomRightLabel.updateView(size)
|
||||
(middleView as? MVMCoreViewProtocol)?.updateView(size)
|
||||
}
|
||||
|
||||
public override func setupView() {
|
||||
super.setupView()
|
||||
shouldSetupMoleculeFromJSON = true
|
||||
|
||||
guard topLeftLabel.superview == nil else {
|
||||
return
|
||||
}
|
||||
@ -141,17 +141,6 @@ import UIKit
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
topLeftLabel.setWithJSON(json?.optionalDictionaryForKey("topLeftLabel"), delegateObject: delegateObject, additionalData: additionalData)
|
||||
topRightLabel.setWithJSON(json?.optionalDictionaryForKey("topRightLabel"), delegateObject: delegateObject, additionalData: additionalData)
|
||||
bottomLeftLabel.setWithJSON(json?.optionalDictionaryForKey("bottomLeftLabel"), delegateObject: delegateObject, additionalData: additionalData)
|
||||
bottomRightLabel.setWithJSON(json?.optionalDictionaryForKey("bottomRightLabel"), delegateObject: delegateObject, additionalData: additionalData)
|
||||
|
||||
topLabelToMoleculeConstraint?.constant = (molecule != nil && (topLeftLabel.hasText || topRightLabel.hasText)) ? spaceAboveMolecule : 0
|
||||
bottomLabelToMoleculeConstraint?.constant = (molecule != nil && (bottomLeftLabel.hasText || bottomRightLabel.hasText)) ? spaceBelowMolecule : 0
|
||||
}
|
||||
|
||||
public override func setAsMolecule() {
|
||||
super.setAsMolecule()
|
||||
styleDefault()
|
||||
@ -163,8 +152,7 @@ import UIKit
|
||||
styleDefault()
|
||||
spaceAboveMolecule = 6.0
|
||||
spaceBelowMolecule = 6.0
|
||||
|
||||
molecule?.reset?()
|
||||
(middleView as? MoleculeViewProtocol)?.reset?()
|
||||
}
|
||||
|
||||
func styleDefault() {
|
||||
@ -174,23 +162,27 @@ import UIKit
|
||||
bottomRightLabel.styleB3(true)
|
||||
}
|
||||
|
||||
public override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||
public class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||
return 34
|
||||
}
|
||||
|
||||
public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
guard let model = model as? CornerLabelsModel,
|
||||
let data = try? model.encode(using: JSONEncoder()),
|
||||
let json = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any] else {
|
||||
return
|
||||
public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
super.setWithModel(model, delegateObject, additionalData)
|
||||
guard let model = model as? CornerLabelsModel else { return }
|
||||
if middleView != nil {
|
||||
(middleView as? ModelMoleculeViewProtocol)?.setWithModel(model, delegateObject, additionalData)
|
||||
} else {
|
||||
if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(model.molecule, delegateObject) {
|
||||
addMiddleView(molecule)
|
||||
}
|
||||
}
|
||||
self.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
// topLeftLabel.setWithModel(model.topLeftLabel, delegateObject, additionalData)
|
||||
// topRightLabel.setWithModel(model.topRightLabel, delegateObject, additionalData)
|
||||
// bottomLeftLabel.setWithModel(model.bottomLeftLabel, delegateObject, additionalData)
|
||||
// bottomRightLabel.setWithModel(model.bottomRightLabel, delegateObject, additionalData)
|
||||
//
|
||||
// topLabelToMoleculeConstraint?.constant = (molecule != nil && (topLeftLabel.hasText || topRightLabel.hasText)) ? spaceAboveMolecule : 0
|
||||
// bottomLabelToMoleculeConstraint?.constant = (molecule != nil && (bottomLeftLabel.hasText || bottomRightLabel.hasText)) ? spaceBelowMolecule : 0
|
||||
|
||||
topLeftLabel.setWithModel(model.topLeftLabel, delegateObject, additionalData)
|
||||
topRightLabel.setWithModel(model.topRightLabel, delegateObject, additionalData)
|
||||
bottomLeftLabel.setWithModel(model.bottomLeftLabel, delegateObject, additionalData)
|
||||
bottomRightLabel.setWithModel(model.bottomRightLabel, delegateObject, additionalData)
|
||||
|
||||
topLabelToMoleculeConstraint?.constant = (middleView != nil && (topLeftLabel.hasText || topRightLabel.hasText)) ? spaceAboveMolecule : 0
|
||||
bottomLabelToMoleculeConstraint?.constant = (middleView != nil && (bottomLeftLabel.hasText || bottomRightLabel.hasText)) ? spaceBelowMolecule : 0
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,11 @@
|
||||
import UIKit
|
||||
|
||||
open class MoleculeContainer: Container {
|
||||
|
||||
/// Can be overriden to change how the molecule is added to the hierarchy.
|
||||
public func addMolecule(_ molecule: UIView) {
|
||||
addAndContain(molecule)
|
||||
}
|
||||
|
||||
override public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
|
||||
guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule) else {
|
||||
@ -31,7 +36,7 @@ open class MoleculeContainer: Container {
|
||||
(view as? ModelMoleculeViewProtocol)?.setWithModel(casteModel.molecule, delegateObject, additionalData)
|
||||
} else {
|
||||
if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(casteModel.molecule, delegateObject) {
|
||||
addAndContain(molecule)
|
||||
addMolecule(molecule)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user