mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Reorder methods
Summary: Reordering the methds in TextInput to be a bit more consistent. Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D18435732 fbshipit-source-id: 05a1d9d2c70a4b5fa00a3dc6be0520a216a24106
This commit is contained in:
committed by
Facebook Github Bot
parent
c70a093dd2
commit
ca78497f73
@@ -812,16 +812,6 @@ const TextInput = createReactClass({
|
||||
*/
|
||||
mixins: [NativeMethodsMixin],
|
||||
|
||||
/**
|
||||
* Returns `true` if the input is currently focused; `false` otherwise.
|
||||
*/
|
||||
isFocused: function(): boolean {
|
||||
return (
|
||||
TextInputState.currentlyFocusedField() ===
|
||||
ReactNative.findNodeHandle(this._inputRef)
|
||||
);
|
||||
},
|
||||
|
||||
_inputRef: (undefined: any),
|
||||
_focusSubscription: (undefined: ?Function),
|
||||
_lastNativeText: (undefined: ?string),
|
||||
@@ -841,6 +831,40 @@ const TextInput = createReactClass({
|
||||
}
|
||||
},
|
||||
|
||||
componentDidUpdate: function() {
|
||||
// This is necessary in case native updates the text and JS decides
|
||||
// that the update should be ignored and we should stick with the value
|
||||
// that we have in JS.
|
||||
const nativeProps = {};
|
||||
|
||||
if (
|
||||
this._lastNativeText !== this.props.value &&
|
||||
typeof this.props.value === 'string'
|
||||
) {
|
||||
nativeProps.text = this.props.value;
|
||||
}
|
||||
|
||||
// Selection is also a controlled prop, if the native value doesn't match
|
||||
// JS, update to the JS value.
|
||||
const {selection} = this.props;
|
||||
if (
|
||||
this._lastNativeSelection &&
|
||||
selection &&
|
||||
(this._lastNativeSelection.start !== selection.start ||
|
||||
this._lastNativeSelection.end !== selection.end)
|
||||
) {
|
||||
nativeProps.selection = this.props.selection;
|
||||
}
|
||||
|
||||
if (
|
||||
Object.keys(nativeProps).length > 0 &&
|
||||
this._inputRef &&
|
||||
this._inputRef.setNativeProps
|
||||
) {
|
||||
this._inputRef.setNativeProps(nativeProps);
|
||||
}
|
||||
},
|
||||
|
||||
componentWillUnmount: function() {
|
||||
this._focusSubscription && this._focusSubscription.remove();
|
||||
if (this.isFocused()) {
|
||||
@@ -862,6 +886,20 @@ const TextInput = createReactClass({
|
||||
this.setNativeProps({text: ''});
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns `true` if the input is currently focused; `false` otherwise.
|
||||
*/
|
||||
isFocused: function(): boolean {
|
||||
return (
|
||||
TextInputState.currentlyFocusedField() ===
|
||||
ReactNative.findNodeHandle(this._inputRef)
|
||||
);
|
||||
},
|
||||
|
||||
getNativeRef: function(): ?React.ElementRef<HostComponent<mixed>> {
|
||||
return this._inputRef;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
let textInput = null;
|
||||
let additionalTouchableProps: {|
|
||||
@@ -974,17 +1012,6 @@ const TextInput = createReactClass({
|
||||
this._inputRef = ref;
|
||||
},
|
||||
|
||||
getNativeRef: function(): ?React.ElementRef<HostComponent<mixed>> {
|
||||
return this._inputRef;
|
||||
},
|
||||
|
||||
_onFocus: function(event: FocusEvent) {
|
||||
TextInputState.focusField(ReactNative.findNodeHandle(this._inputRef));
|
||||
if (this.props.onFocus) {
|
||||
this.props.onFocus(event);
|
||||
}
|
||||
},
|
||||
|
||||
_onPress: function(event: PressEvent) {
|
||||
if (this.props.editable || this.props.editable === undefined) {
|
||||
this.focus();
|
||||
@@ -1030,37 +1057,10 @@ const TextInput = createReactClass({
|
||||
}
|
||||
},
|
||||
|
||||
componentDidUpdate: function() {
|
||||
// This is necessary in case native updates the text and JS decides
|
||||
// that the update should be ignored and we should stick with the value
|
||||
// that we have in JS.
|
||||
const nativeProps = {};
|
||||
|
||||
if (
|
||||
this._lastNativeText !== this.props.value &&
|
||||
typeof this.props.value === 'string'
|
||||
) {
|
||||
nativeProps.text = this.props.value;
|
||||
}
|
||||
|
||||
// Selection is also a controlled prop, if the native value doesn't match
|
||||
// JS, update to the JS value.
|
||||
const {selection} = this.props;
|
||||
if (
|
||||
this._lastNativeSelection &&
|
||||
selection &&
|
||||
(this._lastNativeSelection.start !== selection.start ||
|
||||
this._lastNativeSelection.end !== selection.end)
|
||||
) {
|
||||
nativeProps.selection = this.props.selection;
|
||||
}
|
||||
|
||||
if (
|
||||
Object.keys(nativeProps).length > 0 &&
|
||||
this._inputRef &&
|
||||
this._inputRef.setNativeProps
|
||||
) {
|
||||
this._inputRef.setNativeProps(nativeProps);
|
||||
_onFocus: function(event: FocusEvent) {
|
||||
TextInputState.focusField(ReactNative.findNodeHandle(this._inputRef));
|
||||
if (this.props.onFocus) {
|
||||
this.props.onFocus(event);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user