mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Clean up some grossness in ScrollResponder
Summary: Still gross but less gross. Reviewed By: sebmarkbage Differential Revision: D7107180 fbshipit-source-id: 31f1639a8f44e4ab247c338001a4a5c9b4b83cdf
This commit is contained in:
committed by
Facebook Github Bot
parent
8102e35271
commit
a275eac56e
@@ -192,10 +192,6 @@ const DataDetectorTypes = [
|
||||
|
||||
const TextInput = createReactClass({
|
||||
displayName: 'TextInput',
|
||||
statics: {
|
||||
/* TODO(brentvatne) docs are needed for this */
|
||||
State: TextInputState,
|
||||
},
|
||||
|
||||
propTypes: {
|
||||
...ViewPropTypes,
|
||||
@@ -667,24 +663,30 @@ const TextInput = createReactClass({
|
||||
|
||||
componentDidMount: function() {
|
||||
this._lastNativeText = this.props.value;
|
||||
if (!this.context.focusEmitter) {
|
||||
const tag = ReactNative.findNodeHandle(this._inputRef);
|
||||
if (tag != null) {
|
||||
// tag is null only in unit tests
|
||||
TextInputState.registerInput(tag);
|
||||
}
|
||||
|
||||
if (this.context.focusEmitter) {
|
||||
this._focusSubscription = this.context.focusEmitter.addListener(
|
||||
'focus',
|
||||
el => {
|
||||
if (this === el) {
|
||||
this.requestAnimationFrame(this.focus);
|
||||
} else if (this.isFocused()) {
|
||||
this.blur();
|
||||
}
|
||||
},
|
||||
);
|
||||
if (this.props.autoFocus) {
|
||||
this.context.onFocusRequested(this);
|
||||
}
|
||||
} else {
|
||||
if (this.props.autoFocus) {
|
||||
this.requestAnimationFrame(this.focus);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this._focusSubscription = this.context.focusEmitter.addListener(
|
||||
'focus',
|
||||
el => {
|
||||
if (this === el) {
|
||||
this.requestAnimationFrame(this.focus);
|
||||
} else if (this.isFocused()) {
|
||||
this.blur();
|
||||
}
|
||||
},
|
||||
);
|
||||
if (this.props.autoFocus) {
|
||||
this.context.onFocusRequested(this);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -693,6 +695,10 @@ const TextInput = createReactClass({
|
||||
if (this.isFocused()) {
|
||||
this.blur();
|
||||
}
|
||||
const tag = ReactNative.findNodeHandle(this._inputRef);
|
||||
if (tag != null) {
|
||||
TextInputState.unregisterInput(tag);
|
||||
}
|
||||
},
|
||||
|
||||
getChildContext(): ViewChildContext {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
const Platform = require('Platform');
|
||||
const UIManager = require('UIManager');
|
||||
|
||||
const inputs = new Set();
|
||||
|
||||
const TextInputState = {
|
||||
/**
|
||||
* Internal state
|
||||
@@ -68,7 +70,19 @@ const TextInputState = {
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
registerInput: function(textFieldID: number) {
|
||||
inputs.add(textFieldID);
|
||||
},
|
||||
|
||||
unregisterInput: function(textFieldID: number) {
|
||||
inputs.delete(textFieldID);
|
||||
},
|
||||
|
||||
isTextInput: function(textFieldID: number) {
|
||||
return inputs.has(textFieldID);
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = TextInputState;
|
||||
|
||||
Reference in New Issue
Block a user