Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LGAlertViewStyleActionSheet misplaced on iPhone X #36

Open
mickeyl opened this issue Sep 15, 2017 · 5 comments
Open

LGAlertViewStyleActionSheet misplaced on iPhone X #36

mickeyl opened this issue Sep 15, 2017 · 5 comments

Comments

@mickeyl
Copy link

mickeyl commented Sep 15, 2017

On iPhone X, LGAlertViewStyleActionSheet overlays the home indicator bar, which violates the Apple HIG.

@heroims
Copy link
Contributor

heroims commented Sep 21, 2017

you can set alert.cancelButtonOffsetY=20;

@mickeyl
Copy link
Author

mickeyl commented Sep 21, 2017

Thanks, @heroims. While this is a fine workaround for iPhone X, to make it work everywhere, I'd rather suggest consulting the safe area (or bottom layout margin to make it compatible with iOS < 11) instead.

@Mr-yuwei
Copy link

Mr-yuwei commented Nov 5, 2018

safe area not support yet

@techinpark2
Copy link

@mickeyl are you resolved this issue???
in my case alert.cancelButtonOffsetY=20; is not working..

@mickeyl
Copy link
Author

mickeyl commented Dec 15, 2018

I'm not too proud of this patch, but it's a quick fix. The layout code of LGAlertView is very convoluted, almost unmaintainable in my humble opinion. The major issue is that layoutValidateWithSize only respects the size, thinking it can fill the whole container area. A proper fix would a) need to rewrite this to handle insets on all possible sides, and b) adjust the LGAlertViewController to handle viewSafeAreaInsetsDidChange, because getting the safe area insets from the previous key window is hacky as well.

Anyways, here's the quick workaround in case it's helpful:

diff --git a/LGAlertView/LGAlertView.m b/LGAlertView/LGAlertView.m
index 0d78d95..d644fb9 100644
--- a/LGAlertView/LGAlertView.m
+++ b/LGAlertView/LGAlertView.m
@@ -121,6 +121,7 @@ @interface LGAlertView () <UITableViewDataSource, UITableViewDelegate, UITextFie
 @property (assign, nonatomic) LGAlertViewType type;

 @property (assign, nonatomic) CGFloat keyboardHeight;
+@property (assign, nonatomic) CGFloat safeAreaBottomInset;

 @property (strong, nonatomic) NSMutableDictionary *buttonsPropertiesDictionary;
 @property (strong, nonatomic) NSMutableArray *buttonsEnabledArray;
@@ -1541,6 +1542,10 @@ - (void)showAnimated:(BOOL)animated hidden:(BOOL)hidden completionHandler:(LGAle

     self.window.windowLevel = UIWindowLevelStatusBar + (self.windowLevel == LGAlertViewWindowLevelAboveStatusBar ? 1 : -1);
     self.view.userInteractionEnabled = NO;
+    if ( @available( iOS 11.0, * ) )
+    {
+        self.safeAreaBottomInset = [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom;
+    }

     CGSize size = self.viewController.view.bounds.size;

@@ -2797,7 +2802,7 @@ - (void)layoutValidateWithSize:(CGSize)size {
     }
     else
     {
-        CGFloat bottomShift = self.offsetVertical;
+        CGFloat bottomShift = self.offsetVertical + self.safeAreaBottomInset / 2.0;

         if (kLGAlertViewIsCancelButtonSeparate(self) && self.cancelButton) {
             bottomShift += self.buttonsHeight+self.cancelButtonOffsetY;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants