This commit is contained in:
Pfeil, Scott Robert 2019-09-04 13:45:41 -04:00
parent d1d0b07c8a
commit 3ff48cf700
4 changed files with 76 additions and 11 deletions

View File

@ -15,7 +15,6 @@ import UIKit
// In updateView, will set padding to default. // In updateView, will set padding to default.
open var updateViewHorizontalDefaults = true open var updateViewHorizontalDefaults = true
open var updateViewVerticalDefaults = true
// For the accessory view convenience. // For the accessory view convenience.
public var caretView: CaretView? public var caretView: CaretView?
@ -35,6 +34,45 @@ import UIKit
/// For subclasses that want to use a custom accessory view. /// For subclasses that want to use a custom accessory view.
open var customAccessoryView = false open var customAccessoryView = false
public var topMarginPadding: CGFloat = 24
public var bottomMarginPadding: CGFloat = 24
// MARK: - Styling
func style(with styleString: String?) {
guard let styleString = styleString else {
return
}
switch styleString {
case "standard":
styleStandard()
case "header":
styleHeader()
case "none":
styleNone()
default: break
}
}
func styleStandard() {
topMarginPadding = 24
bottomMarginPadding = 24
bottomSeparatorView?.show()
bottomSeparatorView?.setAsLight()
}
func styleHeader() {
topMarginPadding = 48
bottomMarginPadding = 16
bottomSeparatorView?.show()
bottomSeparatorView?.setAsRegular()
}
func styleNone() {
topMarginPadding = 0
bottomMarginPadding = 0
bottomSeparatorView?.hide()
}
// MARK: - Inits // MARK: - Inits
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier) super.init(style: style, reuseIdentifier: reuseIdentifier)
@ -48,7 +86,7 @@ import UIKit
// MARK: - MFViewProtocol // MARK: - MFViewProtocol
public func updateView(_ size: CGFloat) { public func updateView(_ size: CGFloat) {
MFStyler.setDefaultMarginsFor(self, size: size, horizontal: updateViewHorizontalDefaults, vertical: updateViewVerticalDefaults) MFStyler.setMarginsFor(self, size: size, defaultHorizontal: updateViewHorizontalDefaults, top: topMarginPadding, bottom: bottomMarginPadding)
if #available(iOS 11.0, *) { if #available(iOS 11.0, *) {
if accessoryView != nil { if accessoryView != nil {
// Smaller left margin if accessory view. // Smaller left margin if accessory view.
@ -94,11 +132,14 @@ import UIKit
public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
self.json = json; self.json = json;
style(with: json?.optionalStringForKey("style"))
if let useHorizontalMargins = json?.optionalBoolForKey("useHorizontalMargins") { if let useHorizontalMargins = json?.optionalBoolForKey("useHorizontalMargins") {
updateViewHorizontalDefaults = useHorizontalMargins updateViewHorizontalDefaults = useHorizontalMargins
} }
if let useVerticalMargins = json?.optionalBoolForKey("useVerticalMargins") { if json?.optionalBoolForKey("useVerticalMargins") ?? false {
updateViewVerticalDefaults = useVerticalMargins topMarginPadding = 0
bottomMarginPadding = 0
} }
if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) { if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) {
@ -143,8 +184,8 @@ import UIKit
public func reset() { public func reset() {
molecule?.reset?() molecule?.reset?()
updateViewVerticalDefaults = true
updateViewHorizontalDefaults = true updateViewHorizontalDefaults = true
styleStandard()
backgroundColor = .white backgroundColor = .white
} }

View File

@ -18,6 +18,24 @@ open class HeadlineBody: ViewConstrainingView {
var leftConstraintMessage: NSLayoutConstraint? var leftConstraintMessage: NSLayoutConstraint?
var rightConstraintMessage: NSLayoutConstraint? var rightConstraintMessage: NSLayoutConstraint?
func hasText() -> Bool {
return headlineLabel.hasText || messageLabel.hasText
}
// MARK: - Styling
func style(with styleString: String?) {
guard let styleString = styleString else {
return
}
switch styleString {
case "header":
stylePageHeader()
case "item":
styleListItem()
default: break
}
}
func styleLandingPageHeader() { func styleLandingPageHeader() {
headlineLabel.styleH1(true) headlineLabel.styleH1(true)
messageLabel.styleB2(true) messageLabel.styleB2(true)
@ -36,10 +54,6 @@ open class HeadlineBody: ViewConstrainingView {
spaceBetweenLabelsConstant = 0 spaceBetweenLabelsConstant = 0
} }
func hasText() -> Bool {
return headlineLabel.hasText || messageLabel.hasText
}
// MARK: - MVMCoreViewProtocol // MARK: - MVMCoreViewProtocol
open override func updateView(_ size: CGFloat) { open override func updateView(_ size: CGFloat) {
super.updateView(size) super.updateView(size)
@ -109,6 +123,8 @@ open class HeadlineBody: ViewConstrainingView {
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)
style(with: json?.optionalStringForKey("style"))
let headlineJSON = json?.optionalDictionaryForKey("headline") let headlineJSON = json?.optionalDictionaryForKey("headline")
headlineLabel.setWithJSON(headlineJSON, delegateObject: delegateObject, additionalData: additionalData) headlineLabel.setWithJSON(headlineJSON, delegateObject: delegateObject, additionalData: additionalData)
let bodyJSON = json?.optionalDictionaryForKey("body") let bodyJSON = json?.optionalDictionaryForKey("body")

View File

@ -93,6 +93,7 @@ B3 -> Legal
+ (CGFloat)defaultVerticalPaddingForSize:(CGFloat)size; + (CGFloat)defaultVerticalPaddingForSize:(CGFloat)size;
+ (void)setDefaultMarginsForView:(nullable UIView *)view size:(CGFloat)size; + (void)setDefaultMarginsForView:(nullable UIView *)view size:(CGFloat)size;
+ (void)setDefaultMarginsForView:(nullable UIView *)view size:(CGFloat)size horizontal:(BOOL)horizontal vertical:(BOOL)vertical; + (void)setDefaultMarginsForView:(nullable UIView *)view size:(CGFloat)size horizontal:(BOOL)horizontal vertical:(BOOL)vertical;
+ (void)setMarginsForView:(nullable UIView *)view size:(CGFloat)size defaultHorizontal:(BOOL)horizontal top:(CGFloat)top bottom:(CGFloat)bottom;
//------------------------------------------------- //-------------------------------------------------
// Returns the fonts for these styles. Scales them as needed by default // Returns the fonts for these styles. Scales them as needed by default

View File

@ -96,13 +96,20 @@ CGFloat const LabelWithInternalButtonLineSpace = 2;
} }
+ (void)setDefaultMarginsForView:(nullable UIView *)view size:(CGFloat)size horizontal:(BOOL)horizontal vertical:(BOOL)vertical { + (void)setDefaultMarginsForView:(nullable UIView *)view size:(CGFloat)size horizontal:(BOOL)horizontal vertical:(BOOL)vertical {
CGFloat horizontalPadding = horizontal ? [MFStyler defaultHorizontalPaddingForSize:size] : 0;
CGFloat verticalPadding = vertical ? PaddingDefaultVerticalSpacing3 : 0;
[MVMCoreDispatchUtility performBlockOnMainThread:^{ [MVMCoreDispatchUtility performBlockOnMainThread:^{
CGFloat horizontalPadding = horizontal ? [MFStyler defaultHorizontalPaddingForSize:size] : 0;
CGFloat verticalPadding = vertical ? PaddingDefaultVerticalSpacing3 : 0;
[MVMCoreUIUtility setMarginsForView:view leading:horizontalPadding top:verticalPadding trailing:horizontalPadding bottom:verticalPadding]; [MVMCoreUIUtility setMarginsForView:view leading:horizontalPadding top:verticalPadding trailing:horizontalPadding bottom:verticalPadding];
}]; }];
} }
+ (void)setMarginsForView:(nullable UIView *)view size:(CGFloat)size defaultHorizontal:(BOOL)horizontal top:(CGFloat)top bottom:(CGFloat)bottom {
CGFloat horizontalPadding = horizontal ? [MFStyler defaultHorizontalPaddingForSize:size] : 0;
[MVMCoreDispatchUtility performBlockOnMainThread:^{
[MVMCoreUIUtility setMarginsForView:view leading:horizontalPadding top:top trailing:horizontalPadding bottom:bottom];
}];
}
#pragma mark - 2.0 fonts #pragma mark - 2.0 fonts
+ (nullable UIFont *)fontH1:(BOOL)genericScaling { + (nullable UIFont *)fontH1:(BOOL)genericScaling {