Fixed string ref which was causing alert on react <Strictmode> (#23146)

Summary:
Changelog:
----------
[General] [Fixed] - After using React's `<StricMode>` it was discovered that a string ref was set, which is bad practice.
Pull Request resolved: https://github.com/facebook/react-native/pull/23146

Differential Revision: D13802397

Pulled By: cpojer

fbshipit-source-id: c2744877b25ad59eb1e4e9ce48a45e762f227b56
This commit is contained in:
Rafael Melo 2019-01-24 08:20:46 -08:00 committed by Facebook Github Bot
parent f4def0062c
commit e4d7fc06cb
1 changed files with 10 additions and 9 deletions

View File

@ -52,8 +52,6 @@ type State = {|
bottom: number,
|};
const viewRef = 'VIEW';
/**
* View that moves out of the way when the keyboard appears by automatically
* adjusting its height, position, or bottom padding.
@ -66,10 +64,13 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
_frame: ?ViewLayout = null;
_subscriptions: Array<EmitterSubscription> = [];
viewRef: {current: React.ElementRef<any> | null};
state = {
bottom: 0,
};
constructor(props: Props) {
super(props);
this.state = {bottom: 0};
this.viewRef = React.createRef();
}
_relativeKeyboardHeight(keyboardFrame): number {
const frame = this._frame;
@ -171,7 +172,7 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
}
return (
<View
ref={viewRef}
ref={this.viewRef}
style={StyleSheet.compose(
style,
heightStyle,
@ -185,7 +186,7 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
case 'position':
return (
<View
ref={viewRef}
ref={this.viewRef}
style={style}
onLayout={this._onLayout}
{...props}>
@ -204,7 +205,7 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
case 'padding':
return (
<View
ref={viewRef}
ref={this.viewRef}
style={StyleSheet.compose(
style,
{paddingBottom: bottomHeight},
@ -218,7 +219,7 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
default:
return (
<View
ref={viewRef}
ref={this.viewRef}
onLayout={this._onLayout}
style={style}
{...props}>