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.
open var updateViewHorizontalDefaults = true
open var updateViewVerticalDefaults = true
// For the accessory view convenience.
public var caretView: CaretView?
@ -35,6 +34,45 @@ import UIKit
/// For subclasses that want to use a custom accessory view.
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
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
@ -48,7 +86,7 @@ import UIKit
// MARK: - MFViewProtocol
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 accessoryView != nil {
// Smaller left margin if accessory view.
@ -94,11 +132,14 @@ import UIKit
public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
self.json = json;
style(with: json?.optionalStringForKey("style"))
if let useHorizontalMargins = json?.optionalBoolForKey("useHorizontalMargins") {
updateViewHorizontalDefaults = useHorizontalMargins
}
if let useVerticalMargins = json?.optionalBoolForKey("useVerticalMargins") {
updateViewVerticalDefaults = useVerticalMargins
if json?.optionalBoolForKey("useVerticalMargins") ?? false {
topMarginPadding = 0
bottomMarginPadding = 0
}
if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) {
@ -143,8 +184,8 @@ import UIKit
public func reset() {
molecule?.reset?()
updateViewVerticalDefaults = true
updateViewHorizontalDefaults = true
styleStandard()
backgroundColor = .white
}

View File

@ -18,6 +18,24 @@ open class HeadlineBody: ViewConstrainingView {
var leftConstraintMessage: 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() {
headlineLabel.styleH1(true)
messageLabel.styleB2(true)
@ -35,10 +53,6 @@ open class HeadlineBody: ViewConstrainingView {
messageLabel.styleB2(true)
spaceBetweenLabelsConstant = 0
}
func hasText() -> Bool {
return headlineLabel.hasText || messageLabel.hasText
}
// MARK: - MVMCoreViewProtocol
open override func updateView(_ size: CGFloat) {
@ -109,6 +123,8 @@ open class HeadlineBody: ViewConstrainingView {
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
style(with: json?.optionalStringForKey("style"))
let headlineJSON = json?.optionalDictionaryForKey("headline")
headlineLabel.setWithJSON(headlineJSON, delegateObject: delegateObject, additionalData: additionalData)
let bodyJSON = json?.optionalDictionaryForKey("body")

View File

@ -93,6 +93,7 @@ B3 -> Legal
+ (CGFloat)defaultVerticalPaddingForSize:(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)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

View File

@ -96,13 +96,20 @@ CGFloat const LabelWithInternalButtonLineSpace = 2;
}
+ (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:^{
CGFloat horizontalPadding = horizontal ? [MFStyler defaultHorizontalPaddingForSize:size] : 0;
CGFloat verticalPadding = vertical ? PaddingDefaultVerticalSpacing3 : 0;
[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
+ (nullable UIFont *)fontH1:(BOOL)genericScaling {