-
Notifications
You must be signed in to change notification settings - Fork 596
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
Fix a bug causing keyboard view offset to be incorrect #204
Conversation
In some rare cases, if the height of the view is a fractional point (i.e., not a whole number), it would cause the views to not be offset despite the keyboard being shown on top of them. This does not happen with every fractional height. Different devices also behave a little differently in seemingly identical layouts, due to their pixel density being different. The base issue is that, due to floating point rounding errors, two values that _should_ be identical and pass the guard fail to do so, because the lack of precision results in them not being equal. By flooring the values, we can ignore really minor differences and ensure rounding errors don't cause this issue.
Current coverage is 63.56% (diff: 66.66%)@@ master #204 diff @@
==========================================
Files 62 63 +1
Lines 3486 3488 +2
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 2215 2217 +2
Misses 1271 1271
Partials 0 0
|
Hi @dbburgess, thanks for the contribution. This is a nitpick, but I think it's more correct to use a pixel aware rounding instead of the plain floor, as we do in ChattoAdditions with bma_round() to avoid pixel misalignment. Could you create Utils.swift in Chatto/Source with
And then do
Note that bma_round() in ChattoAdditions is Thanks again! |
Thanks to @diegosanchezr for the suggested improvement.
41b7f16
to
38aebb1
Compare
Thanks @diegosanchezr, that's a good suggestion! Nitpicky or not, I appreciate your feedback, it certainly improves things. I made the change and verified it all seemed work correctly still. One minor detail is because I added |
Unfortunately, removing this in favor of the Chatto version broke size calculations, so putting it back...
1d9e529
to
86c1c79
Compare
Doh! That's unfortunate, good catch. I've made the suggested changes. Hopefully the build passes this time. 👍 |
Thanks again! |
In some rare cases, if the height of the view is a fractional point
(i.e., not a whole number), it would cause the views to not be offset
despite the keyboard being shown on top of them. This does not happen
with every fractional height. Different devices also behave a little
differently in seemingly identical layouts, due to their pixel density
being different.
The base issue is that, due to floating point rounding errors, two
values that should be identical and pass the guard fail to do so,
because the lack of precision results in them not being equal. By
flooring the values, we can ignore really minor differences and ensure
rounding errors don't cause this issue.
I added an example test case in the ChattoApp example project on
the
keyboard-issue
branch of my fork. You can see the bug in action here:The sample project illustrates the issue, outputting this when showing the keyboard:
maxY: 458.333333333333, height: 458.333333333333, equal?: false
Despite the values being nearly identical, they aren't quite equal (thanks floating point numbers!), resulting in the guard catch and returning 0, when it shouldn't. Flooring the values fixes this.
In my testing with the example, it only replicated on the iPhone Plus, but other devices seemed to be okay. I think this is due to different resolutions / densities resulting in a specific use case on that device. It could also possibly happen on other devices, this is just the specific instance I ran into. In any case, I think the fix should resolve it for all devices.