Skip to content

Commit

Permalink
增加 .leeShouldClose(^{ return YES; })
Browse files Browse the repository at this point in the history
增加 .leeShouldActionClickClose(^(NSInteger index){ return YES; })
增加 + (void)closeWithIdentifier:(NSString *)identifier force:(BOOL)force completionBlock:(void (^ _Nullable)(void))completionBlock;
  • Loading branch information
lixiang1994 committed Apr 18, 2019
1 parent 9ae4018 commit 6c6e588
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 79 deletions.
2 changes: 1 addition & 1 deletion LEEAlert.podspec
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "LEEAlert"
s.version = "1.2.2"
s.version = "1.2.3"
s.summary = "优雅的Alert ActionSheet"

s.homepage = "https://github.com/lixiang1994/LEEAlert"
Expand Down
18 changes: 17 additions & 1 deletion LEEAlert/LEEAlert.h
Expand Up @@ -13,7 +13,7 @@
*
* @author LEE
* @copyright Copyright © 2016 - 2018年 lee. All rights reserved.
* @version V1.2.2
* @version V1.2.3
*/

#import <Foundation/Foundation.h>
Expand Down Expand Up @@ -83,9 +83,19 @@ NS_ASSUME_NONNULL_BEGIN
关闭指定标识
@param identifier 标识
@param completionBlock 关闭完成回调
*/
+ (void)closeWithIdentifier:(NSString *)identifier completionBlock:(void (^ _Nullable)(void))completionBlock;

/**
关闭指定标识
@param identifier 标识
@param force 是否强制关闭
@param completionBlock 关闭完成回调
*/
+ (void)closeWithIdentifier:(NSString *)identifier force:(BOOL)force completionBlock:(void (^ _Nullable)(void))completionBlock;

/**
关闭当前
Expand Down Expand Up @@ -251,6 +261,12 @@ NS_ASSUME_NONNULL_BEGIN
/** 设置 ActionSheet距离屏幕底部的间距 -> 格式: .LeeActionSheetBottomMargin(10.0f) */
@property (nonatomic , copy , readonly ) LEEConfigToFloat LeeActionSheetBottomMargin;

/** 设置 是否可以关闭 -> 格式: .leeShouldClose(^{ return YES; }) */
@property (nonatomic, copy, readonly ) LEEConfigToBlockReturnBool leeShouldClose;

/** 设置 是否可以关闭(Action 点击) -> 格式: .leeShouldActionClickClose(^(NSInteger index){ return YES; }) */
@property (nonatomic, copy, readonly ) LEEConfigToBlockIntegerReturnBool leeShouldActionClickClose;

/** 设置 当前关闭回调 -> 格式: .LeeCloseComplete(^{ //code.. }) */
@property (nonatomic , copy , readonly ) LEEConfigToBlock LeeCloseComplete;

Expand Down
170 changes: 96 additions & 74 deletions LEEAlert/LEEAlert.m
Expand Up @@ -13,7 +13,7 @@
*
* @author LEE
* @copyright Copyright © 2016 - 2018年 lee. All rights reserved.
* @version V1.2.2
* @version V1.2.3
*/

#import "LEEAlert.h"
Expand Down Expand Up @@ -76,6 +76,8 @@ @interface LEEAlertConfigModel ()
@property (nonatomic , copy ) void(^modelOpenAnimationConfigBlock)(void (^animatingBlock)(void) , void (^animatedBlock)(void));
@property (nonatomic , copy ) void(^modelCloseAnimationConfigBlock)(void (^animatingBlock)(void) , void (^animatedBlock)(void));
@property (nonatomic , copy ) void (^modelFinishConfig)(void);
@property (nonatomic , copy ) BOOL (^modelShouldClose)(void);
@property (nonatomic , copy ) BOOL (^modelShouldActionClickClose)(NSInteger);
@property (nonatomic , copy ) void (^modelCloseComplete)(void);

@property (nonatomic , assign ) LEEBackgroundStyle modelBackgroundStyle;
Expand Down Expand Up @@ -169,7 +171,13 @@ - (instancetype)init

};

_modelShouldClose = ^{
return YES;
};

