In my Ionic application I need to animate the ion-content element with Angular animation when the keyboard appear/disappear.
I have the following code:
<ion-content padding [@shiftContent]="isKeyboardOpen">
and
@Component({
selector: 'page',
templateUrl: 'page.html',
animations: [
trigger('shiftContent', [
state('0', style({
top: '0px'
})),
state('1', style({
top: "-200px"
})),
transition('* <=> *', animate('50ms')),
])
]
})
and
ionViewDidEnter() {
this.keyboardOpenObs = this.keyboard.onKeyboardShow().subscribe(() => {
this.isKeyboardOpen = true;
});
this.keyboardCloseObs = this.keyboard.onKeyboardHide().subscribe(() => {
this.isKeyboardOpen = false;
});
}
When the page load and I open the keyboard for the first time nothing happen, then when I close the keyboard it start working but in the opposite direction (if I open I get the closing animation and vice versa).
The same setup works great if I control the variable with a button instead of the keyboard event.
The listener to the keyboard open/close works, I tried by logging the variable on the keyboard event.