-
Notifications
You must be signed in to change notification settings - Fork 448
Fix #322: Adjust height for popup when if it clips off screen #351
Conversation
@@ -467,6 +467,7 @@ class PopupView: UIView, UIGestureRecognizerDelegate { | |||
buttonData.isDefault = true | |||
buttonData.handler = tapped | |||
dialogButtons.append(buttonData) | |||
layoutSubviews() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't call layoutSubviews
directly. Instead make this call setNeedsLayout
and additionally layoutIfNeeded
if layout needs to happen instantly
resizePercentage = desiredHeight / containerViewFrame.height | ||
titleLabel.adjustsFontSizeToFitWidth = true | ||
messageLabel.adjustsFontSizeToFitWidth = true | ||
updateSubviews() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's probably never going to be a problem, but is it possible to get a solution that doesn't involve potential recursion? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads up. I've removed the recursion. Let me know what you think :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for submitting a PR! This will be a really nice thing to have, just a few random comments. Please let us know if you have any questions!
: kPopupDialogButtonHeight + paddingHeight | ||
|
||
if containerView.frame.height + externalContentHeight > UIScreen.main.bounds.height { | ||
let desiredHeight: CGFloat = UIScreen.main.bounds.height - externalContentHeight |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is actually functionally equivalent to the if
conditional logic right above it. Probably cleaner to create this constant outside the if
and just use it in the boolean logic:
let desiredHeight: CGFloat = UIScreen.main.bounds.height - externalContentHeight
if containerView.frame.height > desiredHeight {
// use `desiredHeight`
}
|
||
_updateSubviews() | ||
|
||
let paddingHeight: CGFloat = padding * 3.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove all unneeded manual type setting (e.g. the 3 CGFloat
instances)
} | ||
} | ||
|
||
fileprivate func _updateSubviews(_ resizePercentage: CGFloat = 1.0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Remove leading
_
- Make
resizePercentage
a named parameter (no leading_
here either.
let width: CGFloat = dialogWidth | ||
|
||
var imageFrame: CGRect = dialogImage?.frame ?? CGRect.zero | ||
if let dialogImage = dialogImage { | ||
imageFrame.size = CGSize(width: dialogImage.image!.size.width * resizePercentage, height: dialogImage.image!.size.height * resizePercentage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove image
forced casting (can unwrap inside the above if statement:
if let dialogImage = dialogImage, let dialogeImageSize = dialogImage.image?.size {
_updateSubviews() | ||
|
||
let paddingHeight: CGFloat = padding * 3.0 | ||
let externalContentHeight: CGFloat = dialogButtons.count == 0 ? paddingHeight |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed line break, think line is still decent length (< 120 at least), especially after removing the unneeded CGFloat
.
I've been thinking about this a bit more, and I think we can actually calculate all the necessary variables and setup what is needed before ever calling
and then use |
Thanks for the review, @jhreis! I've fixed all of the commented blocks. I'm not quite sure what you mean by
The variables required are only relevant after the subviews are updated initially. They then check if the new height can fit on the screen - if not, it will resize them again, this time to fit. This means that |
Ah, gotcha, I was thinking the height was precalculated, was imaging something like*. But see now why that wasn't possible.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So great! Thank you so much for your help!
Fixes issue 322
Opening a popup in landscape mode would clip the popup off the bottom of the screen for smaller devices. This happened because the height of the popup is set based on the contents of the popup without adjusting for the screen's height.
Pull Request Checklist
My patch has gone through review and I have addressed review comments
My patch has a standard commit message that looks like
Fix #123: This fixes the shattered coffee cup!
I have updated the Unit Tests to cover new or changed functionality
I have updated the UI Tests to cover new or changed functionality
I have marked the bug with
[needsuplift]
I have made sure that localizable strings use
NSLocalizableString()
Screenshots