From ec6e2741720d70f7523477bf4d4e421cac9a19e1 Mon Sep 17 00:00:00 2001 From: Slavik Manukyan Date: Mon, 14 Nov 2016 11:53:52 -0800 Subject: [PATCH] relativeKeyboardHeight works wrong in some cases Summary: relativeKeyboardHeight calculation is wrong when frame.y < keyboardFrame.y Let's look at an example: ``` jsx import React, { Component } from 'react'; import { KeyboardAvoidingView, TextInput, AppRegistry, Text, View } from 'react-native'; export default class Test extends Component { constructor(props, context) { super(props, context); } render() { return ( Hi! This is test. ); } } AppRegistry.registerComponent('Test', () => Test); ``` ![rn-relativekb](https://cloud.githubusercontent.com/assets/13254349/17298119/b2192830-5819-11e6-968c-d9e95b6e4aba.gif) How _relativeKeyboardHeight_ calculates positio Closes https://github.com/facebook/react-native/pull/9139 Differential Revision: D4168431 Pulled By: hramos fbshipit-source-id: 9181276355490452071b51b51ed7dc9ab80b2444 --- Libraries/Components/Keyboard/KeyboardAvoidingView.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Libraries/Components/Keyboard/KeyboardAvoidingView.js b/Libraries/Components/Keyboard/KeyboardAvoidingView.js index 164a66c5243..ec7d6718785 100644 --- a/Libraries/Components/Keyboard/KeyboardAvoidingView.js +++ b/Libraries/Components/Keyboard/KeyboardAvoidingView.js @@ -94,6 +94,9 @@ const KeyboardAvoidingView = React.createClass({ const y1 = Math.max(frame.y, keyboardFrame.screenY - this.props.keyboardVerticalOffset); const y2 = Math.min(frame.y + frame.height, keyboardFrame.screenY + keyboardFrame.height - this.props.keyboardVerticalOffset); + if (frame.y > keyboardFrame.screenY) { + return frame.y + frame.height - keyboardFrame.screenY - this.props.keyboardVerticalOffset; + } return Math.max(y2 - y1, 0); },