Skip to content

Instantly share code, notes, and snippets.

@marcel-ploch
Last active October 11, 2019 10:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcel-ploch/bf914dd62355049a0e5efb4885ca4c6e to your computer and use it in GitHub Desktop.
Save marcel-ploch/bf914dd62355049a0e5efb4885ca4c6e to your computer and use it in GitHub Desktop.
Keyboard Events for IOs in NativeScript
// Keyboard up event on ios
if (application.ios) {
// First Event is Catched before the Keyboard Jumps Up
// We Save the Height of the Keyboard for the Positioning of the LayoutElement
application.ios.addNotificationObserver(UIKeyboardWillShowNotification, (event) => {
// console.log('WillShow', typeof event.userInfo, event.userInfo.valueForKey(UIKeyboardFrameEndUserInfoKey).CGRectValue.size.height);
// console.log(this.textView.ios.contentSize);
this.contentSizeStartValue = event.userInfo.valueForKey(UIKeyboardFrameEndUserInfoKey).CGRectValue.size.height + 10;
});
// Second Event is Catched when the Keyboard is Up to Reposition our Element
application.ios.addNotificationObserver(UIKeyboardDidShowNotification, (event) => {
if (this.textView) {
this.ngZone.run(() => {
if (this.textView.ios.contentSize.height > 100) {
this.textHeight = this.contentSizeStartValue + 100;
this.textViewHeight = 90;
} else {
this.textHeight = this.textViewHeight = this.contentSizeStartValue;
}
this.textChanged();
// console.log('HEIGHT ON KEYBOARD UP', this.textHeight, this.textView.ios.contentSize.height);
});
}
});
// Keyboard down event on ios to reposition our element again
application.ios.addNotificationObserver(UIKeyboardWillHideNotification, () => {
if (this.textView) {
this.ngZone.run(() => {
if (this.textView.ios.contentSize.height > 100) {
this.textHeight = this.textViewHeight = 100;
} else {
this.textHeight = this.textViewHeight = this.textView.ios.contentSize.height - this.contentSizeStartValue;
}
});
}
});
}
@bgrand-ch
Copy link

Thanks a lot !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment