Merge branch 'feature/estimated_heights' into 'develop'
Feature/estimated heights See merge request BPHV_MIPS/mvm_core_ui!93
This commit is contained in:
commit
7fa0943a42
@ -139,4 +139,8 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI
|
||||
open func alignment() -> UIStackView.Alignment {
|
||||
return UIStackView.Alignment.leading;
|
||||
}
|
||||
|
||||
public static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||
return 10
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,6 +146,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject {
|
||||
return 31;
|
||||
}
|
||||
|
||||
#pragma mark - MVMCoreUIViewConstrainingProtocol
|
||||
|
||||
- (BOOL)needsToBeConstrained {
|
||||
|
||||
@ -184,6 +184,10 @@ import UIKit
|
||||
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]?) {
|
||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
if let accessibilityString = json?.optionalStringForKey("accessibilityText") {
|
||||
|
||||
@ -78,6 +78,9 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
|
||||
additionalData: additionalData];
|
||||
}
|
||||
|
||||
+ (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject {
|
||||
return CheckBoxHeightWidth;
|
||||
}
|
||||
|
||||
#pragma mark - convenient class methods
|
||||
|
||||
|
||||
@ -31,4 +31,6 @@ typedef void(^ValueChangeBlock)(void);
|
||||
// Sets the state without triggering the value changed block.
|
||||
- (void)setState:(BOOL)stateWithoutBlock withoutBlockAnimated:(BOOL)animated;
|
||||
|
||||
+ (CGFloat)getSwitchHeight;
|
||||
|
||||
@end
|
||||
|
||||
@ -70,10 +70,6 @@
|
||||
|
||||
#pragma mark - set up
|
||||
|
||||
- (void)reset {
|
||||
[self setAsLight];
|
||||
}
|
||||
|
||||
- (void)updateView:(CGFloat)size {
|
||||
[super updateView:size];
|
||||
self.height.constant = [self.heightSizeObject getValueBasedOnSize:size];
|
||||
@ -163,6 +159,10 @@
|
||||
}
|
||||
|
||||
#pragma mark - Molecule
|
||||
|
||||
- (void)reset {
|
||||
[self setAsLight];
|
||||
}
|
||||
|
||||
- (BOOL)needsToBeConstrained {
|
||||
return YES;
|
||||
@ -172,4 +172,19 @@
|
||||
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
|
||||
|
||||
@ -53,7 +53,7 @@ open class ModuleMolecule: ViewConstrainingView {
|
||||
// Critical error
|
||||
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? {
|
||||
|
||||
@ -218,8 +218,25 @@ public class MoleculeStackView: ViewConstrainingView {
|
||||
}
|
||||
|
||||
public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||
// if horizontal, max, if vertical, append.
|
||||
return 100
|
||||
guard let items = json?.optionalArrayForKey(KeyMolecules) else {
|
||||
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]? {
|
||||
|
||||
@ -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 {
|
||||
return 80
|
||||
}
|
||||
return height
|
||||
return max(80, height)
|
||||
}
|
||||
|
||||
public static func name(forReuse molecule: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
|
||||
@ -103,4 +103,8 @@ public class StandardFooterView: ViewConstrainingView {
|
||||
twoButtonView.reset()
|
||||
textButton.reset()
|
||||
}
|
||||
|
||||
public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||
return 42
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,14 +111,6 @@ public class StandardHeaderView: ViewConstrainingView {
|
||||
separatorView?.rightPin?.constant = constant
|
||||
}
|
||||
|
||||
open override func reset() {
|
||||
backgroundColor = .clear
|
||||
headlineLabel.styleH2(true)
|
||||
messageLabel.styleB2(true)
|
||||
separatorView?.setAsHeavy()
|
||||
separatorView?.show()
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
@ -143,4 +135,16 @@ public class StandardHeaderView: ViewConstrainingView {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,5 +83,9 @@ import UIKit
|
||||
public override func alignment() -> UIStackView.Alignment {
|
||||
return UIStackView.Alignment.leading
|
||||
}
|
||||
|
||||
public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||
return MVMCoreUISwitch.getHeight()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user