Skip to content

Conversation

@KashishGoel
Copy link
Contributor

@KashishGoel KashishGoel commented Mar 11, 2018

PR is based on the suggestions in GitHawkApp/GitHawk#1613

Additions

  • ability to set max ratio of screen to use for message view
  • ability to set maxHeight of message view
  • works well for devices with a hardware keyboard attached

Tested On

  • Devices: iPhone 7,8
  • Simulators: iPhone 5s, X

@KashishGoel
Copy link
Contributor Author

KashishGoel commented Mar 11, 2018

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

Copy link
Member

@rnystrom rnystrom left a 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?

}

internal var buttonAction: Selector?
internal var keyboardHeight: CGFloat = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these used?

Copy link
Contributor Author

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.


public var maxScreenRatio: CGFloat = 0 {
didSet {
maxScreenRatio = 0...1 ~= maxScreenRatio ? maxScreenRatio : 0
Copy link
Member

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

Copy link
Contributor Author

@KashishGoel KashishGoel Mar 16, 2018

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
Copy link
Member

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.

Copy link
Contributor Author

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

@KashishGoel
Copy link
Contributor Author

We could add explicit height as its own customization. Something like
public var maxMessageViewHeight

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.

@KashishGoel
Copy link
Contributor Author

@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.

@rnystrom rnystrom merged commit d985cf5 into GitHawkApp:master Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants