Last active
October 11, 2019 10:40
-
-
Save marcel-ploch/bf914dd62355049a0e5efb4885ca4c6e to your computer and use it in GitHub Desktop.
Keyboard Events for IOs in NativeScript
This file contains hidden or 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
// 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; | |
} | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot !