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 {
|
- (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)]) {
|
if ([self.molecule respondsToSelector:@selector(copyBackgroundColor)] && [self.molecule performSelector:@selector(copyBackgroundColor)]) {
|
||||||
self.backgroundColor = self.molecule.backgroundColor;
|
self.backgroundColor = self.molecule.backgroundColor;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,6 +61,7 @@ extension View: MVMCoreViewProtocol {
|
|||||||
open func setupView() {
|
open func setupView() {
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
insetsLayoutMarginsFromSafeArea = false
|
insetsLayoutMarginsFromSafeArea = false
|
||||||
|
MVMCoreUIUtility.setMarginsFor(self, leading: 0, top: 0, trailing: 0, bottom: 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,13 +13,12 @@ import UIKit
|
|||||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||||
public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
super.setWithModel(model, delegateObject, additionalData)
|
super.setWithModel(model, delegateObject, additionalData)
|
||||||
|
guard let moleculeModel = (model as? ListItemModel)?.molecule else { return }
|
||||||
guard let model = model,
|
if molecule != nil {
|
||||||
let moleculeModel = (model as? ListItemModel)?.molecule,
|
(molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, additionalData)
|
||||||
let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) else {
|
} else if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) {
|
||||||
return
|
addMolecule(moleculeView)
|
||||||
}
|
}
|
||||||
addMolecule(moleculeView)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
public override class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||||
|
|||||||
@ -8,8 +8,8 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
@objcMembers public class CornerLabels: ViewConstrainingView, ModelMoleculeViewProtocol {
|
@objcMembers public class CornerLabels: View {
|
||||||
|
var middleView: UIView?
|
||||||
let topLeftLabel = Label.commonLabelB1(true)
|
let topLeftLabel = Label.commonLabelB1(true)
|
||||||
let topRightLabel = Label.commonLabelB1(true)
|
let topRightLabel = Label.commonLabelB1(true)
|
||||||
let bottomLeftLabel = Label.commonLabelB3(true)
|
let bottomLeftLabel = Label.commonLabelB3(true)
|
||||||
@ -38,18 +38,19 @@ import UIKit
|
|||||||
var topLabelToMoleculeConstraint: NSLayoutConstraint?
|
var topLabelToMoleculeConstraint: NSLayoutConstraint?
|
||||||
var bottomLabelToMoleculeConstraint: NSLayoutConstraint?
|
var bottomLabelToMoleculeConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
public override func addMolecule(_ molecule: UIView) {
|
public func addMiddleView(_ view: UIView) {
|
||||||
insertSubview(molecule, at: 0)
|
insertSubview(view, at: 0)
|
||||||
topLabelToMoleculeConstraint?.isActive = false
|
topLabelToMoleculeConstraint?.isActive = false
|
||||||
bottomLabelToMoleculeConstraint?.isActive = false
|
bottomLabelToMoleculeConstraint?.isActive = false
|
||||||
|
|
||||||
molecule.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor).isActive = true
|
view.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor).isActive = true
|
||||||
layoutMarginsGuide.rightAnchor.constraint(equalTo: molecule.rightAnchor).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
|
topLabelToMoleculeConstraint?.isActive = true
|
||||||
bottomLabelToMoleculeConstraint = bottomLabelsView.topAnchor.constraint(equalTo: molecule.bottomAnchor, constant: spaceBelowMolecule)
|
bottomLabelToMoleculeConstraint = bottomLabelsView.topAnchor.constraint(equalTo: view.bottomAnchor, constant: spaceBelowMolecule)
|
||||||
bottomLabelToMoleculeConstraint?.isActive = true
|
bottomLabelToMoleculeConstraint?.isActive = true
|
||||||
|
self.middleView = view
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MVMCoreViewProtocol
|
// MARK: - MVMCoreViewProtocol
|
||||||
@ -59,12 +60,11 @@ import UIKit
|
|||||||
topRightLabel.updateView(size)
|
topRightLabel.updateView(size)
|
||||||
bottomLeftLabel.updateView(size)
|
bottomLeftLabel.updateView(size)
|
||||||
bottomRightLabel.updateView(size)
|
bottomRightLabel.updateView(size)
|
||||||
|
(middleView as? MVMCoreViewProtocol)?.updateView(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func setupView() {
|
public override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
shouldSetupMoleculeFromJSON = true
|
|
||||||
|
|
||||||
guard topLeftLabel.superview == nil else {
|
guard topLeftLabel.superview == nil else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -141,17 +141,6 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
// 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() {
|
public override func setAsMolecule() {
|
||||||
super.setAsMolecule()
|
super.setAsMolecule()
|
||||||
styleDefault()
|
styleDefault()
|
||||||
@ -163,8 +152,7 @@ import UIKit
|
|||||||
styleDefault()
|
styleDefault()
|
||||||
spaceAboveMolecule = 6.0
|
spaceAboveMolecule = 6.0
|
||||||
spaceBelowMolecule = 6.0
|
spaceBelowMolecule = 6.0
|
||||||
|
(middleView as? MoleculeViewProtocol)?.reset?()
|
||||||
molecule?.reset?()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func styleDefault() {
|
func styleDefault() {
|
||||||
@ -174,23 +162,27 @@ import UIKit
|
|||||||
bottomRightLabel.styleB3(true)
|
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
|
return 34
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
guard let model = model as? CornerLabelsModel,
|
super.setWithModel(model, delegateObject, additionalData)
|
||||||
let data = try? model.encode(using: JSONEncoder()),
|
guard let model = model as? CornerLabelsModel else { return }
|
||||||
let json = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any] else {
|
if middleView != nil {
|
||||||
return
|
(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)
|
topLeftLabel.setWithModel(model.topLeftLabel, delegateObject, additionalData)
|
||||||
// topRightLabel.setWithModel(model.topRightLabel, delegateObject, additionalData)
|
topRightLabel.setWithModel(model.topRightLabel, delegateObject, additionalData)
|
||||||
// bottomLeftLabel.setWithModel(model.bottomLeftLabel, delegateObject, additionalData)
|
bottomLeftLabel.setWithModel(model.bottomLeftLabel, delegateObject, additionalData)
|
||||||
// bottomRightLabel.setWithModel(model.bottomRightLabel, delegateObject, additionalData)
|
bottomRightLabel.setWithModel(model.bottomRightLabel, delegateObject, additionalData)
|
||||||
//
|
|
||||||
// topLabelToMoleculeConstraint?.constant = (molecule != nil && (topLeftLabel.hasText || topRightLabel.hasText)) ? spaceAboveMolecule : 0
|
topLabelToMoleculeConstraint?.constant = (middleView != nil && (topLeftLabel.hasText || topRightLabel.hasText)) ? spaceAboveMolecule : 0
|
||||||
// bottomLabelToMoleculeConstraint?.constant = (molecule != nil && (bottomLeftLabel.hasText || bottomRightLabel.hasText)) ? spaceBelowMolecule : 0
|
bottomLabelToMoleculeConstraint?.constant = (middleView != nil && (bottomLeftLabel.hasText || bottomRightLabel.hasText)) ? spaceBelowMolecule : 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,11 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
open class MoleculeContainer: Container {
|
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]?) {
|
override public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
|
||||||
guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule) else {
|
guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule) else {
|
||||||
@ -31,7 +36,7 @@ open class MoleculeContainer: Container {
|
|||||||
(view as? ModelMoleculeViewProtocol)?.setWithModel(casteModel.molecule, delegateObject, additionalData)
|
(view as? ModelMoleculeViewProtocol)?.setWithModel(casteModel.molecule, delegateObject, additionalData)
|
||||||
} else {
|
} else {
|
||||||
if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(casteModel.molecule, delegateObject) {
|
if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(casteModel.molecule, delegateObject) {
|
||||||
addAndContain(molecule)
|
addMolecule(molecule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user