From 9eb28ff675029a566b1149c28397b67a554cebc2 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 30 Mar 2021 16:36:08 -0400 Subject: [PATCH] top alert margins --- .../CollapsableNotificationModel.swift | 4 ++-- .../Molecules/TopNotification/Notification.swift | 10 ++-------- .../TopNotification/NotificationModel.swift | 14 ++++++++++---- MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m | 10 ++++++---- .../MVMCoreUICommonViewsUtility+Extension.swift | 4 ++-- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift index 17b1aef7..bdcd3fe1 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift @@ -24,8 +24,8 @@ open class CollapsableNotificationModel: NotificationModel { super.init(with: headline) } - open override func setDefault() { - super.setDefault() + open override func setDefaults() { + super.setDefaults() if topLabel.textColor == nil { topLabel.textColor = Color(uiColor: .white) } diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/Notification.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/Notification.swift index 09edbbcc..c17f43e0 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/Notification.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/Notification.swift @@ -8,7 +8,7 @@ import Foundation -@objcMembers open class NotificationView: View { +@objcMembers open class NotificationView: Container { //-------------------------------------------------- // MARK: - Outlets //-------------------------------------------------- @@ -43,19 +43,13 @@ import Foundation labelStack = Stack.createStack(with: [headline, body], spacing: 0) horizontalStack = Stack.createStack(with: [(view: labelStack, model: StackItemModel()),(view: button, model: StackItemModel(horizontalAlignment: .fill)),(view: closeButton, model: StackItemModel(horizontalAlignment: .fill))], axis: .horizontal) - addSubview(horizontalStack) - NSLayoutConstraint.constraintPinSubview(horizontalStack, pinTop: true, topConstant: PaddingTwo, pinBottom: true, bottomConstant: PaddingTwo, pinLeft: true, leftConstant: PaddingThree, pinRight: true, rightConstant: PaddingThree) + addAndContain(horizontalStack) labelStack.restack() horizontalStack.restack() heightAnchor.constraint(equalToConstant: Self.viewHeight).isActive = true } - open override func updateView(_ size: CGFloat) { - super.updateView(size) - horizontalStack.updateView(size) - } - open override func reset() { super.reset() backgroundColor = .mvmGreen() diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift index 3d02cecd..1e77e61d 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift @@ -7,7 +7,7 @@ // -open class NotificationModel: MoleculeModelProtocol { +open class NotificationModel: ContainerModel, MoleculeModelProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -26,13 +26,19 @@ open class NotificationModel: MoleculeModelProtocol { public init(with headline: LabelModel) { self.headline = headline + super.init() } //-------------------------------------------------- // MARK: - Default //-------------------------------------------------- - open func setDefault() { + open override func setDefaults() { + useHorizontalMargins = true + useVerticalMargins = true + topPadding = PaddingTwo + bottomPadding = PaddingTwo + if backgroundColor == nil { backgroundColor = Color(uiColor: .mvmGreen) } @@ -76,10 +82,10 @@ open class NotificationModel: MoleculeModelProtocol { body = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .body) button = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .button) closeButton = try typeContainer.decodeIfPresent(NotificationXButtonModel.self, forKey: .closeButton) - setDefault() + super.init() } - open func encode(to encoder: Encoder) throws { + open override func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m index 44f248f3..fa96630f 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m @@ -164,18 +164,19 @@ [self.iconView removeFromSuperview]; } + CGFloat horizontalPadding = [MFStyler defaultHorizontalPaddingForApplicationWidth]; if (imageURL) { LoadImageView *imageView = [[LoadImageView alloc] init]; imageView.translatesAutoresizingMaskIntoConstraints = NO; [imageView setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal]; [self addSubview:imageView]; [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|->=space-[imageView]->=space-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:@{@"space":@(PaddingFive)} views:NSDictionaryOfVariableBindings(imageView)]]; - [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-space-[imageView]-space-[centerView]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:@{@"space":@(PaddingThree)} views:NSDictionaryOfVariableBindings(imageView,centerView)]]; + [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-space-[imageView]-space-[centerView]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:@{@"space":@(horizontalPadding)} views:NSDictionaryOfVariableBindings(imageView,centerView)]]; [NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0].active = YES; self.iconView = imageView; [imageView loadImageWithName:imageURL width:@(32)]; } else { - [NSLayoutConstraint constraintWithItem:centerView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:PaddingThree].active = YES; + [NSLayoutConstraint constraintWithItem:centerView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:horizontalPadding].active = YES; } } @@ -193,6 +194,7 @@ - (void)setupWithButton:(BOOL)showButton { // Setup the button. + CGFloat horizontalPadding = [MFStyler defaultHorizontalPaddingForApplicationWidth]; if (showButton) { if (!self.button) { @@ -210,7 +212,7 @@ [self addSubview:button]; [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0].active = YES; [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.centerView attribute:NSLayoutAttributeRight multiplier:1 constant:PaddingThree].active = YES; - [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:button attribute:NSLayoutAttributeRight multiplier:1 constant:(self.closeButton ? PaddingTen : PaddingFive)].active = YES; + [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:button attribute:NSLayoutAttributeRight multiplier:1 constant:(self.closeButton ? PaddingTen : horizontalPadding)].active = YES; self.button = button; } } else { @@ -222,7 +224,7 @@ } if (!self.labelRightConstraint) { - self.labelRightConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.centerView attribute:NSLayoutAttributeRight multiplier:1 constant:(self.closeButton ? PaddingTen : PaddingFive)]; + self.labelRightConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.centerView attribute:NSLayoutAttributeRight multiplier:1 constant:(self.closeButton ? PaddingTen : horizontalPadding)]; } self.labelRightConstraint.active = YES; } diff --git a/MVMCoreUI/Utility/MVMCoreUICommonViewsUtility+Extension.swift b/MVMCoreUI/Utility/MVMCoreUICommonViewsUtility+Extension.swift index d1173250..60e57d75 100644 --- a/MVMCoreUI/Utility/MVMCoreUICommonViewsUtility+Extension.swift +++ b/MVMCoreUI/Utility/MVMCoreUICommonViewsUtility+Extension.swift @@ -23,11 +23,11 @@ public extension MVMCoreUICommonViewsUtility { view.addSubview(button) var constraints: [NSLayoutConstraint] = [] if centeredVertically { - constraints.append(view.rightAnchor.constraint(equalTo: button.rightAnchor, constant: PaddingTwo)) + constraints.append(view.rightAnchor.constraint(equalTo: button.rightAnchor, constant: Padding.Component.horizontalPaddingForApplicationWidth)) constraints.append(view.centerYAnchor.constraint(equalTo: button.centerYAnchor)) } else { constraints.append(button.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: PaddingOne)) - constraints.append(view.safeAreaLayoutGuide.rightAnchor.constraint(equalTo: button.rightAnchor, constant: PaddingTwo)) + constraints.append(view.safeAreaLayoutGuide.rightAnchor.constraint(equalTo: button.rightAnchor, constant: Padding.Component.horizontalPaddingForApplicationWidth)) } NSLayoutConstraint.activate(constraints) return button