merging from develop

This commit is contained in:
Kevin G Christiano 2020-02-17 14:20:17 -05:00
commit db74add496
12 changed files with 125 additions and 115 deletions

View File

@ -37,7 +37,7 @@ import Foundation
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case backgroundColor case backgroundColor
case title case title = "label"
case isEnabled case isEnabled
case feedback case feedback
case errorMessage = "errorMsg" case errorMessage = "errorMsg"

View File

@ -9,36 +9,52 @@
import Foundation import Foundation
public extension NSLayoutConstraint { public extension NSLayoutConstraint {
static func pinSubviewsCenter(leftView: UIView, rightView: UIView) {
guard let superView = leftView.superview else { /// Pins the views vertically in the super view, allowing the super to expand depending on the tallest view. Shorter views are aligned center.
return static func pinViewsVerticalExpandableAlignCenter(_ views: [UIView]) {
for view in views {
guard let superView = view.superview else {
return
}
view.centerYAnchor.constraint(equalTo: superView.centerYAnchor).isActive = true
view.topAnchor.constraint(greaterThanOrEqualTo: superView.layoutMarginsGuide.topAnchor).isActive = true
superView.layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: view.bottomAnchor).isActive = true
var constraint = view.topAnchor.constraint(equalTo: superView.layoutMarginsGuide.topAnchor)
constraint.priority = .defaultLow
constraint.isActive = true
constraint = superView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: view.bottomAnchor)
constraint.priority = .defaultLow
constraint.isActive = true
} }
leftView.centerYAnchor.constraint(equalTo: superView.centerYAnchor).isActive = true }
leftView.leftAnchor.constraint(equalTo: superView.layoutMarginsGuide.leftAnchor).isActive = true
leftView.topAnchor.constraint(greaterThanOrEqualTo: superView.layoutMarginsGuide.topAnchor).isActive = true /// Pins the views vertically in the super view, allowing the super to expand depending on the tallest view. Shorter views are aligned top.
superView.layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: leftView.bottomAnchor).isActive = true static func pinViewsVerticalExpandableAlignTop(_ views: [UIView]) {
for view in views {
guard let superView = view.superview else {
return
}
view.topAnchor.constraint(equalTo: superView.layoutMarginsGuide.topAnchor).isActive = true
superView.layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: view.bottomAnchor).isActive = true
var constraint = leftView.topAnchor.constraint(equalTo: superView.layoutMarginsGuide.topAnchor) let constraint = superView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: view.bottomAnchor)
constraint.priority = .defaultLow constraint.priority = .defaultLow
constraint.isActive = true constraint.isActive = true
}
constraint = superView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: leftView.bottomAnchor) }
constraint.priority = .defaultLow
constraint.isActive = true /// Pins a view to the left and a view to the right, flexible space in between. The super can expand depending on the taller view. Shorter views are aligned top if alignTop true, else aligned center.
static func pinViews(leftView: UIView, rightView: UIView, alignTop: Bool) {
rightView.leftAnchor.constraint(greaterThanOrEqualTo: leftView.rightAnchor, constant: 16).isActive = true guard let superView = leftView.superview else { return }
if alignTop {
rightView.centerYAnchor.constraint(equalTo: superView.centerYAnchor).isActive = true pinViewsVerticalExpandableAlignTop([leftView, rightView])
superView.layoutMarginsGuide.rightAnchor.constraint(equalTo: rightView.rightAnchor).isActive = true } else {
rightView.topAnchor.constraint(greaterThanOrEqualTo: superView.layoutMarginsGuide.topAnchor).isActive = true pinViewsVerticalExpandableAlignCenter([leftView, rightView])
superView.layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: rightView.bottomAnchor).isActive = true }
leftView.leadingAnchor.constraint(equalTo: superView.layoutMarginsGuide.leadingAnchor).isActive = true
constraint = rightView.topAnchor.constraint(equalTo: superView.layoutMarginsGuide.topAnchor) superView.layoutMarginsGuide.trailingAnchor.constraint(equalTo: rightView.trailingAnchor).isActive = true
constraint.priority = .defaultLow rightView.leftAnchor.constraint(greaterThanOrEqualTo: leftView.rightAnchor, constant: PaddingHorizontalBetweenRelatedItems).isActive = true
constraint.isActive = true
constraint = superView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: rightView.bottomAnchor)
constraint.priority = .defaultLow
constraint.isActive = true
} }
} }

