Last active
January 24, 2018 12:15
-
-
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.
This file contains 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
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