fix(footer): remove toolbar bottom padding if near bottom slot tabs or keyboard is open#25746
Merged
Conversation
…rd is open Co-authored-by: EinfachHans <EinfachHans@users.noreply.github.com>
13 tasks
sean-perkins
suggested changes
Aug 10, 2022
Contributor
|
One possible approach to sharing the logic across both implementations would be through a controller, similar to how we handle modal, popover, menu, etc. const createKeyboardController = () => {
let keyboardWillShowHandler: (() => void) | undefined;
let keyboardWillHideHandler: (() => void) | undefined;
let keyboardVisible: boolean;
const init = (el?: HTMLElement) => {
keyboardWillShowHandler = () => {
if (el && el.getAttribute('slot') !== 'top') {
keyboardVisible = true;
}
};
keyboardWillHideHandler = () => {
setTimeout(() => (keyboardVisible = false), 50);
};
window.addEventListener('keyboardWillShow', keyboardWillShowHandler!);
window.addEventListener('keyboardWillHide', keyboardWillHideHandler!);
}
const destroy = () => {
if (typeof window !== 'undefined') {
window.removeEventListener('keyboardWillShow', keyboardWillShowHandler!);
window.removeEventListener('keyboardWillHide', keyboardWillHideHandler!);
keyboardWillShowHandler = keyboardWillHideHandler = undefined;
}
}
const isKeyboardVisible = () => keyboardVisible;
return { init, destroy, isKeyboardVisible };
}private keyboardCtrl: any; // TODO type
connectedCallback() {
this.keyboardCtrl = createKeyboardController();
this.keyboardCtrl.init(this.el);
}
disconnectedCallback() {
if (this.keyboardCtrl) {
this.keyboardCtrl.destroy();
}
}In your implementation you need to trigger a re-render when the keyboard visibility changes. For this, you may need to pass in a callback that can trigger your state variable to re-render. |
liamdebeasi
reviewed
Aug 12, 2022
liamdebeasi
reviewed
Aug 15, 2022
liamdebeasi
approved these changes
Aug 15, 2022
Contributor
liamdebeasi
left a comment
There was a problem hiding this comment.
Great job! This is good to go once tests for the keyboard controller are written.
sean-perkins
suggested changes
Aug 15, 2022
sean-perkins
approved these changes
Aug 16, 2022
7 tasks
This was referenced Sep 1, 2022
7 tasks
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request checklist
Please check if your PR fulfills the following requirements:
ionic-docsrepo, in a separate PR. See the contributing guide for details.npm run build) was run locally and any changes were pushednpm run lint) has passed locally and any fixes were made for failuresPull request type
Please check the type of change your PR introduces:
What is the current behavior?
Currently, an
ion-toolbarinside anion-footerreceives bottom padding according to the safe area, via this CSS. However, this padding becomes unnecessary if there is also anion-tab-baron the bottom of the screen, as it also has its own safe area bottom padding.This situation also applies when you have the phone’s keyboard open, with or without an
ion-tab-bar.Issue URL: Resolves #17560
What is the new behavior?
Extra bottom padding removed if there is a
slot="bottom"tab bar nearby, or if the keyboard is open. (The keyboard logic is the same as inion-tab-bar.)This PR also pulls the
keyboardVisiblelogic shared betweenion-footerandion-tab-barinto a separatecreateKeyboardControllerfunction.Does this introduce a breaking change?
Other information
This PR is adapted from #23193. Co-author credit will be given when merging.
I left off a test for the keyboard being open since I don't believe that's possible in Playwright 🤔