View File

@ -10,13 +10,14 @@ import UIKit
@objcMembers open class ImageHeadlineBody: View { @objcMembers open class ImageHeadlineBody: View {
let headlineBody = HeadlineBody(frame: .zero) let headlineBody = HeadlineBody(frame: .zero)
let imageView = MFLoadImageView() let imageView = MFLoadImageView(pinnedEdges: .all)
var constraintBetweenImageLabelsConstant: CGFloat = 16 var constraintBetweenImageLabelsConstant: CGFloat = 16
var constraintBetweenImageLabels: NSLayoutConstraint? var constraintBetweenImageLabels: NSLayoutConstraint?
// MARK: - MFViewProtocol // MARK: - MFViewProtocol
open override func setupView() { open override func setupView() {
super.setupView()
guard subviews.count == 0 else { guard subviews.count == 0 else {
return return
} }
@ -26,23 +27,9 @@ import UIKit
addSubview(headlineBody) addSubview(headlineBody)
addSubview(imageView) addSubview(imageView)
headlineBody.topAnchor.constraint(equalTo: topAnchor).isActive = true NSLayoutConstraint.pinViewsVerticalExpandableAlignCenter([imageView, headlineBody])
rightAnchor.constraint(equalTo: headlineBody.rightAnchor).isActive = true rightAnchor.constraint(equalTo: headlineBody.rightAnchor).isActive = true
bottomAnchor.constraint(greaterThanOrEqualTo: headlineBody.bottomAnchor).isActive = true
var constraint = bottomAnchor.constraint(equalTo: headlineBody.bottomAnchor)
constraint.priority = .defaultLow
constraint.isActive = true
imageView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
imageView.leftAnchor.constraint(equalTo: leftAnchor).isActive = true imageView.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
imageView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true
bottomAnchor.constraint(greaterThanOrEqualTo: imageView.bottomAnchor).isActive = true
constraint = bottomAnchor.constraint(equalTo: imageView.bottomAnchor)
constraint.priority = UILayoutPriority(rawValue: 200)
constraint.isActive = true
constraint = imageView.topAnchor.constraint(equalTo: topAnchor)
constraint.priority = UILayoutPriority(rawValue: 200)
constraint.isActive = true
constraintBetweenImageLabels = headlineBody.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: constraintBetweenImageLabelsConstant) constraintBetweenImageLabels = headlineBody.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: constraintBetweenImageLabelsConstant)
constraintBetweenImageLabels?.isActive = true constraintBetweenImageLabels?.isActive = true

View File

@ -27,7 +27,7 @@ import UIKit
headlineBodyLink.headlineBody.styleListItem() headlineBodyLink.headlineBody.styleListItem()
addSubview(headlineBodyLink) addSubview(headlineBodyLink)
addSubview(toggle) addSubview(toggle)
NSLayoutConstraint.pinSubviewsCenter(leftView: headlineBodyLink, rightView: toggle) NSLayoutConstraint.pinViews(leftView: headlineBodyLink, rightView: toggle, alignTop: false)
} }
// MARK: - MVMCoreUIMoleculeViewProtoco // MARK: - MVMCoreUIMoleculeViewProtoco

View File

@ -31,7 +31,7 @@ import UIKit
view.addSubview(headlineBody) view.addSubview(headlineBody)
view.addSubview(toggle) view.addSubview(toggle)
NSLayoutConstraint.pinSubviewsCenter(leftView: headlineBody, rightView: toggle) NSLayoutConstraint.pinViews(leftView: headlineBody, rightView: toggle, alignTop: false)
} }
// MARK:- ModelMoleculeViewProtocol // MARK:- ModelMoleculeViewProtocol

View File

@ -28,7 +28,7 @@ import UIKit
addSubview(label) addSubview(label)
addSubview(toggle) addSubview(toggle)
label.setContentHuggingPriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical) label.setContentHuggingPriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical)
NSLayoutConstraint.pinSubviewsCenter(leftView: label, rightView: toggle) NSLayoutConstraint.pinViews(leftView: label, rightView: toggle, alignTop: false)
} }
// MARK:- ModelMoleculeViewProtocol // MARK:- ModelMoleculeViewProtocol

View File

