freshOS / KeyboardLayoutGuide

⌨️ KeyboardLayoutGuide, back from when it didn't exist.
MIT License
1.19k stars 60 forks source link

Support tab bar height #34

Open MikeDonahue opened 4 years ago

MikeDonahue commented 4 years ago

We had an issue when using this when a keyboard was being used in a VC that was presented modally by a tab controller, when the tab bar isn't visible.

The following comment presented a solution that worked: https://github.com/freshOS/KeyboardLayoutGuide/issues/19#issuecomment-468267299

But it only checked if the root view controller was a tab bar. My solution will look at the current visible view controller, and check if it has a tab bar controller where it is not hidden, and account for the tab bar height.

This works in our app with a pretty complicated navigation setup with Navigation Controllers and Tab Controllers, pushing and presenting, but it would be nice to get some other testing on this in other cases. Worst case, it will not change anything if the current view controller doesn't have a tabBarController.

s4cha commented 2 years ago

Hey @MikeDonahue, thanks a ton for taking the time to solve this issue for everyone else. Sadly, I have tried to reproduce this issue to no avail. Could you provide a sample code/project that would trigger this issue? I'd love to see (and understand) the fix before merging. Cheers,

MikeDonahue commented 2 years ago

Sorry for just now seeing this @s4cha, I'd have to spend some time putting together a sample project, but I can quickly describe the setup that triggered this.

  1. Set up a UITabBarController with a UINavigationController as a tab's view controller.
  2. Push a view controller (inside the tab view, so the tabs are still visible after the push) with a text view/field that is constraint to the keyboard layout guide.

To show you before the textview becomes the first responder....

Screen Shot 2022-03-15 at 3 20 43 PM

As it becomes the first responder, you should see that there is an extra space from the keyboard layout guide because the tab bar height isn't factored into the constraint constant when the keyboard is shown.

Screen Shot 2022-03-15 at 3 20 49 PM

And after this PR's adjustments...

Screen Shot 2022-03-15 at 3 23 20 PM