Andr3wHur5t / react-native-keyboard-spacer

Plug and play react-native keyboard spacer view.
MIT License
1.56k stars 219 forks source link

Wrong spacing when external physical keyboard is connected #32

Closed JaxGit closed 7 years ago

JaxGit commented 8 years ago

Actual result: The keyboardSpace is taking too much when external physical keyboard is connected.

External physical keyboard could be simulated as well with the following method:

  1. Create an example iOS project with project setting -> Deployment Info -> Devices set to "Universal";
  2. Run on iPad simulator, make sure simulator setting -> Hardware -> Keyboard has set to be: ✓ Use the Same Layout as OSX ✓ Connect Hardware Keyboard

Reason: frames.endCoordinates deviation from screenHeight does not necessarily equal to virtual keyboard height. When external physical keyboard is connected, only the keyboard toolbar is showing if there should be one. The keyboard frame is located offscreen and could be glimpsed only during rotation.

JaxGit commented 8 years ago

Solution: For any major version of react-native-keyboard-spacer, use this:

  updateKeyboardSpace(frames) {
    if (!frames.endCoordinates) {
      return;
    }

    // get updated on rotation
    const screenHeight = Dimensions.get('window').height;
    // when external physical keyboard is connected
    // frames.endCoordinates.height still equals virtual keyboard height
    // however only the keyboard toolbar is showing if there should be one
    const keyboardSpace = (screenHeight - frames.endCoordinates.screenY) + this.props.topSpacing;
    this.setState({
      keyboardSpace,
      isKeyboardOpened: true
    }, this.props.onToggle(true, keyboardSpace));
  }

Fix for latest version is in PR https://github.com/Andr3wHur5t/react-native-keyboard-spacer/pull/31

Andr3wHur5t commented 8 years ago

Nice catch, will verify fix / review PR when I get back to my machine.