-
Notifications
You must be signed in to change notification settings - Fork 93
Dynamically increase textview size according to maxScreenRatio #39
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
Conversation
One comment: the available screen is calculated as the screen available without the software keyboard. I'm on the fence about changing it to the available screen after keyboard height is factored in. The reason this matters is because if you consider a screen size of 640 and set the available screen ratio to 0.3. You have 192 screen space available for the message view. But when the keyboard is up you take away the height effectively making it < 0 so the maxLines overrides this value. @rnystrom |
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.
Is there a way to make this behavior optional? I want to make sure that if someone wants an explicit max height, that's always used. Would that be setting the maxScreenRatio
to 1?
@@ -27,6 +27,11 @@ public final class MessageView: UIView, MessageTextViewListener { | |||
case right | |||
} | |||
|
|||
internal var buttonAction: Selector? | |||
internal var keyboardHeight: CGFloat = 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.
Are these used?
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.
Whoops, forgot to delete. Thanks for the catch.
@@ -163,6 +168,13 @@ public final class MessageView: UIView, MessageTextViewListener { | |||
} | |||
} | |||
|
|||
public var maxScreenRatio: CGFloat = 0 { | |||
didSet { | |||
maxScreenRatio = 0...1 ~= maxScreenRatio ? maxScreenRatio : 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.
Wo! What is this syntax? Haha
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.
it checks if maxScreenRatio is within the range 0-1. If it isn't we default to 0 since we never want the message view frame to be bigger than our view frame. ~= is used for pattern matching
|
||
|
||
internal var maxScreenHeight: CGFloat { | ||
return maxScreenRatio * (superview?.frame.height ?? 0) - heightOffset |
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.
Isn't this using the kb height now w/ the offset? I agree that we shouldn't account for this at all. If anything, it should be optional.
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.
gotcha, will add this as another customization option
We could add explicit height as its own customization. Something like This would override both LineHeight and ScreenRatio. The purpose of screen ratio is to optimize for different screen sizes, so instead of setting one maxValue for each screen (e.g. 150) we can change the amount depending on how much space the screen has. Currently, the behavior of screenRatio is optional because we initialize it to 0 by default and maxLinesHeight is used instead because it is initialized to 4 by default. |
@rnystrom added your suggestion of allowing them to set a maxHeight. So now the message view height is set to the minimum of the max line height, max height (cgfloat) and max screen ratio which is defaulted to be set to 1. The only caveat with this is if you want to set a custom maxHeight that is larger than 4 * line height (4 is our default line count) we need to ensure the user sets line count to 0. Similar to how we set UILabel.numberOfLines to 0 to allow it to grow. |
PR is based on the suggestions in GitHawkApp/GitHawk#1613
Additions
Tested On