You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2019/02/27 01:51:40 UTC

[GitHub] hunturkey commented on issue #417: Keyboard Dismissal Leaves Viewport Shifted in iOS 12 / XCode 10

hunturkey commented on issue #417: Keyboard Dismissal Leaves Viewport Shifted in iOS 12 / XCode 10
URL: https://github.com/apache/cordova-ios/issues/417#issuecomment-467690772
 
 
   For anyone using React Native, my fix for this involves detecting the keyboard on show and hide, and triggers contentInset to reset the view to default.
   
   Add the following to your code:
   ```
   import { Keyboard } from 'react-native'
   
     state = {
         keyboardState: 'closed'
     }
   
     componentWillMount() {
       this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
       this.keyboardWillHideListener = Keyboard.addListener('keyboardWillHide', this._keyboardWillHide);
     }
   
     componentWillUnmount() {
       this.keyboardDidShowListener.remove();
       this.keyboardWillHideListener.remove();
     }
   
     _keyboardDidShow = () => {
       this.setState({
           keyboardState: 'opened'
       });
     }
   
     _keyboardWillHide = () => {
       this.setState({
           keyboardState: 'closed'
       });
     }
   ```
   
   and then put this line inside your WebView or WKWebView:
   
   ```
   contentInset={this.state.keyboardState === 'opened' ? {bottom: 0.01} : {bottom: 0}}
   ```
   
   keyboardState will change on open and on detecting a close.
   When it does so, the contentInset switches between 0.01 and 0, which is visually unnoticeable.
   This simulates a person touching the screen, which forces a reset to default position.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org