Skip to content

Commit

Permalink
Wrap textInput with KeyboardAvoidingView
Browse files Browse the repository at this point in the history
Differential Revision: D6693570

fbshipit-source-id: f6946074d82cef2c68454bfc829c30013d19a151
  • Loading branch information
Wenjing Wang authored and facebook-github-bot committed Jan 10, 2018
1 parent 2c74f93 commit 85bd98e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Libraries/Components/Keyboard/KeyboardAvoidingView.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ const KeyboardAvoidingView = createReactClass({
* may be non-zero in some use cases. The default value is 0.
*/
keyboardVerticalOffset: PropTypes.number.isRequired,
/**
* This is to allow us to manually control which KAV shuld take effect when
* having more than one KAV at the same screen
*/
enabled: PropTypes.bool.isRequired,
},

getDefaultProps() {
return {
enabled: true,
keyboardVerticalOffset: 0,
};
},
Expand Down Expand Up @@ -157,7 +163,7 @@ const KeyboardAvoidingView = createReactClass({
render(): React.Element<any> {
// $FlowFixMe(>=0.41.0)
const {behavior, children, style, ...props} = this.props;

const bottomHeight = this.props.enabled ? this.state.bottom : 0;
switch (behavior) {
case 'height':
let heightStyle;
Expand All @@ -166,7 +172,7 @@ const KeyboardAvoidingView = createReactClass({
// i.e. this.state.bottom is greater than 0. If we remove that condition,
// this.frame.height will never go back to its original value.
// When height changes, we need to disable flex.
heightStyle = {height: this.frame.height - this.state.bottom, flex: 0};
heightStyle = {height: this.frame.height - bottomHeight, flex: 0};
}
return (
<View ref={viewRef} style={[style, heightStyle]} onLayout={this._onLayout} {...props}>
Expand All @@ -175,7 +181,7 @@ const KeyboardAvoidingView = createReactClass({
);

case 'position':
const positionStyle = {bottom: this.state.bottom};
const positionStyle = {bottom: bottomHeight};
const { contentContainerStyle } = this.props;

return (
Expand All @@ -187,7 +193,7 @@ const KeyboardAvoidingView = createReactClass({
);

case 'padding':
const paddingStyle = {paddingBottom: this.state.bottom};
const paddingStyle = {paddingBottom: bottomHeight};
return (
<View ref={viewRef} style={[style, paddingStyle]} onLayout={this._onLayout} {...props}>
{children}
Expand Down

3 comments on commit 85bd98e

@vovkasm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit message does not describe code changes 👎

@msageryd
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find the commit where the actual wrapping takes place (as per the commit message). But I see that this commit will enable it by default. I suppose that many apps already has KAV in place. Setting enabled=true by default would be a breaking change for all those apps, wouldn't it?

@vovkasm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msageryd No, enabled added properly. Before this change KAV behave (I actually looks only at this diff) as it always enabled. What this code change adds, is actually "allow to disable KAV".

But with such commit message, no one could see the error if even it was here.

Please sign in to comment.