@ -30,16 +30,16 @@
- (nullable instancetype)initWithTopAlertObject:(nonnull MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout; - (nullable instancetype)initWithTopAlertObject:(nonnull MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout;
// Used primarily for when button presses will expand or collapse. (Short view button will need to be set manually) // Used primarily for when button presses will expand or collapse. (Short view button will need to be set manually)
- (nullable instancetype)initWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message buttonTitle:(nullable NSString *)buttonTitle animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout; - (nullable instancetype)initWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message contentColor:(nonnull UIColor *)contentColor buttonTitle:(nullable NSString *)buttonTitle animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout;
- (nullable instancetype)initWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage buttonTitle:(nullable NSString *)buttonTitle animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout; - (nullable instancetype)initWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage contentColor:(nonnull UIColor *)contentColor buttonTitle:(nullable NSString *)buttonTitle animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout;
// Used when button uses standard action map. // Used when button uses standard action map.
- (nullable instancetype)initWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout; - (nullable instancetype)initWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage contentColor:(nonnull UIColor *)contentColor actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout;
// Convenience change functions // Convenience change functions
- (void)setTopMessage:(nullable NSString *)topMessage; - (void)setTopMessage:(nullable NSString *)topMessage;
- (void)setTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData; - (void)setTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage contentColor:(nonnull UIColor *)contentColor actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData;
- (void)setTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler; - (void)setTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage contentColor:(nonnull UIColor *)contentColor buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler;
// Setters for making buttons expand and collapse the cell. // Setters for making buttons expand and collapse the cell.
- (void)setButtonPressToExpand; - (void)setButtonPressToExpand;

View File

@ -41,10 +41,10 @@
- (void)setupTopAlertWithButton:(MVMCoreUITopAlertMainView *)topAlertWithButton; - (void)setupTopAlertWithButton:(MVMCoreUITopAlertMainView *)topAlertWithButton;
// Sets up the whole view without setting button action. // Sets up the whole view without setting button action.
- (void)setupViewWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage buttonTitle:(nullable NSString *)buttonTitle; - (void)setupViewWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage contentColor:(nonnull UIColor *)contentColor buttonTitle:(nullable NSString *)buttonTitle;
// Sets up the whole view while setting button action. // Sets up the whole view while setting button action.
- (void)setupViewWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData; - (void)setupViewWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage contentColor:(nonnull UIColor *)contentColor actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData;
@end @end
@ -97,14 +97,8 @@
[self setupTopAlertWithButton:topAlertWithButton]; [self setupTopAlertWithButton:topAlertWithButton];
// Sets the color // Sets the color
if (topAlertObject.backgroundColor) { self.shortView.label.textColor = topAlertObject.textColor ?: [[MVMCoreUITopAlertView sharedGlobal] getContentColorForType:topAlertObject.type];
self.backgroundColor = topAlertObject.backgroundColor; self.backgroundColor = topAlertObject.backgroundColor ?: [[MVMCoreUITopAlertView sharedGlobal] getBackgroundColorForType:topAlertObject.type];
} else {
self.backgroundColor = [[MVMCoreUITopAlertView sharedGlobal] getBackgroundColorForType:topAlertObject.type];
}
if (topAlertObject.textColor) {
self.shortView.label.textColor = topAlertObject.textColor;
}
if (topAlertWithButton.label.text.length > 0) { if (topAlertWithButton.label.text.length > 0) {
[self expand:NO]; [self expand:NO];
@ -112,8 +106,10 @@
} else { } else {
// Old style, has no top alert and main view is limited. // Old style, has no top alert and main view is limited.
self.backgroundColor = [[MVMCoreUITopAlertView sharedGlobal] getBackgroundColorForType:topAlertObject.type]; [self setupTopMessage:nil]; self.backgroundColor = [[MVMCoreUITopAlertView sharedGlobal] getBackgroundColorForType:topAlertObject.type];
MVMCoreUITopAlertMainView *topAlertWithButton = [[MVMCoreUITopAlertMainView alloc] initWithColor:self.backgroundColor message:topAlertObject.message subMessage:nil closeButton:YES animationDelegate:animationDelegate]; UIColor *contentColor = [[MVMCoreUITopAlertView sharedGlobal] getContentColorForType:topAlertObject.type];
[self setupTopMessage:nil];
MVMCoreUITopAlertMainView *topAlertWithButton = [[MVMCoreUITopAlertMainView alloc] initWithColor:self.backgroundColor contentColor:contentColor message:topAlertObject.message subMessage:nil closeButton:YES animationDelegate:animationDelegate];
[self setupTopAlertWithButton:topAlertWithButton]; [self setupTopAlertWithButton:topAlertWithButton];
[self expand:NO]; [self expand:NO];
} }
@ -121,29 +117,29 @@
return self; return self;
} }
- (nullable instancetype)initWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message buttonTitle:(nullable NSString *)buttonTitle animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout { - (nullable instancetype)initWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message contentColor:(nonnull UIColor *)contentColor buttonTitle:(nullable NSString *)buttonTitle animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout {
if ([self init]) { if ([self init]) {
self.animationDelegate = animationDelegate; self.animationDelegate = animationDelegate;
self.viewToLayout = viewTolayout; self.viewToLayout = viewTolayout;
[self setupViewWithTopMessage:topMessage message:message subMessage:nil buttonTitle:buttonTitle]; [self setupViewWithTopMessage:topMessage message:message subMessage:nil contentColor:contentColor buttonTitle:buttonTitle];
} }
return self; return self;
} }
- (nullable instancetype)initWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage buttonTitle:(nullable NSString *)buttonTitle animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout { - (nullable instancetype)initWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage contentColor:(nonnull UIColor *)contentColor buttonTitle:(nullable NSString *)buttonTitle animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout {
if ([self init]) { if ([self init]) {
self.animationDelegate = animationDelegate; self.animationDelegate = animationDelegate;
self.viewToLayout = viewTolayout; self.viewToLayout = viewTolayout;
[self setupViewWithTopMessage:topMessage message:message subMessage:subMessage buttonTitle:buttonTitle]; [self setupViewWithTopMessage:topMessage message:message subMessage:subMessage contentColor:contentColor buttonTitle:buttonTitle];
} }
return self; return self;
} }
- (nullable instancetype)initWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout { - (nullable instancetype)initWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage contentColor:(nonnull UIColor *)contentColor actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate viewToLayout:(nonnull UIView *)viewTolayout {
if ([self init]) { if ([self init]) {
self.animationDelegate = animationDelegate; self.animationDelegate = animationDelegate;
self.viewToLayout = viewTolayout; self.viewToLayout = viewTolayout;
[self setupViewWithTopMessage:topMessage message:message subMessage:subMessage actionMap:actionMap additionalData:additionalData]; [self setupViewWithTopMessage:topMessage message:message subMessage:subMessage contentColor:contentColor actionMap:actionMap additionalData:additionalData];
} }
return self; return self;
} }
@ -174,19 +170,19 @@
[NSLayoutConstraint constraintPinSubview:topAlertWithButton pinTop:NO topConstant:0 pinBottom:YES bottomConstant:0 pinLeft:YES leftConstant:0 pinRight:YES rightConstant:0]; [NSLayoutConstraint constraintPinSubview:topAlertWithButton pinTop:NO topConstant:0 pinBottom:YES bottomConstant:0 pinLeft:YES leftConstant:0 pinRight:YES rightConstant:0];
} }
- (void)setupViewWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage buttonTitle:(nullable NSString *)buttonTitle { - (void)setupViewWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage contentColor:(nonnull UIColor *)contentColor buttonTitle:(nullable NSString *)buttonTitle {
[self setupTopMessage:topMessage]; [self setupTopMessage:topMessage];
MVMCoreUITopAlertMainView *topAlertWithButton = [[MVMCoreUITopAlertMainView alloc] initWithColor:[UIColor clearColor] message:message subMessage:subMessage buttonTitle:buttonTitle userActionHandler:nil]; MVMCoreUITopAlertMainView *topAlertWithButton = [[MVMCoreUITopAlertMainView alloc] initWithColor:[UIColor clearColor] contentColor:contentColor message:message subMessage:subMessage buttonTitle:buttonTitle userActionHandler:nil];
[self setupTopAlertWithButton:topAlertWithButton]; [self setupTopAlertWithButton:topAlertWithButton];
} }
- (void)setupViewWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData { - (void)setupViewWithTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage contentColor:(nonnull UIColor *)contentColor actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData {
[self setupTopMessage:topMessage]; [self setupTopMessage:topMessage];
MVMCoreUITopAlertMainView *topAlertWithButton = [[MVMCoreUITopAlertMainView alloc] initWithColor:[UIColor clearColor] message:message subMessage:subMessage actionMap:actionMap additionalData:additionalData]; MVMCoreUITopAlertMainView *topAlertWithButton = [[MVMCoreUITopAlertMainView alloc] initWithColor:[UIColor clearColor] contentColor:contentColor message:message subMessage:subMessage actionMap:actionMap additionalData:additionalData];
[self setupTopAlertWithButton:topAlertWithButton]; [self setupTopAlertWithButton:topAlertWithButton];
} }
@ -204,17 +200,17 @@
}]; }];
} }
- (void)setTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData { - (void)setTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage contentColor:(nonnull UIColor *)contentColor actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData {
[MVMCoreDispatchUtility performBlockOnMainThread:^{ [MVMCoreDispatchUtility performBlockOnMainThread:^{
[self setTopMessage:topMessage]; [self setTopMessage:topMessage];
[self.buttonView setupWithMessage:message subMessage:subMessage actionMap:actionMap additionalData:additionalData]; [self.buttonView setupWithMessage:message subMessage:subMessage color:contentColor actionMap:actionMap additionalData:additionalData];
}]; }];
} }
- (void)setTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler { - (void)setTopMessage:(nullable NSString *)topMessage message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage contentColor:(nonnull UIColor *)contentColor buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler {
[MVMCoreDispatchUtility performBlockOnMainThread:^{ [MVMCoreDispatchUtility performBlockOnMainThread:^{
[self setTopMessage:topMessage]; [self setTopMessage:topMessage];
[self.buttonView setupWithMessage:message subMessage:subMessage buttonTitle:buttonTitle userActionHandler:userActionHandler]; [self.buttonView setupWithMessage:message subMessage:subMessage color:contentColor buttonTitle:buttonTitle userActionHandler:userActionHandler];
}]; }];
} }

