Skip to content

Instantly share code, notes, and snippets.

@jourdan-jobox
Last active January 24, 2018 12:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jourdan-jobox/ca632e15f43e8f5860a369d3e019fa33 to your computer and use it in GitHub Desktop.
Save jourdan-jobox/ca632e15f43e8f5860a369d3e019fa33 to your computer and use it in GitHub Desktop.
An Ionic 2 example of how to place your page's content above the Keyboard.
import { Platform } from 'ionic-angular';
import { Keyboard } from 'ionic-native';
import { Subscription } from 'Rxjs/rx';
@Component({
selector: 'page-conversation',
templateUrl: 'conversation.html'
})
export class ConversationPage {
@ViewChild(Content) content: Content;
private keyboardSubscription: Subscription;
constructor(private platform: Platform) {}
ionViewDidLoad() {
if (this.platform.is('cordova')) {
this.keyboardSubscription = Keyboard.onKeyboardShow().subscribe(e => {
setTimeout(() => {
this.content.scrollToBottom(500); // 500 for a smooth slow scroll after the Keyboard opens, but you can change this
}, 50);
});
}
}
ionViewWillLeave() {
if (this.platform.is('cordova')) {
this.keyboardSubscription.unsubscribe();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment