From 2a65ca6fc00ddb2fdef672b8fd677771a7ebf640 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Thu, 27 Oct 2016 22:31:43 -0700 Subject: [PATCH] [add] TextInput support for isFocused --- docs/components/TextInput.md | 4 ++++ src/components/TextInput/index.js | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/components/TextInput.md b/docs/components/TextInput.md index 4c5064bb..7dfd9cdb 100644 --- a/docs/components/TextInput.md +++ b/docs/components/TextInput.md @@ -157,6 +157,10 @@ Clear the text from the underlying DOM input. Focus the underlying DOM input. +**isFocused()** + +Returns `true` if the input is currently focused; `false` otherwise. + ## Examples ```js diff --git a/src/components/TextInput/index.js b/src/components/TextInput/index.js index 8485fc96..5ac7492c 100644 --- a/src/components/TextInput/index.js +++ b/src/components/TextInput/index.js @@ -72,6 +72,10 @@ class TextInput extends Component { TextInputState.focusTextInput(ReactDOM.findDOMNode(this._inputRef)); } + isFocused() { + return TextInputState.currentlyFocusedField() === ReactDOM.findDOMNode(this._inputRef); + } + setNativeProps(props) { UIManager.updateView(this._inputRef, props, this); } @@ -247,8 +251,6 @@ class TextInput extends Component { } } -applyNativeMethods(TextInput); - const styles = StyleSheet.create({ initial: { borderColor: 'black' @@ -284,4 +286,4 @@ const styles = StyleSheet.create({ } }); -module.exports = TextInput; +module.exports = applyNativeMethods(TextInput);