Merge branch 'feature/estimated_heights' into 'develop'

Feature/estimated heights

See merge request BPHV_MIPS/mvm_core_ui!93
This commit is contained in:
Pfeil, Scott Robert 2019-07-01 09:14:34 -04:00
commit 7fa0943a42
12 changed files with 77 additions and 16 deletions

View File

@ -139,4 +139,8 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI
open func alignment() -> UIStackView.Alignment { open func alignment() -> UIStackView.Alignment {
return UIStackView.Alignment.leading; return UIStackView.Alignment.leading;
} }
public static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
return 10
}
} }

View File

@ -146,6 +146,10 @@
} }
} }
+ (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject {
return 31;
}
#pragma mark - MVMCoreUIViewConstrainingProtocol #pragma mark - MVMCoreUIViewConstrainingProtocol
- (BOOL)needsToBeConstrained { - (BOOL)needsToBeConstrained {

View File

@ -184,6 +184,10 @@ import UIKit
addSizeConstraintsForAspectRatio = true addSizeConstraintsForAspectRatio = true
} }
public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
return json?.optionalCGFloatForKey("height") ?? 0
}
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
if let accessibilityString = json?.optionalStringForKey("accessibilityText") { if let accessibilityString = json?.optionalStringForKey("accessibilityText") {

View File

@ -78,6 +78,9 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
additionalData: additionalData]; additionalData: additionalData];
} }
+ (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject {
return CheckBoxHeightWidth;
}
#pragma mark - convenient class methods #pragma mark - convenient class methods

View File

@ -31,4 +31,6 @@ typedef void(^ValueChangeBlock)(void);
// Sets the state without triggering the value changed block. // Sets the state without triggering the value changed block.
- (void)setState:(BOOL)stateWithoutBlock withoutBlockAnimated:(BOOL)animated; - (void)setState:(BOOL)stateWithoutBlock withoutBlockAnimated:(BOOL)animated;
+ (CGFloat)getSwitchHeight;
@end @end

View File

@ -70,10 +70,6 @@
#pragma mark - set up #pragma mark - set up
- (void)reset {
[self setAsLight];
}
- (void)updateView:(CGFloat)size { - (void)updateView:(CGFloat)size {
[super updateView:size]; [super updateView:size];
self.height.constant = [self.heightSizeObject getValueBasedOnSize:size]; self.height.constant = [self.heightSizeObject getValueBasedOnSize:size];
@ -163,6 +159,10 @@
} }
#pragma mark - Molecule #pragma mark - Molecule
- (void)reset {
[self setAsLight];
}
- (BOOL)needsToBeConstrained { - (BOOL)needsToBeConstrained {
return YES; return YES;
@ -172,4 +172,19 @@
return NO; return NO;
} }
+ (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject {
NSString *type = [json string:KeyType];
if ([type isEqualToString:@"none"]) {
return 0;
} else {
if ([type isEqualToString:@"medium"]) {
return 2;
} else if ([type isEqualToString:@"heavy"]) {
return 4;
} else {
return 1;
}
}
}
@end @end

View File

@ -53,7 +53,7 @@ open class ModuleMolecule: ViewConstrainingView {
// Critical error // Critical error
return 0 return 0
} }
return MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.estimatedHeight?(forRow: module, delegateObject: delegateObject) ?? 80 return MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.estimatedHeight?(forRow: module, delegateObject: delegateObject) ?? 0
} }
public override static func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { public override static func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? {

View File

@ -218,8 +218,25 @@ public class MoleculeStackView: ViewConstrainingView {
} }
public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
// if horizontal, max, if vertical, append. guard let items = json?.optionalArrayForKey(KeyMolecules) else {
return 100 return 0
}
let horizontal = json?.optionalStringForKey("axis") == "horizontal"
var estimatedHeight: CGFloat = 0
for case let item as [AnyHashable: AnyHashable] in items {
if let molecule = item.optionalDictionaryForKey(KeyMolecule) {
let height = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: molecule)?.estimatedHeight?(forRow: molecule, delegateObject: delegateObject)
if !horizontal {
// Vertical stack aggregates the items
let spacing = item.optionalCGFloatForKey("spacing") ?? (estimatedHeight != 0 ? (json?.optionalCGFloatForKey("spacing") ?? 16) : 0)
estimatedHeight += ((height ?? 0) + spacing)
} else if let height = height {
// Horizontal stack takes the tallest item.
estimatedHeight = max(estimatedHeight, height)
}
}
}
return estimatedHeight
} }
public override static func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? { public override static func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {

View File

@ -131,7 +131,7 @@ import UIKit
guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule), let height = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: moleculeJSON)?.estimatedHeight?(forRow: moleculeJSON, delegateObject: delegateObject) else { guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule), let height = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: moleculeJSON)?.estimatedHeight?(forRow: moleculeJSON, delegateObject: delegateObject) else {
return 80 return 80
} }
return height return max(80, height)
} }
public static func name(forReuse molecule: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { public static func name(forReuse molecule: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? {

View File

@ -103,4 +103,8 @@ public class StandardFooterView: ViewConstrainingView {
twoButtonView.reset() twoButtonView.reset()
textButton.reset() textButton.reset()
} }
public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
return 42
}
} }

View File

@ -111,14 +111,6 @@ public class StandardHeaderView: ViewConstrainingView {
separatorView?.rightPin?.constant = constant separatorView?.rightPin?.constant = constant
} }
open override func reset() {
backgroundColor = .clear
headlineLabel.styleH2(true)
messageLabel.styleB2(true)
separatorView?.setAsHeavy()
separatorView?.show()
}
// MARK: - MVMCoreUIMoleculeViewProtocol // MARK: - MVMCoreUIMoleculeViewProtocol
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
@ -143,4 +135,16 @@ public class StandardHeaderView: ViewConstrainingView {
bottomPin?.constant = PaddingDefaultVerticalSpacing bottomPin?.constant = PaddingDefaultVerticalSpacing
} }
} }
open override func reset() {
backgroundColor = .clear
headlineLabel.styleH2(true)
messageLabel.styleB2(true)
separatorView?.setAsHeavy()
separatorView?.show()
}
public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
return 121
}
} }

View File

@ -83,5 +83,9 @@ import UIKit
public override func alignment() -> UIStackView.Alignment { public override func alignment() -> UIStackView.Alignment {
return UIStackView.Alignment.leading return UIStackView.Alignment.leading
} }
public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
return MVMCoreUISwitch.getHeight()
}
} }