deprecating

This commit is contained in:
Pfeil, Scott Robert 2019-04-15 11:14:29 -04:00
parent f1d80adf57
commit aa4da8f74f
4 changed files with 65 additions and 31 deletions

View File

@ -106,14 +106,14 @@ open class CaretButton: MFCustomButton {
//------------------------------------------------------
// Default values for view.
@objc open override func setAsMolecule() {
@objc open func setAsMolecule() {
backgroundColor = .clear
setTitleColor(enabledColor, for: .normal)
setTitleColor(disabledColor, for: .disabled)
}
@objc override open func setWithJSON(_ json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) {
@objc open func setWithJSON(_ json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) {
setWithActionMap(json, delegate: delegate as? (MVMCoreActionDelegateProtocol & NSObjectProtocol), additionalData: additionalData)
guard let dictionary = json else { return }

View File

@ -11,14 +11,14 @@
#import <MVMCoreUI/ButtonDelegateProtocol.h>
#import <MVMCoreUI/MFButtonProtocol.h>
#import <MVMCoreUI/MVMCoreUIMoleculeViewProtocol.h>
@import MVMCore.MVMCoreViewProtocol;
@class MVMCoreUIDelegateObject;
typedef void (^ButtonTapBlock)(id _Nonnull sender);
extern CGFloat const CloseButtonHeight;
extern CGFloat const CloseButtonWidth;
@interface MFCustomButton : UIButton <MFButtonProtocol, MVMCoreUIMoleculeViewProtocol>
@interface MFCustomButton : UIButton <MFButtonProtocol>
@property (nullable, nonatomic, strong) NSDictionary *actionMap;
@property (nullable, nonatomic, weak) id <ButtonDelegateProtocol> buttonDelegate;
@ -28,14 +28,19 @@ extern CGFloat const CloseButtonWidth;
- (void)addBlock:(nonnull ButtonTapBlock)buttonTapBlock forControlEvents:(UIControlEvents)event;
// Sets up the button with the passed in action map. Will set the title and set the action to use the action handler.
- (void)setWithActionMap:(nullable NSDictionary *)actionMap delegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)delegate additionalData:(nullable NSDictionary *)additionalData;
// Sets up the button with the passed in action map. Will set the title and set the action to use the action handler. Also pass in the button delegate
- (void)setWithActionMap:(nullable NSDictionary *)actionMap actionDelegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id <ButtonDelegateProtocol>)buttonDelegate;
- (void)setWithActionMap:(nullable NSDictionary *)actionMap delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData;
//accessibility
- (void)addAccessibilityForCameraControl;
- (nonnull UIAccessibilityCustomAction *)accessibilityCustomAction;
#pragma mark - Deprecated
// Sets up the button with the passed in action map. Will set the title and set the action to use the action handler.
- (void)setWithActionMap:(nullable NSDictionary *)actionMap delegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)delegate additionalData:(nullable NSDictionary *)additionalData __deprecated;
// Sets up the button with the passed in action map. Will set the title and set the action to use the action handler. Also pass in the button delegate
- (void)setWithActionMap:(nullable NSDictionary *)actionMap actionDelegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id <ButtonDelegateProtocol>)buttonDelegate __deprecated;
@end

View File

@ -13,6 +13,7 @@
@import MVMCore.NSDictionary_MFConvenience;
#import "MVMCoreUIUtility.h"
#import "MVMCoreUIConstants.h"
#import <MVMCoreUI/MVMCoreUI-Swift.h>
CGFloat const CloseButtonHeight = 40.0f;
CGFloat const CloseButtonWidth = 40.0f;
@ -37,6 +38,52 @@ CGFloat const CloseButtonWidth = 40.0f;
}
}
- (void)setWithActionMap:(nullable NSDictionary *)actionMap delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData {
self.actionMap = actionMap;
self.titleLabel.numberOfLines = 0;
self.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
[self setTitle:[actionMap stringForKey:KeyTitle] forState:UIControlStateNormal];
[self setEnabled:![actionMap[KeyDisableButton]boolValue]];
self.buttonDelegate = delegateObject.buttonDelegate;
__weak MFCustomButton *weakSelf = self;
[self addBlock:^(id _Nonnull sender) {
BOOL performAction = YES;
if (weakSelf.buttonDelegate && [weakSelf.buttonDelegate respondsToSelector:@selector(button:shouldPerformActionWithMap:additionalData:)]) {
performAction = [weakSelf.buttonDelegate button:weakSelf shouldPerformActionWithMap:actionMap additionalData:additionalData];
}
if (performAction) {
[[MVMCoreActionHandler sharedActionHandler] handleActionWithDictionary:actionMap additionalData:additionalData delegateObject:delegateObject];
}
} forControlEvents:UIControlEventTouchUpInside];
}
//accessibility
-(void)addAccessibilityForCameraControl{
self.accessibilityLabel = [MVMCoreUIUtility hardcodedStringWithKey:@"AccCameraButton"];
self.accessibilityHint = [MVMCoreUIUtility hardcodedStringWithKey:@"AccCameraHint"];
self.accessibilityTraits = UIAccessibilityTraitNone;
}
- (UIAccessibilityCustomAction *)accessibilityCustomAction {
NSString *name = self.accessibilityLabel ?: self.titleLabel.text;
return [[UIAccessibilityCustomAction alloc] initWithName:name target:self selector:@selector(performAccessibilityAction:)];
}
- (BOOL)performAccessibilityAction:(UIAccessibilityCustomAction *)action {
if (self.buttonTapBlock) {
self.buttonTapBlock(self);
}
return YES;
}
#pragma mark - Deprecated
- (void)setWithActionMap:(nullable NSDictionary *)actionMap delegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)delegate additionalData:(nullable NSDictionary *)additionalData {
self.actionMap = actionMap;
@ -53,11 +100,11 @@ CGFloat const CloseButtonWidth = 40.0f;
}
- (void)setWithActionMap:(nullable NSDictionary *)actionMap actionDelegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id <ButtonDelegateProtocol>)buttonDelegate {
if (!buttonDelegate) {
[self setWithActionMap:actionMap delegate:actionDelegate additionalData:additionalData];
} else {
self.actionMap = actionMap;
self.titleLabel.numberOfLines = 0;
self.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
@ -86,24 +133,4 @@ CGFloat const CloseButtonWidth = 40.0f;
}
}
//accessibility
-(void)addAccessibilityForCameraControl{
self.accessibilityLabel = [MVMCoreUIUtility hardcodedStringWithKey:@"AccCameraButton"];
self.accessibilityHint = [MVMCoreUIUtility hardcodedStringWithKey:@"AccCameraHint"];
self.accessibilityTraits = UIAccessibilityTraitNone;
}
- (UIAccessibilityCustomAction *)accessibilityCustomAction {
NSString *name = self.accessibilityLabel ?: self.titleLabel.text;
return [[UIAccessibilityCustomAction alloc] initWithName:name target:self selector:@selector(performAccessibilityAction:)];
}
- (BOOL)performAccessibilityAction:(UIAccessibilityCustomAction *)action {
if (self.buttonTapBlock) {
self.buttonTapBlock(self);
}
return YES;
}
@end

View File

@ -11,8 +11,10 @@ import UIKit
@objc(MVMCoreUIDelegateObject)
open class DelegateObject: MVMCore.DelegateObject {
public weak var formValidationProtocol: FormValidationProtocol?
public weak var buttonDelegate: ButtonDelegateProtocol?
open override func setAll(withDelegate delegate: Any) {
formValidationProtocol = delegate as? FormValidationProtocol
buttonDelegate = delegate as? ButtonDelegateProtocol
}
}