_modelShouldActionClickClose = ^(NSInteger index){
return YES;
};
}
return self;
}
Expand Down Expand Up @@ -804,6 +812,28 @@ - (LEEConfigToColor)LeeActionSheetBackgroundColor{

}

- (LEEConfigToBlockReturnBool)leeShouldClose{

return ^(BOOL (^block)(void)){

self.modelShouldClose = block;

return self;
};

}

- (LEEConfigToBlockIntegerReturnBool)leeShouldActionClickClose{

return ^(BOOL (^block)(NSInteger index)){

self.modelShouldActionClickClose = block;

return self;
};

}

- (LEEConfigToBlock)LeeCloseComplete{

return ^(void (^block)(void)){
Expand Down Expand Up @@ -912,7 +942,11 @@ + (void)clearQueue{
[[LEEAlert shareManager].queueArray removeAllObjects];
}

+ (void)closeWithIdentifier:(NSString *)identifier completionBlock:(void (^)(void))completionBlock{
+ (void)closeWithIdentifier:(NSString *)identifier completionBlock:(void (^ _Nullable)(void))completionBlock{
[self closeWithIdentifier:identifier force:NO completionBlock:completionBlock];
}

+ (void)closeWithIdentifier:(NSString *)identifier force:(BOOL)force completionBlock:(void (^)(void))completionBlock{

if ([LEEAlert shareManager].queueArray.count) {

Expand All @@ -931,6 +965,9 @@ + (void)closeWithIdentifier:(NSString *)identifier completionBlock:(void (^)(voi
if (model.modelIdentifier != nil && [identifier isEqualToString: model.modelIdentifier]) {

if (i == count - 1 && [[LEEAlert shareManager] viewController]) {
if (force) {
model.modelShouldClose = ^{ return YES; };
}

isLast = true;

Expand Down Expand Up @@ -2014,49 +2051,44 @@ - (void)configAlert{

}

- (void)buttonAction:(UIButton *)sender{
- (void)buttonAction:(LEEActionButton *)sender{

BOOL isClose = NO;

void (^clickBlock)(void) = nil;

for (LEEActionButton *button in self.alertActionArray) {

if (button == sender) {
switch (sender.action.type) {

switch (button.action.type) {

case LEEActionTypeDefault:

isClose = button.action.isClickNotClose ? NO : YES;

break;

case LEEActionTypeCancel:

isClose = YES;

break;

case LEEActionTypeDestructive:

isClose = YES;

break;

default:
break;
}
case LEEActionTypeDefault:

clickBlock = button.action.clickBlock;
isClose = sender.action.isClickNotClose ? NO : YES;

break;
}


case LEEActionTypeCancel:

isClose = YES;

break;

case LEEActionTypeDestructive:

isClose = YES;

break;

default:
break;
}

clickBlock = sender.action.clickBlock;

NSInteger index = [self.alertActionArray indexOfObject:sender];

if (isClose) {

if (self.config.modelShouldActionClickClose && !self.config.modelShouldActionClickClose(index)) return;

[self closeAnimationsWithCompletionBlock:^{

if (clickBlock) clickBlock();
Expand Down Expand Up @@ -2178,6 +2210,7 @@ - (void)closeAnimationsWithCompletionBlock:(void (^)(void))completionBlock{
[super closeAnimationsWithCompletionBlock:completionBlock];

if (self.isClosing) return;
if (self.config.modelShouldClose && !self.config.modelShouldClose()) return;

self.isClosing = YES;

Expand Down Expand Up @@ -2682,7 +2715,7 @@ - (void)configActionSheet{
switch (action.type) {
case LEEActionTypeCancel:
{
[button addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

button.layer.cornerRadius = self.config.modelCornerRadius;

Expand Down Expand Up @@ -2732,48 +2765,47 @@ - (void)configActionSheet{

}

- (void)buttonAction:(UIButton *)sender{
- (void)buttonAction:(LEEActionButton *)sender{

BOOL isClose = NO;

NSInteger index = 0;
void (^clickBlock)(void) = nil;

for (LEEActionButton *button in self.actionSheetActionArray) {

if (button == sender) {
switch (sender.action.type) {
case LEEActionTypeDefault:

switch (button.action.type) {
case LEEActionTypeDefault:

isClose = button.action.isClickNotClose ? NO : YES;

break;

case LEEActionTypeCancel:

isClose = YES;

break;

case LEEActionTypeDestructive:

isClose = YES;

break;

default:
break;
}
isClose = sender.action.isClickNotClose ? NO : YES;

clickBlock = button.action.clickBlock;
index = [self.actionSheetActionArray indexOfObject:sender];

break;
}


case LEEActionTypeCancel:

isClose = YES;

index = self.actionSheetActionArray.count;

break;

case LEEActionTypeDestructive:

isClose = YES;

index = [self.actionSheetActionArray indexOfObject:sender];

break;

default:
break;
}

clickBlock = sender.action.clickBlock;

if (isClose) {

if (self.config.modelShouldActionClickClose && !self.config.modelShouldActionClickClose(index)) return;

[self closeAnimationsWithCompletionBlock:^{

if (clickBlock) clickBlock();
Expand All @@ -2786,17 +2818,6 @@ - (void)buttonAction:(UIButton *)sender{

}

- (void)cancelButtonAction:(UIButton *)sender{

void (^clickBlock)(void) = self.actionSheetCancelAction.action.clickBlock;

[self closeAnimationsWithCompletionBlock:^{

if (clickBlock) clickBlock();
}];

}

- (void)headerTapAction:(UITapGestureRecognizer *)tap{

if (self.config.modelIsClickHeaderClose) [self closeAnimationsWithCompletionBlock:nil];
Expand Down Expand Up @@ -2917,6 +2938,7 @@ - (void)closeAnimationsWithCompletionBlock:(void (^)(void))completionBlock{
[super closeAnimationsWithCompletionBlock:completionBlock];

if (self.isClosing) return;
if (self.config.modelShouldClose && !self.config.modelShouldClose()) return;

self.isClosing = YES;

Expand Down
4 changes: 3 additions & 1 deletion LEEAlert/LEEAlertHelper.h
Expand Up @@ -13,7 +13,7 @@
*
* @author LEE
* @copyright Copyright © 2016 - 2018年 lee. All rights reserved.
* @version V1.2.2
* @version V1.2.3
*/

#ifndef LEEAlertHelper_h
Expand Down Expand Up @@ -125,6 +125,8 @@ typedef LEEAlertConfigModel * _Nonnull (^LEEConfigToConfigLabel)(void(^ _Nullabl
typedef LEEAlertConfigModel * _Nonnull (^LEEConfigToConfigTextField)(void(^ _Nullable)(UITextField *textField));
typedef LEEAlertConfigModel * _Nonnull (^LEEConfigToItem)(void(^)(LEEItem *item));
typedef LEEAlertConfigModel * _Nonnull (^LEEConfigToBlock)(void(^block)(void));
typedef LEEAlertConfigModel * _Nonnull (^LEEConfigToBlockReturnBool)(BOOL(^block)(void));
typedef LEEAlertConfigModel * _Nonnull (^LEEConfigToBlockIntegerReturnBool)(BOOL(^block)(NSInteger index));
typedef LEEAlertConfigModel * _Nonnull (^LEEConfigToBlockAndBlock)(void(^)(void (^animatingBlock)(void) , void (^animatedBlock)(void)));

typedef LEEAlertConfigModel * _Nonnull (^LEEConfigToStatusBarStyle)(UIStatusBarStyle style);
Expand Down
10 changes: 8 additions & 2 deletions LEEAlertDemo/LEEAlertDemo/AlertTableViewController.m
Expand Up @@ -163,8 +163,14 @@ - (void)base:(NSInteger)index{
tf = textField; //赋值
})
.LeeAction(@"好的", ^{

[tf resignFirstResponder];

})
.leeShouldActionClickClose(^(NSInteger index){
// 是否可以关闭回调, 当即将关闭时会被调用 根据返回值决定是否执行关闭处理
// 这里演示了与输入框非空校验结合的例子
BOOL result = ![tf.text isEqualToString:@""];
result = index == 0 ? result : YES;
return result;
})
.LeeCancelAction(@"取消", nil) // 点击事件的Block如果不需要可以传nil
.LeeShow();
Expand Down

0 comments on commit 6c6e588

Please sign in to comment.