Skip to content

Commit

Permalink
Merge pull request #561 from mlch911/fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Wei18 authored Mar 18, 2024
2 parents 4bb227d + 6e56ff1 commit e70a84a
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ @interface AbstractActionSheetPicker () <UIGestureRecognizerDelegate>
@property(nonatomic, assign) SEL successAction;
@property(nonatomic, assign) SEL cancelAction;
@property(nonatomic, strong) UIViewController *popOverViewController;
@property(nonatomic, strong) UITapGestureRecognizer *windowTapAction;
@property(nonatomic, assign) NSInteger windowTapActionRetryCount;
@property(nonatomic, strong) CIFilter *filter;
@property(nonatomic, strong) CIContext *context;
@property(nonatomic, strong) NSObject *selfReference;
Expand Down Expand Up @@ -287,38 +289,51 @@ - (void)showActionSheetPicker {
[self presentPickerForView:masterView];
}

[self addTapDismissAction];
}

- (void)addTapDismissAction {
if (!self.pickerView) {
NSAssert(_pickerView != NULL, @"Picker view failed to instantiate, perhaps you have invalid component data.");
return;
}
if (self.windowTapActionRetryCount > 10) {
NSAssert(NO, @"Failed to find Picker view's window. This may cause a memory leak.");
}
if (!self.pickerView.window) {
self.windowTapActionRetryCount += 1;
dispatch_async(dispatch_get_main_queue(), ^{
[self addTapDismissAction];
});
return;
}

#pragma clang diagnostic push
#pragma ide diagnostic ignored "UnavailableInDeploymentTarget"
{
SEL sel;
switch (self.tapDismissAction) {
case TapActionDismiss: {
case TapActionDismiss:
// add tap dismiss action
self.actionSheet.superview.userInteractionEnabled = YES;
UITapGestureRecognizer *tapAction = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissPicker)];
tapAction.delegate = self;
[self.actionSheet.superview addGestureRecognizer:tapAction];
sel = @selector(dismissPicker);
break;
}
case TapActionSuccess: {
case TapActionSuccess:
// add tap success action with dismissPicker
self.actionSheet.superview.userInteractionEnabled = YES;
UITapGestureRecognizer *tapAction = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionPickerDone:)];
tapAction.delegate = self;
[self.actionSheet.superview addGestureRecognizer:tapAction];
sel = @selector(actionPickerDone:);
break;
}
case TapActionCancel: {
case TapActionCancel:
// add tap cancel action with dismissPicker
self.actionSheet.superview.userInteractionEnabled = YES;
UITapGestureRecognizer *tapAction = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionPickerCancel:)];
tapAction.delegate = self;
[self.actionSheet.superview addGestureRecognizer:tapAction];
sel = @selector(actionPickerCancel:);
break;
}
};
if (sel) {
self.actionSheet.window.userInteractionEnabled = YES;
self.windowTapAction = [[UITapGestureRecognizer alloc] initWithTarget:self action:sel];
self.windowTapAction.delegate = self;
[self.actionSheet.window addGestureRecognizer:self.windowTapAction];
}
}
#pragma clang diagnostic pop

}

- (IBAction)actionPickerDone:(id)sender {
Expand All @@ -339,6 +354,7 @@ - (void)dismissPicker {
self.actionSheet = nil;
self.popOverViewController = nil;
self.selfReference = nil;
[self.pickerView.window removeGestureRecognizer:self.windowTapAction];
}

#pragma mark - Custom Buttons
Expand Down Expand Up @@ -797,6 +813,13 @@ - (void)presentPopover:(UIViewController *)viewController {

#pragma mark UIGestureRecognizerDelegate

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if (IS_IPAD) {
return YES;
}
return NO;
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
CGPoint toolbarLocation = [gestureRecognizer locationInView:self.toolbar];
CGPoint actionSheetLocation = [gestureRecognizer locationInView:self.actionSheet];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ @implementation ActionSheetDatePicker
@synthesize datePickerStyle = _datePickerStyle;


-(UIDatePickerStyle)datePickerStyle {
- (UIDatePickerStyle)datePickerStyle {
if (_datePickerStyle != UIDatePickerStyleAutomatic) {
return _datePickerStyle;
} else {
Expand Down Expand Up @@ -168,7 +168,7 @@ - (instancetype)initWithTitle:(NSString *)title
}

- (UIView *)configuredPickerView {
CGRect datePickerFrame = CGRectMake(0, 40, self.viewSize.width, 216);
CGRect datePickerFrame = CGRectMake(0, 44, self.viewSize.width, self.getDatePickerHeight);
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:datePickerFrame];
datePicker.datePickerMode = self.datePickerMode;
datePicker.maximumDate = self.maximumDate;
Expand Down Expand Up @@ -290,14 +290,13 @@ - (void)customButtonPressed:(id)sender {
}
}

- (CGFloat)getDatePickerHeight
{
- (CGFloat)getDatePickerHeight {
CGFloat height = 216.0;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 // Xcode 12 and iOS 14, or greater
if (@available(iOS 14.0, *)) {
if (_datePickerStyle == UIDatePickerStyleCompact) {
if (self.datePickerStyle == UIDatePickerStyleCompact) {
height = 90.0;
} else if (_datePickerStyle == UIDatePickerStyleInline) {
} else if (self.datePickerStyle == UIDatePickerStyleInline) {
switch (_datePickerMode) {
case UIDatePickerModeDate:
height = 350.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright (c) 2012 Club 15CC. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <AbstractActionSheetPicker.h>
#import <ActionSheetCustomPickerDelegate.h>
#import "AbstractActionSheetPicker.h"
#import "ActionSheetCustomPickerDelegate.h"

@interface ActionSheetCustomPicker : AbstractActionSheetPicker
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import <UIKit/UIKit.h>
#import <AbstractActionSheetPicker.h>
#import "AbstractActionSheetPicker.h"

@protocol ActionSheetCustomPickerDelegate <UIPickerViewDelegate, UIPickerViewDataSource>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#import <AbstractActionSheetPicker.h>
#import "AbstractActionSheetPicker.h"

@class ActionSheetDatePicker;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#import <AbstractActionSheetPicker.h>
#import <DistancePickerView.h>
#import "AbstractActionSheetPicker.h"
#import "DistancePickerView.h"

@interface ActionSheetDistancePicker : AbstractActionSheetPicker <UIPickerViewDelegate, UIPickerViewDataSource>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#import <AbstractActionSheetPicker.h>
#import "AbstractActionSheetPicker.h"

@class ActionSheetLocalePicker;
typedef void(^ActionLocaleDoneBlock)(ActionSheetLocalePicker *picker, NSTimeZone * selectedValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#import <AbstractActionSheetPicker.h>
#import "AbstractActionSheetPicker.h"

@class ActionSheetMultipleStringPicker;
typedef void(^ActionMultipleStringDoneBlock)(ActionSheetMultipleStringPicker *picker, NSArray *selectedIndexes, id selectedValues);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#import <AbstractActionSheetPicker.h>
#import "AbstractActionSheetPicker.h"

@class ActionSheetStringPicker;
typedef void(^ActionStringDoneBlock)(ActionSheetStringPicker *picker, NSInteger selectedIndex, id selectedValue);
Expand Down

0 comments on commit e70a84a

Please sign in to comment.