View File

@ -22,16 +22,16 @@
// Standard // Standard
- (nullable instancetype)initWithTopAlertObject:(nonnull MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate; - (nullable instancetype)initWithTopAlertObject:(nonnull MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate;
- (nullable instancetype)initWithColor:(nonnull UIColor *)color message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate; - (nullable instancetype)initWithColor:(nonnull UIColor *)color contentColor:(nullable UIColor *)contentColor message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate;
// inits with images // inits with images
- (nullable instancetype)initWithColor:(nonnull UIColor *)color imageURL:(nullable NSString *)imageURL message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate; - (nullable instancetype)initWithColor:(nonnull UIColor *)color contentColor:(nullable UIColor *)contentColor imageURL:(nullable NSString *)imageURL message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate;
- (nullable instancetype)initWithColor:(nonnull UIColor *)color imageURL:(nullable NSString *)imageURL message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate; - (nullable instancetype)initWithColor:(nonnull UIColor *)color contentColor:(nullable UIColor *)contentColor imageURL:(nullable NSString *)imageURL message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate;
// Setters for label and button. // Setters for label and button.
- (void)setupWithMessage:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData; - (void)setupWithMessage:(nullable NSString *)message subMessage:(nullable NSString *)subMessage color:(nullable UIColor *)color actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData;
- (void)setupWithMessage:(nullable NSString *)message subMessage:(nullable NSString *)subMessage buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler; - (void)setupWithMessage:(nullable NSString *)message subMessage:(nullable NSString *)subMessage color:(nullable UIColor *)color buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler;
// Setters for button. // Setters for button.
- (void)setupButtonWithActionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData; - (void)setupButtonWithActionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData;
@ -40,13 +40,13 @@
#pragma mark - legacy inits #pragma mark - legacy inits
// Legacy init: inits with a label and button, no close button or icon. // Legacy init: inits with a label and button, no close button or icon.
- (nullable instancetype)initWithColor:(nonnull UIColor *)color message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData; - (nullable instancetype)initWithColor:(nonnull UIColor *)color contentColor:(nonnull UIColor *)contentColor message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData;
// Legacy init: inits with a label and possible icon and close button. No main button. // Legacy init: inits with a label and possible icon and close button. No main button.
- (nullable instancetype)initWithColor:(nonnull UIColor *)color message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate; - (nullable instancetype)initWithColor:(nonnull UIColor *)color contentColor:(nonnull UIColor *)contentColor message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate;
// Legacy init: inits with a label and button, no close button or icon. If passing in a block to use for the button, the top alert delegate button functions will not be called. // Legacy init: inits with a label and button, no close button or icon. If passing in a block to use for the button, the top alert delegate button functions will not be called.
- (nullable instancetype)initWithColor:(nonnull UIColor *)color message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler; - (nullable instancetype)initWithColor:(nonnull UIColor *)color contentColor:(nonnull UIColor *)contentColor message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler;
@end @end

View File

@ -60,52 +60,49 @@
- (nullable instancetype)initWithTopAlertObject:(nonnull MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate { - (nullable instancetype)initWithTopAlertObject:(nonnull MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate {
if ([self init]) { if ([self init]) {
if (topAlertObject.backgroundColor) { UIColor *contentColor = topAlertObject.textColor ?: [[MVMCoreUITopAlertView sharedGlobal] getContentColorForType:topAlertObject.type];
self.backgroundColor = topAlertObject.backgroundColor; self.backgroundColor = topAlertObject.backgroundColor ?: [[MVMCoreUITopAlertView sharedGlobal] getBackgroundColorForType:topAlertObject.type];
} else {
self.backgroundColor = [[MVMCoreUITopAlertView sharedGlobal] getBackgroundColorForType:topAlertObject.type];
}
[self setupViewWithLabelAndImage:topAlertObject.imageNameOrURL topImage:topAlertObject.aboveTextImageString]; [self setupViewWithLabelAndImage:topAlertObject.imageNameOrURL topImage:topAlertObject.aboveTextImageString];
[self setupCloseButton:topAlertObject.useCloseButton animationDelegate:animationDelegate]; [self setupCloseButton:topAlertObject.useCloseButton animationDelegate:animationDelegate];
[self setupWithMessage:topAlertObject.title subMessage:topAlertObject.message color:topAlertObject.textColor actionMap:topAlertObject.buttonMap additionalData:topAlertObject.additionalData]; [self setupWithMessage:topAlertObject.title subMessage:topAlertObject.message color:contentColor actionMap:topAlertObject.buttonMap additionalData:topAlertObject.additionalData];
} }
return self; return self;
} }
- (nullable instancetype)initWithColor:(nonnull UIColor *)color message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate { - (nullable instancetype)initWithColor:(nonnull UIColor *)color contentColor:(nullable UIColor *)contentColor message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate {
// Handles all scenarios. // Handles all scenarios.
if ([self init]) { if ([self init]) {
self.backgroundColor = color; self.backgroundColor = color;
[self setupViewWithLabelAndImage:nil topImage:nil]; [self setupViewWithLabelAndImage:nil topImage:nil];
[self setupCloseButton:closeButton animationDelegate:animationDelegate]; [self setupCloseButton:closeButton animationDelegate:animationDelegate];
[self setupWithMessage:message subMessage:subMessage actionMap:actionMap additionalData:additionalData]; [self setupWithMessage:message subMessage:subMessage color:contentColor actionMap:actionMap additionalData:additionalData];
} }
return self; return self;
} }
#pragma mark - inits with images #pragma mark - inits with images
- (nullable instancetype)initWithColor:(nonnull UIColor *)color imageURL:(nullable NSString *)imageURL message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate { - (nullable instancetype)initWithColor:(nonnull UIColor *)color contentColor:(nullable UIColor *)contentColor imageURL:(nullable NSString *)imageURL message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate {
// Handles all scenarios. // Handles all scenarios.
if ([self init]) { if ([self init]) {
self.backgroundColor = color; self.backgroundColor = color;
[self setupViewWithLabelAndImage:imageURL topImage:nil]; [self setupViewWithLabelAndImage:imageURL topImage:nil];
[self setupCloseButton:closeButton animationDelegate:animationDelegate]; [self setupCloseButton:closeButton animationDelegate:animationDelegate];
[self setupWithMessage:message subMessage:subMessage actionMap:actionMap additionalData:additionalData]; [self setupWithMessage:message subMessage:subMessage color:contentColor actionMap:actionMap additionalData:additionalData];
} }
return self; return self;
} }
- (nullable instancetype)initWithColor:(nonnull UIColor *)color imageURL:(nullable NSString *)imageURL message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate { - (nullable instancetype)initWithColor:(nonnull UIColor *)color contentColor:(nullable UIColor *)contentColor imageURL:(nullable NSString *)imageURL message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate {
// No main button. // No main button.
if ([self init]) { if ([self init]) {
self.backgroundColor = color; self.backgroundColor = color;
[self setupViewWithLabelAndImage:imageURL topImage:nil]; [self setupViewWithLabelAndImage:imageURL topImage:nil];
[self setupCloseButton:closeButton animationDelegate:animationDelegate]; [self setupCloseButton:closeButton animationDelegate:animationDelegate];
[self setupWithMessage:message subMessage:subMessage buttonTitle:nil userActionHandler:NULL]; [self setupWithMessage:message subMessage:subMessage color:contentColor buttonTitle:nil userActionHandler:NULL];
} }
return self; return self;
} }
@ -173,7 +170,7 @@
if (closeButton && !self.closeButton) { if (closeButton && !self.closeButton) {
self.closeButton = [self addCloseButtonWithAnimationDelegate:animationDelegate]; self.closeButton = [self addCloseButtonWithAnimationDelegate:animationDelegate];
[self.closeButton setTintColor:self.contentColor ?:[UIColor whiteColor]]; [self.closeButton setTintColor:self.contentColor ?: [UIColor whiteColor]];
} else if (!closeButton && self.closeButton) { } else if (!closeButton && self.closeButton) {
[self.closeButton removeFromSuperview]; [self.closeButton removeFromSuperview];
self.closeButton = nil; self.closeButton = nil;
@ -241,17 +238,19 @@
}]; }];
} }
- (void)setupWithMessage:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData { - (void)setupWithMessage:(nullable NSString *)message subMessage:(nullable NSString *)subMessage color:(nullable UIColor *)color buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler {
[self setupWithMessage:message subMessage:subMessage color:nil actionMap:actionMap additionalData:additionalData];
}
- (void)setupWithMessage:(nullable NSString *)message subMessage:(nullable NSString *)subMessage buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler {
self.message = message; self.message = message;
self.subMessage = subMessage; self.subMessage = subMessage;
self.contentColor = color;
[MVMCoreDispatchUtility performBlockOnMainThread:^{ [MVMCoreDispatchUtility performBlockOnMainThread:^{
// Sets the string // Sets the string
self.label.attributedText = [MVMCoreUITopAlertBaseView getStringForMessage:message subMessage:subMessage color:nil]; self.label.attributedText = [MVMCoreUITopAlertBaseView getStringForMessage:message subMessage:subMessage color:color];
// Sets the color
if (color) {
[self.closeButton setTintColor:color];
}
// Sets the button // Sets the button
[self setupButtonWithButtonTitle:buttonTitle userActionHandler:userActionHandler]; [self setupButtonWithButtonTitle:buttonTitle userActionHandler:userActionHandler];
@ -284,36 +283,36 @@
#pragma mark - legacy inits #pragma mark - legacy inits
- (nullable instancetype)initWithColor:(nonnull UIColor *)color message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData { - (nullable instancetype)initWithColor:(nonnull UIColor *)color contentColor:(nonnull UIColor *)contentColor message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData {
// No icon or close button. // No icon or close button.
if ([self init]) { if ([self init]) {
self.backgroundColor = color; self.backgroundColor = color;
[self setupViewWithLabelAndImage:nil topImage:nil]; [self setupViewWithLabelAndImage:nil topImage:nil];
[self setupWithMessage:message subMessage:subMessage actionMap:actionMap additionalData:additionalData]; [self setupWithMessage:message subMessage:subMessage color:contentColor actionMap:actionMap additionalData:additionalData];
} }
return self; return self;
} }
- (nullable instancetype)initWithColor:(nonnull UIColor *)color message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate { - (nullable instancetype)initWithColor:(nonnull UIColor *)color contentColor:(nonnull UIColor *)contentColor message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage closeButton:(BOOL)closeButton animationDelegate:(nullable id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate {
// No main button. // No main button.
if ([self init]) { if ([self init]) {
self.backgroundColor = color; self.backgroundColor = color;
[self setupViewWithLabelAndImage:nil topImage:nil]; [self setupViewWithLabelAndImage:nil topImage:nil];
[self setupWithMessage:message subMessage:subMessage color:contentColor buttonTitle:nil userActionHandler:NULL];
[self setupCloseButton:closeButton animationDelegate:animationDelegate]; [self setupCloseButton:closeButton animationDelegate:animationDelegate];
[self setupWithMessage:message subMessage:subMessage buttonTitle:nil userActionHandler:NULL];
} }
return self; return self;
} }
- (nullable instancetype)initWithColor:(nonnull UIColor *)color message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler { - (nullable instancetype)initWithColor:(nonnull UIColor *)color contentColor:(nonnull UIColor *)contentColor message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler {
// No icon or close button. Custom button action. // No icon or close button. Custom button action.
if ([self init]) { if ([self init]) {
self.backgroundColor = color; self.backgroundColor = color;
[self setupViewWithLabelAndImage:nil topImage:nil]; [self setupViewWithLabelAndImage:nil topImage:nil];
[self setupWithMessage:message subMessage:subMessage buttonTitle:buttonTitle userActionHandler:userActionHandler]; [self setupWithMessage:message subMessage:subMessage color:contentColor buttonTitle:buttonTitle userActionHandler:userActionHandler];
} }
return self; return self;
} }

View File

@ -47,9 +47,12 @@
// Can be subclassed for custom views. // Can be subclassed for custom views.
- (nonnull MVMCoreUITopAlertBaseView *)topAlertViewForTopAlertObject:(nullable MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nonnull id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate statusBarColor:(UIColor *_Nullable *_Nullable)statusBarColor; - (nonnull MVMCoreUITopAlertBaseView *)topAlertViewForTopAlertObject:(nullable MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nonnull id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate statusBarColor:(UIColor *_Nullable *_Nullable)statusBarColor;
// Get the background color based on the type /// Get the background color based on the type
- (nonnull UIColor *)getBackgroundColorForType:(nullable NSString *)type; - (nonnull UIColor *)getBackgroundColorForType:(nullable NSString *)type;
/// Get the content color based on the type
- (nonnull UIColor *)getContentColorForType:(nullable NSString *)type;
// Set the status bar color. Used for updating the status bar when the view changes. // Set the status bar color. Used for updating the status bar when the view changes.
- (void)setStatusBarColor:(nullable UIColor *)statusBarColor statusBarStyle:(UIStatusBarStyle)style; - (void)setStatusBarColor:(nullable UIColor *)statusBarColor statusBarStyle:(UIStatusBarStyle)style;

View File

@ -114,6 +114,14 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
} }
} }
- (nonnull UIColor *)getContentColorForType:(nullable NSString *)type {
if ([type isEqualToString:ValueTypeError]) {
return [UIColor blackColor];
} else {
return [UIColor whiteColor];
}
}
- (void)showWithTopAlertObject:(nullable MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nonnull id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate completionHandler:(void (^ __nullable)(BOOL finished))completionHandler { - (void)showWithTopAlertObject:(nullable MVMCoreTopAlertObject *)topAlertObject animationDelegate:(nonnull id <MVMCoreTopAlertAnimationDelegateProtocol>)animationDelegate completionHandler:(void (^ __nullable)(BOOL finished))completionHandler {
self.animationDelegate = animationDelegate; self.animationDelegate = animationDelegate;
@ -126,7 +134,8 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
MVMCoreUITopAlertBaseView *view = [self topAlertViewForTopAlertObject:topAlertObject animationDelegate:animationDelegate statusBarColor:&statusBarColor]; MVMCoreUITopAlertBaseView *view = [self topAlertViewForTopAlertObject:topAlertObject animationDelegate:animationDelegate statusBarColor:&statusBarColor];
if (!statusBarColor) { if (!statusBarColor) {
statusBarColor = [UIColor whiteColor]; statusBarColor = [UIColor whiteColor];
} }
#warning This logic is incomplete, it is possible to show the wrong status bar color here if the background is yellow or pumpkin.
UIStatusBarStyle statusBarStyle = statusBarColor == [UIColor whiteColor] ? UIStatusBarStyleDefault : UIStatusBarStyleLightContent; UIStatusBarStyle statusBarStyle = statusBarColor == [UIColor whiteColor] ? UIStatusBarStyleDefault : UIStatusBarStyleLightContent;
[self setStatusBarColor:statusBarColor statusBarStyle:statusBarStyle]; [self setStatusBarColor:statusBarColor statusBarStyle:statusBarStyle];
[self showAlertView:view topAlertObject:topAlertObject completionHandler:completionHandler]; [self showAlertView:view topAlertObject:topAlertObject completionHandler:completionHandler];