Skip to content

Commit

Permalink
fix: Fix flow issues with ref (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
gawrysiak authored and ferrannp committed Oct 4, 2018
1 parent 60e0782 commit 526b8c1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/components/Searchbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,41 +74,41 @@ class Searchbar extends React.Component<Props> {
this.props.onChangeText && this.props.onChangeText('');
};

_root: TextInput;
_root: ?TextInput;

/**
* @internal
*/
setNativeProps(...args) {
return this._root.setNativeProps(...args);
return this._root && this._root.setNativeProps(...args);
}

/**
* Returns `true` if the input is currently focused, `false` otherwise.
*/
isFocused() {
return this._root.isFocused();
return this._root && this._root.isFocused();
}

/**
* Removes all text from the TextInput.
*/
clear() {
return this._root.clear();
return this._root && this._root.clear();
}

/**
* Focuses the input.
*/
focus() {
return this._root.focus();
return this._root && this._root.focus();
}

/**
* Removes focus from the input.
*/
blur() {
return this._root.blur();
return this._root && this._root.blur();
}

render() {
Expand Down
12 changes: 6 additions & 6 deletions src/components/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class TextInput extends React.Component<Props, State> {
});

_timer: TimeoutID;
_root: NativeTextInput;
_root: ?NativeTextInput;

_showError = () => {
Animated.timing(this.state.error, {
Expand Down Expand Up @@ -335,35 +335,35 @@ class TextInput extends React.Component<Props, State> {
* @internal
*/
setNativeProps(...args) {
return this._root.setNativeProps(...args);
return this._root && this._root.setNativeProps(...args);
}

/**
* Returns `true` if the input is currently focused, `false` otherwise.
*/
isFocused() {
return this._root.isFocused();
return this._root && this._root.isFocused();
}

/**
* Removes all text from the TextInput.
*/
clear() {
return this._root.clear();
return this._root && this._root.clear();
}

/**
* Focuses the input.
*/
focus() {
return this._root.focus();
return this._root && this._root.focus();
}

/**
* Removes focus from the input.
*/
blur() {
return this._root.blur();
return this._root && this._root.blur();
}

render() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Typography/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ type Props = {
* @extends Text props https://facebook.github.io/react-native/docs/text.html#props
*/
class Text extends React.Component<Props> {
_root: NativeText;
_root: ?NativeText;

/**
* @internal
*/
setNativeProps(...args) {
return this._root.setNativeProps(...args);
return this._root && this._root.setNativeProps(...args);
}

render() {
Expand Down

0 comments on commit 526b8c1

Please sign in to comment.