add PrimaryButtonView back into legacy view and view controller
This commit is contained in:
parent
80b45df27b
commit
e6ae064c44
@ -115,6 +115,8 @@
|
||||
94C2D9AB23872EB50006CF46 /* LabelAttributeActionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9AA23872EB50006CF46 /* LabelAttributeActionModel.swift */; };
|
||||
94C661D923CCF4B400D9FE5B /* LeftRightLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9402C34F23A2CEA3004B974C /* LeftRightLabelModel.swift */; };
|
||||
94C661DA23CCF4FB00D9FE5B /* UIColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA33B33239813C50067DD0F /* UIColor+Extension.swift */; };
|
||||
94F217B623E0BF6100A47C06 /* PrimaryButtonView.h in Headers */ = {isa = PBXBuildFile; fileRef = 94F217B423E0BF6100A47C06 /* PrimaryButtonView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
94F217B723E0BF6100A47C06 /* PrimaryButtonView.m in Sources */ = {isa = PBXBuildFile; fileRef = 94F217B523E0BF6100A47C06 /* PrimaryButtonView.m */; };
|
||||
94FB966223D797DA003D482B /* MFTextButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 94FB966023D797DA003D482B /* MFTextButton.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
94FB966323D797DA003D482B /* MFTextButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 94FB966123D797DA003D482B /* MFTextButton.m */; };
|
||||
C003506123AA94CD00B6AC29 /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = C003506023AA94CD00B6AC29 /* Button.swift */; };
|
||||
@ -422,6 +424,8 @@
|
||||
94C2D9A623872DA90006CF46 /* LabelAttributeColorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeColorModel.swift; sourceTree = "<group>"; };
|
||||
94C2D9A823872E5E0006CF46 /* LabelAttributeImageModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeImageModel.swift; sourceTree = "<group>"; };
|
||||
94C2D9AA23872EB50006CF46 /* LabelAttributeActionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeActionModel.swift; sourceTree = "<group>"; };
|
||||
94F217B423E0BF6100A47C06 /* PrimaryButtonView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrimaryButtonView.h; sourceTree = "<group>"; };
|
||||
94F217B523E0BF6100A47C06 /* PrimaryButtonView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PrimaryButtonView.m; sourceTree = "<group>"; };
|
||||
94FB966023D797DA003D482B /* MFTextButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFTextButton.h; sourceTree = "<group>"; };
|
||||
94FB966123D797DA003D482B /* MFTextButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFTextButton.m; sourceTree = "<group>"; };
|
||||
C003506023AA94CD00B6AC29 /* Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = "<group>"; };
|
||||
@ -859,6 +863,8 @@
|
||||
D28A838E23CCDEDE00DFE4FC /* TwoButtonViewModel.swift */,
|
||||
D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */,
|
||||
D28A837E23CCA96400DFE4FC /* TabsModel.swift */,
|
||||
94F217B423E0BF6100A47C06 /* PrimaryButtonView.h */,
|
||||
94F217B523E0BF6100A47C06 /* PrimaryButtonView.m */,
|
||||
);
|
||||
path = HorizontalCombinationViews;
|
||||
sourceTree = "<group>";
|
||||
@ -1423,6 +1429,7 @@
|
||||
D29DF2A121E7AF4E003B2FB9 /* MVMCoreUIUtility.h in Headers */,
|
||||
D29DF17621E69E1F003B2FB9 /* PrimaryButton.h in Headers */,
|
||||
D29DF2C821E7BFC1003B2FB9 /* MFSizeObject.h in Headers */,
|
||||
94F217B623E0BF6100A47C06 /* PrimaryButtonView.h in Headers */,
|
||||
D29DF32021ED0CBA003B2FB9 /* LabelView.h in Headers */,
|
||||
D29770C921F7C4AE00B2F0D0 /* TopLabelsView.h in Headers */,
|
||||
D29DF2E121E9240B003B2FB9 /* MVMCoreUIPanelProtocol.h in Headers */,
|
||||
@ -1608,6 +1615,7 @@
|
||||
D29DF13021E6851E003B2FB9 /* MVMCoreUITopAlertShortView.m in Sources */,
|
||||
0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */,
|
||||
0A7EF85B23D8A52800B2AAD1 /* EntryFieldModel.swift in Sources */,
|
||||
94F217B723E0BF6100A47C06 /* PrimaryButtonView.m in Sources */,
|
||||
0A1B4A96233BB18F005B3FB4 /* CheckboxWithLabelView.swift in Sources */,
|
||||
0A21DB8B235E06EF00C160A2 /* MFDigitTextBox.m in Sources */,
|
||||
D260D7B222D65BDD007E7233 /* MVMCoreUIPageControl.m in Sources */,
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import "TopLabelsAndBottomButtonsTableViewController.h"
|
||||
#import <MVMCoreUI/PrimaryButtonView.h>
|
||||
#import <MVMCoreUI/MVMCoreUIUtility.h>
|
||||
#import <MVMCoreUI/StackableViewController.h>
|
||||
#import <MVMCoreUI/MVMCoreUICommonViewsUtility.h>
|
||||
@ -121,7 +122,7 @@
|
||||
// Sets up the buttons/button.
|
||||
NSDictionary *primaryButtonDictionary = [self primaryButtonMap];
|
||||
NSDictionary *secondaryButtonDictionary = [self secondaryButtonMap];
|
||||
TwoButtonView *buttonView = [[TwoButtonView alloc] initWithPrimaryButtonMap:primaryButtonDictionary secondaryButtonMap:secondaryButtonDictionary delegateObject:[self delegateObject] additionalData:nil];
|
||||
PrimaryButtonView *buttonView = [[PrimaryButtonView alloc] initWithPrimaryButtonMap:primaryButtonDictionary secondaryButtonMap:secondaryButtonDictionary actionDelegate:self additionalData:nil buttonDelegate:self];
|
||||
self.secondaryButton = buttonView.secondaryButton;
|
||||
self.primaryButton = buttonView.primaryButton;
|
||||
|
||||
@ -439,16 +440,16 @@
|
||||
|
||||
|
||||
- (void)setPrimaryLeftButtonHidden:(BOOL)left rightButtonHidden:(BOOL)right {
|
||||
if ([self.bottomView isKindOfClass:[TwoButtonView class]]) {
|
||||
TwoButtonView *buttonView = (TwoButtonView *)self.bottomView;
|
||||
if ([self.bottomView isKindOfClass:[PrimaryButtonView class]]) {
|
||||
PrimaryButtonView *buttonView = (PrimaryButtonView *)self.bottomView;
|
||||
if (right && !left) {
|
||||
[buttonView hideRightButton];
|
||||
[buttonView hidePrimaryRightButton];
|
||||
} else if (!right && left) {
|
||||
[buttonView hideLeftButton];
|
||||
[buttonView hidePrimaryLeftButton];
|
||||
} else if (right && left) {
|
||||
[buttonView hideBothButtons];
|
||||
[buttonView hideBothPrimaryButtons];
|
||||
} else if (!right && !left) {
|
||||
[buttonView showBothButtons];
|
||||
[buttonView showBothPrimaryButtons];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import "TopLabelsAndBottomButtonsViewController.h"
|
||||
#import <MVMCoreUI/PrimaryButtonView.h>
|
||||
#import <MVMCoreUI/MFSizeObject.h>
|
||||
#import <MVMCoreUI/MVMCoreUICommonViewsUtility.h>
|
||||
#import <MVMCoreUI/UIColor+MFConvenience.h>
|
||||
@ -81,18 +82,18 @@
|
||||
}
|
||||
|
||||
if (!self.customBottemView) {
|
||||
TwoButtonView *buttonView = (TwoButtonView *)self.bottomView;
|
||||
PrimaryButtonView *buttonView = (PrimaryButtonView *)self.bottomView;
|
||||
if (self.secondaryButton || self.primaryButton) {
|
||||
UIEdgeInsets paddingForBottomButtons = [self paddingForBottomButtons];
|
||||
[buttonView setLeftPinConstant:paddingForBottomButtons.left];
|
||||
[buttonView setRightPinConstant:paddingForBottomButtons.right];
|
||||
buttonView.leftPin.constant = paddingForBottomButtons.left;
|
||||
buttonView.rightPin.constant = paddingForBottomButtons.right;
|
||||
buttonView.topPin.constant = paddingForBottomButtons.top;
|
||||
buttonView.bottomPin.constant = paddingForBottomButtons.bottom;
|
||||
} else {
|
||||
buttonView.topPin.constant = 0;
|
||||
buttonView.bottomPin.constant = 0;
|
||||
[buttonView setLeftPinConstant:0];
|
||||
[buttonView setRightPinConstant:0];
|
||||
buttonView.leftPin.constant = 0;
|
||||
buttonView.rightPin.constant = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -138,7 +139,7 @@
|
||||
// Sets up the buttons/button.
|
||||
NSDictionary *primaryButtonDictionary = [self primaryButtonMap];
|
||||
NSDictionary *secondaryButtonDictionary = [self secondaryButtonMap];
|
||||
TwoButtonView *buttonView = [[TwoButtonView alloc] initWithPrimaryButtonMap:primaryButtonDictionary secondaryButtonMap:secondaryButtonDictionary delegateObject:[self delegateObject] additionalData:nil];
|
||||
PrimaryButtonView *buttonView = [[PrimaryButtonView alloc] initWithPrimaryButtonMap:primaryButtonDictionary secondaryButtonMap:secondaryButtonDictionary actionDelegate:self additionalData:nil buttonDelegate:self];
|
||||
self.secondaryButton = buttonView.secondaryButton;
|
||||
self.primaryButton = buttonView.primaryButton;
|
||||
bottomView = buttonView;
|
||||
|
||||
@ -88,6 +88,7 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[];
|
||||
#import <MVMCoreUI/MFCustomButton.h>
|
||||
#import <MVMCoreUI/PrimaryButton.h>
|
||||
#import <MVMCoreUI/MFTextButton.h>
|
||||
#import <MVMCoreUI/PrimaryButtonView.h>
|
||||
|
||||
#pragma mark TextFields
|
||||
#import <MVMCoreUI/MFTextField.h>
|
||||
|
||||
@ -0,0 +1,61 @@
|
||||
//
|
||||
// PrimaryButtonView.h
|
||||
// myverizon
|
||||
//
|
||||
// Created by Scott Pfeil on 12/11/15.
|
||||
// Copyright © 2015 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <MVMCoreUI/ViewConstrainingView.h>
|
||||
#import <MVMCoreUI/PrimaryButton.h>
|
||||
|
||||
@interface PrimaryButtonView : ViewConstrainingView
|
||||
|
||||
// Set when there is one button or it is the right button when there are two.
|
||||
@property (nullable, weak, nonatomic) PrimaryButton *primaryButton;
|
||||
|
||||
// The left button when there are two buttons.
|
||||
@property (nullable, weak, nonatomic) PrimaryButton *secondaryButton;
|
||||
|
||||
// Inits with a single button.
|
||||
- (nonnull instancetype)initButtonSmall:(BOOL)small enabled:(BOOL)enabled;
|
||||
|
||||
// Inits with two buttons.
|
||||
- (nonnull instancetype)initWithTwoButtons;
|
||||
|
||||
// Legacy: Sets up with whatever is in the passed in button map. (could be 0, 1, or 2 buttons)
|
||||
- (nonnull instancetype)initButtonSmall:(BOOL)small buttonMap:(nullable NSDictionary *)buttonMap actionDelegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id <ButtonDelegateProtocol>)buttonDelegate;
|
||||
- (nonnull instancetype)initWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap actionDelegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id <ButtonDelegateProtocol>)buttonDelegate;
|
||||
- (void)setupWithButtonMap:(nullable NSDictionary *)buttonMap actionDelegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id <ButtonDelegateProtocol>)buttonDelegate;
|
||||
- (void)setupWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap actionDelegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id <ButtonDelegateProtocol>)buttonDelegate;
|
||||
|
||||
// Sets up with two buttons.
|
||||
- (void)setupWithTwoButtons;
|
||||
|
||||
// For subclassing, just returns the button.
|
||||
- (nonnull id)createButton;
|
||||
|
||||
// Change the alignment of the button
|
||||
- (void)alignLeft;
|
||||
- (void)alignCenter;
|
||||
- (void)alignRight;
|
||||
- (void)alignFill;//default behavior
|
||||
|
||||
// Show/hide left and right primary buttons. This does not impact the vertical space of the view.
|
||||
- (void)hidePrimaryLeftButton;
|
||||
- (void)hidePrimaryRightButton;
|
||||
- (void)showBothPrimaryButtons;
|
||||
- (void)hideBothPrimaryButtons;
|
||||
|
||||
- (void)removeSubviews;
|
||||
|
||||
|
||||
// update with delegateObject
|
||||
- (nonnull instancetype)initButtonSmall:(BOOL)small buttonMap:(nullable NSDictionary *)buttonMap delegateObject:(nullable DelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData;
|
||||
|
||||
- (void)setupWithButtonMap:(nullable NSDictionary *)buttonMap delegateObject:(nullable DelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData;
|
||||
|
||||
- (void)setupWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap delegateObject:(nullable DelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData;
|
||||
|
||||
@end
|
||||
@ -0,0 +1,383 @@
|
||||
//
|
||||
// PrimaryButtonView.m
|
||||
// myverizon
|
||||
//
|
||||
// Created by Scott Pfeil on 12/11/15.
|
||||
// Copyright © 2015 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PrimaryButtonView.h"
|
||||
#import <MVMCore/NSDictionary+MFConvenience.h>
|
||||
#import <MVMCore/MVMCoreDispatchUtility.h>
|
||||
#import <MVMCore/MVMCoreJSONConstants.h>
|
||||
#import "MVMCoreUICommonViewsUtility.h"
|
||||
#import "MVMCoreUIConstants.h"
|
||||
#import "UIColor+MFConvenience.h"
|
||||
#import <MVMCoreUI/MVMCoreUI-Swift.h>
|
||||
@import MVMCore.Swift;
|
||||
|
||||
@interface PrimaryButtonView ()
|
||||
|
||||
@property (weak, nonatomic) UIView *twoButtonView;
|
||||
@property (weak, nonatomic) NSLayoutConstraint *alignCenterPin;
|
||||
@property (weak, nonatomic) NSLayoutConstraint *alignCenterLeftPin;
|
||||
@property (weak, nonatomic) NSLayoutConstraint *alignCenterRightPin;
|
||||
@property (weak, nonatomic) NSLayoutConstraint *height;
|
||||
|
||||
@property (nonatomic, strong) NSArray<NSLayoutConstraint *> *horizontalConstraints;
|
||||
|
||||
@end
|
||||
|
||||
@implementation PrimaryButtonView
|
||||
|
||||
- (void)updateView:(CGFloat)size {
|
||||
[super updateView:size];
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
[self.primaryButton updateView:size];
|
||||
[self.secondaryButton updateView:size];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
|
||||
[super setWithJSON:json delegateObject:delegateObject additionalData:additionalData];
|
||||
NSString *backgroundColorString = [json string:@"backgroundColor"];
|
||||
if (backgroundColorString) {
|
||||
self.backgroundColor = [UIColor mfGetColorForHex:backgroundColorString];
|
||||
}
|
||||
NSDictionary *primaryButtonMap = [json dict:@"primaryButton"];
|
||||
NSDictionary *secondaryButtonMap = [json dict:@"secondaryButton"];
|
||||
[self setupUIWithPrimaryButtonMap:primaryButtonMap secondaryButtonMap:secondaryButtonMap];
|
||||
[self.primaryButton setAsStandardCustom];
|
||||
[self.secondaryButton setAsSecondaryCustom];
|
||||
[self.primaryButton setWithJSON:primaryButtonMap delegateObject:delegateObject additionalData:additionalData];
|
||||
[self.secondaryButton setWithJSON:secondaryButtonMap delegateObject:delegateObject additionalData:additionalData];
|
||||
}
|
||||
|
||||
#pragma mark - Inits
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self setupWithSingleButton];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
|
||||
if (self = [super initWithCoder:aDecoder]) {
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self setupWithSingleButton];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self setupWithSingleButton];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nonnull instancetype)initButtonSmall:(BOOL)small enabled:(BOOL)enabled {
|
||||
if (self = [self init]) {
|
||||
[self.primaryButton setAsSmallButton:small];
|
||||
[self.primaryButton setEnabled:enabled];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nonnull instancetype)initWithTwoButtons {
|
||||
if (self = [self init]) {
|
||||
[self setupWithTwoButtons];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Legacy Setup
|
||||
|
||||
- (nonnull instancetype)initButtonSmall:(BOOL)small buttonMap:(nullable NSDictionary *)buttonMap actionDelegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id <ButtonDelegateProtocol>)buttonDelegate {
|
||||
if (self = [self init]) {
|
||||
[self setupWithButtonMap:buttonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate];
|
||||
[self.primaryButton setAsSmallButton:small];
|
||||
[self.secondaryButton setAsSmallButton:small];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nonnull instancetype)initWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap actionDelegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id <ButtonDelegateProtocol>)buttonDelegate {
|
||||
if (self = [self init]) {
|
||||
[self setupWithPrimaryButtonMap:primaryButtonMap secondaryButtonMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setupWithButtonMap:(nullable NSDictionary *)buttonMap actionDelegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id <ButtonDelegateProtocol>)buttonDelegate {
|
||||
NSDictionary *secondaryButtonMap = [buttonMap dict:KeySecondaryButton];
|
||||
NSDictionary *primaryButtonMap = [buttonMap dict:KeyPrimaryButton];
|
||||
[self setupWithPrimaryButtonMap:primaryButtonMap secondaryButtonMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate];
|
||||
}
|
||||
|
||||
- (void)setupWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap actionDelegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id <ButtonDelegateProtocol>)buttonDelegate {
|
||||
[self setupUIWithPrimaryButtonMap:primaryButtonMap secondaryButtonMap:secondaryButtonMap];
|
||||
if (primaryButtonMap && secondaryButtonMap) {
|
||||
[self.primaryButton setWithActionMap:primaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate];
|
||||
[self.secondaryButton setWithActionMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate];
|
||||
} else if (primaryButtonMap) {
|
||||
[self.primaryButton setWithActionMap:primaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate];
|
||||
self.primaryButton.bordered = NO;
|
||||
} else {
|
||||
[self.primaryButton setWithActionMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate];
|
||||
self.primaryButton.bordered = YES;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Setup
|
||||
|
||||
- (void)setupUIWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap {
|
||||
if (primaryButtonMap && secondaryButtonMap) {
|
||||
self.height.active = NO;
|
||||
|
||||
// Setup with two buttons
|
||||
if (!self.primaryButton || !self.secondaryButton) {
|
||||
[self removeSubviews];
|
||||
self.twoButtonView = nil;
|
||||
[self setupWithTwoButtons];
|
||||
}
|
||||
} else if (primaryButtonMap || secondaryButtonMap) {
|
||||
self.height.active = NO;
|
||||
|
||||
// Setup with one button.
|
||||
if (!self.primaryButton || self.secondaryButton) {
|
||||
[self removeSubviews];
|
||||
self.primaryButton = nil;
|
||||
self.secondaryButton = nil;
|
||||
[self setupWithSingleButton];
|
||||
}
|
||||
} else {
|
||||
[self removeSubviews];
|
||||
if (!self.height) {
|
||||
NSLayoutConstraint *height = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:0];
|
||||
height.active = YES;
|
||||
self.height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (id)createButton {
|
||||
return [PrimaryButton primaryButton:NO];
|
||||
}
|
||||
|
||||
- (void)setupWithTwoButtons {
|
||||
if (self.primaryButton) {
|
||||
[self.primaryButton removeFromSuperview];
|
||||
self.primaryButton = nil;
|
||||
}
|
||||
|
||||
if (!self.twoButtonView) {
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
|
||||
UIView *buttonView = [MVMCoreUICommonViewsUtility commonView];
|
||||
|
||||
PrimaryButton *leftButton = [PrimaryButton primaryButton];
|
||||
leftButton.bordered = YES;
|
||||
leftButton.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[buttonView addSubview:leftButton];
|
||||
self.secondaryButton = leftButton;
|
||||
|
||||
PrimaryButton *rightButton = [PrimaryButton primaryButton];
|
||||
rightButton.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[buttonView addSubview:rightButton];
|
||||
self.primaryButton = rightButton;
|
||||
|
||||
[rightButton.widthAnchor constraintEqualToAnchor:leftButton.widthAnchor multiplier:1].active = YES;
|
||||
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[leftButton]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(leftButton)]];
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[rightButton]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(rightButton)]];
|
||||
self.horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[leftButton]-10-[rightButton]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(leftButton,rightButton)];
|
||||
[NSLayoutConstraint activateConstraints:self.horizontalConstraints];
|
||||
[self addSubview:buttonView];
|
||||
|
||||
[self setupAlignmentsWithView:buttonView];
|
||||
|
||||
self.twoButtonView = buttonView;
|
||||
|
||||
[self alignCenter];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupWithSingleButton {
|
||||
|
||||
if (!self.primaryButton) {
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
|
||||
PrimaryButton *button = [self createButton];
|
||||
button.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self addSubview:button];
|
||||
self.primaryButton = button;
|
||||
|
||||
[self setupAlignmentsWithView:button];
|
||||
|
||||
[self alignCenter];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupAlignmentsWithView:(UIView *)view {
|
||||
// Align left and right constants.
|
||||
NSLayoutConstraint *leftPin = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
|
||||
self.leftPin = leftPin;
|
||||
leftPin.active = YES;
|
||||
|
||||
NSLayoutConstraint *topPin = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
|
||||
self.topPin = topPin;
|
||||
topPin.active = YES;
|
||||
|
||||
NSLayoutConstraint *bottomPin = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
|
||||
self.bottomPin = bottomPin;
|
||||
bottomPin.active = YES;
|
||||
|
||||
NSLayoutConstraint *rightPin = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
|
||||
self.rightPin = rightPin;
|
||||
rightPin.active = YES;
|
||||
|
||||
// Center alignments
|
||||
NSLayoutConstraint *alignCenter = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];
|
||||
self.alignCenterPin = alignCenter;
|
||||
alignCenter.active = YES;
|
||||
|
||||
NSLayoutConstraint *centerLeftPin = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
|
||||
self.alignCenterLeftPin = centerLeftPin;
|
||||
centerLeftPin.active = YES;
|
||||
|
||||
NSLayoutConstraint *centerRightPin = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
|
||||
self.alignCenterRightPin = centerRightPin;
|
||||
centerRightPin.active = YES;
|
||||
}
|
||||
|
||||
#pragma mark - Configuring
|
||||
|
||||
- (void)alignLeft {
|
||||
self.alignCenterPin.active = NO;
|
||||
self.alignCenterLeftPin.active = NO;
|
||||
self.alignCenterRightPin.active = YES;
|
||||
self.leftPin.active = YES;
|
||||
self.rightPin.active = NO;
|
||||
}
|
||||
|
||||
- (void)alignCenter {
|
||||
self.alignCenterPin.active = YES;
|
||||
self.alignCenterLeftPin.active = YES;
|
||||
self.alignCenterRightPin.active = YES;
|
||||
self.leftPin.active = NO;
|
||||
self.rightPin.active = NO;
|
||||
}
|
||||
|
||||
- (void)alignFill {
|
||||
self.alignCenterPin.active = NO;
|
||||
self.alignCenterLeftPin.active = NO;
|
||||
self.alignCenterRightPin.active = NO;
|
||||
self.leftPin.active = YES;
|
||||
self.rightPin.active = YES;
|
||||
}
|
||||
|
||||
- (void)alignRight {
|
||||
self.alignCenterPin.active = NO;
|
||||
self.alignCenterLeftPin.active = YES;
|
||||
self.alignCenterRightPin.active = NO;
|
||||
self.leftPin.active = NO;
|
||||
self.rightPin.active = YES;
|
||||
}
|
||||
|
||||
- (void)setLeftPinConstant:(CGFloat)constant {
|
||||
[super setLeftPinConstant:constant];
|
||||
self.alignCenterLeftPin.constant = constant;
|
||||
}
|
||||
|
||||
- (void)setRightPinConstant:(CGFloat)constant {
|
||||
[super setRightPinConstant:constant];
|
||||
self.alignCenterRightPin.constant = constant;
|
||||
}
|
||||
|
||||
- (void)resetConstraints {
|
||||
[super resetConstraints];
|
||||
self.primaryButton.enabled = NO;
|
||||
}
|
||||
|
||||
- (void)hidePrimaryLeftButton {
|
||||
if (!self.secondaryButton.hidden) {
|
||||
self.secondaryButton.hidden = YES;
|
||||
PrimaryButton *rightButton = self.primaryButton;
|
||||
[NSLayoutConstraint deactivateConstraints:self.horizontalConstraints];
|
||||
self.horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[rightButton]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(rightButton)];
|
||||
[NSLayoutConstraint activateConstraints:self.horizontalConstraints];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)hidePrimaryRightButton {
|
||||
if (!self.primaryButton.hidden) {
|
||||
self.primaryButton.hidden = YES;
|
||||
PrimaryButton *leftButton = self.secondaryButton;
|
||||
[NSLayoutConstraint deactivateConstraints:self.horizontalConstraints];
|
||||
self.horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[leftButton]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(leftButton)];
|
||||
[NSLayoutConstraint activateConstraints:self.horizontalConstraints];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showBothPrimaryButtons {
|
||||
self.primaryButton.hidden = NO;
|
||||
self.secondaryButton.hidden = NO;
|
||||
PrimaryButton *rightButton = self.primaryButton;
|
||||
PrimaryButton *leftButton = self.secondaryButton;
|
||||
[NSLayoutConstraint deactivateConstraints:self.horizontalConstraints];
|
||||
self.horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[leftButton]-10-[rightButton]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(leftButton,rightButton)];
|
||||
[NSLayoutConstraint activateConstraints:self.horizontalConstraints];
|
||||
}
|
||||
|
||||
- (void)hideBothPrimaryButtons {
|
||||
self.primaryButton.hidden = YES;
|
||||
self.secondaryButton.hidden = YES;
|
||||
}
|
||||
|
||||
- (void)removeSubviews {
|
||||
for (UIView *view in self.subviews) {
|
||||
[view removeFromSuperview];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// update with delegateObject
|
||||
- (nonnull instancetype)initButtonSmall:(BOOL)small buttonMap:(nullable NSDictionary *)buttonMap delegateObject:(nullable DelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData {
|
||||
NSObject<ButtonDelegateProtocol> *buttonDelegate;
|
||||
NSObject<MVMCoreActionDelegateProtocol> *actionDelegate = delegateObject.actionDelegate;
|
||||
if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) {
|
||||
buttonDelegate = ((MVMCoreUIDelegateObject *)delegateObject).buttonDelegate;
|
||||
}
|
||||
return [self initButtonSmall:small buttonMap:buttonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate];
|
||||
}
|
||||
|
||||
- (void)setupWithButtonMap:(nullable NSDictionary *)buttonMap delegate:(nullable DelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData {
|
||||
NSObject<ButtonDelegateProtocol> *buttonDelegate;
|
||||
NSObject<MVMCoreActionDelegateProtocol> *actionDelegate = delegateObject.actionDelegate;
|
||||
if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) {
|
||||
buttonDelegate = ((MVMCoreUIDelegateObject *)delegateObject).buttonDelegate;
|
||||
}
|
||||
[self setupWithButtonMap:buttonMap actionDelegate:actionDelegate additionalData:nil buttonDelegate:buttonDelegate];
|
||||
}
|
||||
|
||||
|
||||
- (void)setupWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap delegateObject:(nullable DelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData {
|
||||
NSObject<ButtonDelegateProtocol> *buttonDelegate;
|
||||
NSObject<MVMCoreActionDelegateProtocol> *actionDelegate = delegateObject.actionDelegate;
|
||||
if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) {
|
||||
buttonDelegate = ((MVMCoreUIDelegateObject *)delegateObject).buttonDelegate;
|
||||
}
|
||||
[self setupWithPrimaryButtonMap:primaryButtonMap secondaryButtonMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate];
|
||||
}
|
||||
|
||||
@end
|
||||
Loading…
Reference in New Issue
Block a user