mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
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 (
<View style={{flex: 1, marginTop: 20}}>
<Text style={{ flex: 1, alignItems: 'center'}}>
Hi! This is test.
</Text>
<KeyboardAvoidingView behavior={'position'} keyboardVerticalOffset={-20} >
<TextInput
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
/>
</KeyboardAvoidingView>
</View>
);
}
}
AppRegistry.registerComponent('Test', () => Test);
```

How _relativeKeyboardHeight_ calculates positio
Closes https://github.com/facebook/react-native/pull/9139
Differential Revision: D4168431
Pulled By: hramos
fbshipit-source-id: 9181276355490452071b51b51ed7dc9ab80b2444
This commit is contained in:
committed by
Facebook Github Bot
parent
ab898ddda7
commit
ec6e274172
@@ -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);
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user