Skip to content

Commit

Permalink
Merge pull request #18197 from wordpress-mobile/fix/18190-ipad-remove…
Browse files Browse the repository at this point in the history
…-quickstart-crash

Fix: Crash when displaying remove quickstart action sheet on iPad
  • Loading branch information
hassaanelgarem authored Mar 24, 2022
2 parents a088a03 + 214c226 commit ef28092
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ NS_ASSUME_NONNULL_BEGIN

@interface UIViewController (RemoveQuickStart)

- (void)removeQuickStartFromBlog:(Blog *)blog;

/// Displays an action sheet with an option to remove current quickstart tours from the provided blog.
/// Displayed as an action sheet on iPhone and as a popover on iPad
/// @param blog Blog to remove quickstart from
/// @param sourceView View used as sourceView for the sheet's popoverPresentationController
/// @param sourceRect rect used as sourceRect for the sheet's popoverPresentationController
- (void)removeQuickStartFromBlog:(Blog *)blog sourceView:(UIView *)sourceView sourceRect:(CGRect)sourceRect;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@implementation UIViewController (RemoveQuickStart)

- (void)removeQuickStartFromBlog:(Blog *)blog
- (void)removeQuickStartFromBlog:(Blog *)blog sourceView:(UIView *)sourceView sourceRect:(CGRect)sourceRect
{
[NoticesDispatch lock];
NSString *removeTitle = NSLocalizedString(@"Remove Next Steps", @"Title for action that will remove the next steps/quick start menus.");
Expand All @@ -25,6 +25,8 @@ - (void)removeQuickStartFromBlog:(Blog *)blog
}];

UIAlertController *removeSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
removeSheet.popoverPresentationController.sourceView = sourceView;
removeSheet.popoverPresentationController.sourceRect = sourceRect;
[removeSheet addDestructiveActionWithTitle:removeTitle handler:^(UIAlertAction * _Nonnull action) {
[self presentViewController:removeConfirmation animated:YES completion:nil];
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class BlogDashboardCardFrameView: UIView {

weak var currentView: UIView?

/// Current frame of the ellipsis button. Used when displaying an action sheet as a popover.
var ellipsisButtonFrame: CGRect {
return ellipsisButton.frame
}

/// The title at the header
var title: String? {
didSet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class DashboardQuickStartCardCell: UICollectionViewCell, Reusable, BlogDas
let blog = self?.blog else {
return
}
viewController.removeQuickStart(from: blog)
viewController.removeQuickStart(from: blog, sourceView: frameView, sourceRect: frameView.ellipsisButtonFrame)
}
return frameView
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,9 @@ - (UIView *)quickStartHeaderWithTitle:(NSString *)title
BlogDetailsSectionHeaderView *view = [self.tableView dequeueReusableHeaderFooterViewWithIdentifier:BlogDetailsSectionHeaderViewIdentifier];
[view setTitle:title];
view.ellipsisButtonDidTouch = ^(BlogDetailsSectionHeaderView *header) {
[weakSelf removeQuickStartFromBlog:weakSelf.blog];
[weakSelf removeQuickStartFromBlog:weakSelf.blog
sourceView:header
sourceRect:header.ellipsisButton.frame];
};
return view;
}
Expand Down

0 comments on commit ef28092

Please sign in to comment.