Hi ,I used your code and in middle i was getting white space on header and also when i came back from other page, here is the attachment…[quote=“CurtisDrumeo, post:3, topic:60827, full:true”]
For anyone who might have been following this I did put together a method to solve this.
First, what I did was download the ionic-keyboard plugin:
$ ionic plugin add ionic-plugin-keyboard
Then I needed to do a couple native things for Android and Ios keyboards to maintain similar behaviors.
For IOS:
Keyboard.disableScroll(true);
For Android I had to go into platforms/android/AndroidManifest.xml and change the rule windowSoftInputMode:
android:windowSoftInputMode="adjustPan"
This makes the keyboard overlap the content rather than just shrink the viewport height.
After I did that I had to set up three event listeners, one for when the keyboard is opened, one for when the keyboard is closed, and lastly one for a click event.
window.addEventListener('native.keyboardshow', keyboardShowHandler); window.addEventListener('native.keyboardhide', keyboardHideHandler); window.addEventListener('touchstart', tapCoordinates);
Declare some variables to be used within the events.
let y; let h; let offsetY;
First event I handled was the click event. All I did was find the Y coordinates of my click and subtract that from the height of the device.
function tapCoordinates(e) {
y = e.touches[0].clientY;
h = window.innerHeight;
offsetY = (h - y);
console.log("offset = " + offsetY);
}
Second event was the keyboard opening. The keyboard plugin conveniently handles all of this for me and even allows me to get the height of the devices keyboard. So all I did was determine whether or not the Y offset was less than keyboard height + 40px (I used 40px because it seemed like an acceptable buffer zone to prevent the input from being cut in half when the keyboard shows up) and just pushed the entire body up by that amount.
function keyboardShowHandler(e) {
let kH = e.keyboardHeight;
console.log(e.keyboardHeight);
let bodyMove = <HTMLElement>document.querySelector("ion-app"), bodyMoveStyle = bodyMove.style;
console.log("calculating " + kH + "-" + offsetY + "=" + (kH - offsetY));
if (offsetY < kH + 40) {
bodyMoveStyle.bottom = (kH - offsetY + 40) + "px";
bodyMoveStyle.top = "initial";
}
}
Lastly we check if the keyboard closes and wipe all of those styles from the “ion-app” element
function keyboardHideHandler() {
console.log('gone');
let removeStyles = <HTMLElement>document.querySelector("ion-app");
removeStyles.removeAttribute("style");
}
This seems like kind of a lot of work to emulate what the device should be doing by default though. In any case atleast I know this is going to work consistently across all devices. (I hope).
If anyone spots some issues in my code, or problems that may occur down the line, please feel free to let me know.
[/quote]
Hi, I used your code but getting whitespace on top of the header after coming back from other screen in my app and am getting the output what was expected but extra white space is adding.Can u plz help me .
And the screen shot is