mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Second Updates from Wed 25 Mar
- [MAdMan][Android] Make things look more Androidy | Philipp von Weitershausen - flowified Libraries from Avik | Basil Hosmer - flowify some Libraries | Basil Hosmer - [ReactKit] Add shake development menu | Alex Kotliarskyi - [ReactNative] Add debugger and change SampleApp files structure | Alex Kotliarskyi - Flowify ReactIOSEventEmitter | Marshall Roch - [react_native] JS files from D1941151: Allow fontWeight to be 100,200,...,900 | Krzysztof Magiera
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule TextInput
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
@@ -63,6 +64,12 @@ var notMultiline = {
|
||||
onSubmitEditing: true,
|
||||
};
|
||||
|
||||
type DefaultProps = {
|
||||
bufferDelay: number;
|
||||
};
|
||||
|
||||
type Event = Object;
|
||||
|
||||
/**
|
||||
* A foundational component for inputting text into the app via a
|
||||
* keyboard. Props provide configurability for several features, such as auto-
|
||||
@@ -206,12 +213,12 @@ var TextInput = React.createClass({
|
||||
validAttributes: RCTTextFieldAttributes,
|
||||
},
|
||||
|
||||
isFocused: function() {
|
||||
isFocused: function(): boolean {
|
||||
return TextInputState.currentlyFocusedField() ===
|
||||
this.refs.input.getNativeNode();
|
||||
},
|
||||
|
||||
getDefaultProps: function() {
|
||||
getDefaultProps: function(): DefaultProps {
|
||||
return {
|
||||
bufferDelay: 100,
|
||||
};
|
||||
@@ -229,6 +236,8 @@ var TextInput = React.createClass({
|
||||
focusEmitter: React.PropTypes.instanceOf(EventEmitter),
|
||||
},
|
||||
|
||||
_focusSubscription: (undefined: ?Function),
|
||||
|
||||
componentDidMount: function() {
|
||||
if (!this.context.focusEmitter) {
|
||||
if (this.props.autoFocus) {
|
||||
@@ -255,7 +264,9 @@ var TextInput = React.createClass({
|
||||
this._focusSubscription && this._focusSubscription.remove();
|
||||
},
|
||||
|
||||
componentWillReceiveProps: function(newProps) {
|
||||
_bufferTimeout: (undefined: ?number),
|
||||
|
||||
componentWillReceiveProps: function(newProps: {value: any}) {
|
||||
if (newProps.value !== this.props.value) {
|
||||
if (!this.isFocused()) {
|
||||
// Set the value immediately if the input is not focused since that
|
||||
@@ -385,17 +396,17 @@ var TextInput = React.createClass({
|
||||
);
|
||||
},
|
||||
|
||||
_onFocus: function(event) {
|
||||
_onFocus: function(event: Event) {
|
||||
if (this.props.onFocus) {
|
||||
this.props.onFocus(event);
|
||||
}
|
||||
},
|
||||
|
||||
_onPress: function(event) {
|
||||
_onPress: function(event: Event) {
|
||||
this.focus();
|
||||
},
|
||||
|
||||
_onChange: function(event) {
|
||||
_onChange: function(event: Event) {
|
||||
if (this.props.controlled && event.nativeEvent.text !== this.props.value) {
|
||||
this.refs.input.setNativeProps({text: this.props.value});
|
||||
}
|
||||
@@ -403,14 +414,14 @@ var TextInput = React.createClass({
|
||||
this.props.onChangeText && this.props.onChangeText(event.nativeEvent.text);
|
||||
},
|
||||
|
||||
_onBlur: function(event) {
|
||||
_onBlur: function(event: Event) {
|
||||
this.blur();
|
||||
if (this.props.onBlur) {
|
||||
this.props.onBlur(event);
|
||||
}
|
||||
},
|
||||
|
||||
_onSelectionChange: function(event) {
|
||||
_onSelectionChange: function(event: Event) {
|
||||
if (this.props.selectionState) {
|
||||
var selection = event.nativeEvent.selection;
|
||||
this.props.selectionState.update(selection.start, selection.end);
|
||||
@@ -418,7 +429,7 @@ var TextInput = React.createClass({
|
||||
this.props.onSelectionChange && this.props.onSelectionChange(event);
|
||||
},
|
||||
|
||||
_onTextInput: function(event) {
|
||||
_onTextInput: function(event: Event) {
|
||||
this.props.onTextInput && this.props.onTextInput(event);
|
||||
var counter = event.nativeEvent.eventCounter;
|
||||
if (counter > this.state.mostRecentEventCounter) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule TextInputState
|
||||
* @flow
|
||||
*
|
||||
* This class is responsible for coordinating the "focused"
|
||||
* state for TextInputs. All calls relating to the keyboard
|
||||
@@ -20,13 +21,13 @@ var TextInputState = {
|
||||
/**
|
||||
* Internal state
|
||||
*/
|
||||
_currentlyFocusedID: null,
|
||||
_currentlyFocusedID: (null: ?string),
|
||||
|
||||
/**
|
||||
* Returns the ID of the currently focused text field, if one exists
|
||||
* If no text field is focused it returns null
|
||||
*/
|
||||
currentlyFocusedField: function() {
|
||||
currentlyFocusedField: function(): ?string {
|
||||
return this._currentlyFocusedID;
|
||||
},
|
||||
|
||||
@@ -35,7 +36,7 @@ var TextInputState = {
|
||||
* Focuses the specified text field
|
||||
* noop if the text field was already focused
|
||||
*/
|
||||
focusTextInput: function(textFieldID) {
|
||||
focusTextInput: function(textFieldID: string) {
|
||||
if (this._currentlyFocusedID != textFieldID && textFieldID != null) {
|
||||
this._currentlyFocusedID = textFieldID;
|
||||
RCTUIManager.focus(textFieldID);
|
||||
@@ -47,7 +48,7 @@ var TextInputState = {
|
||||
* Unfocuses the specified text field
|
||||
* noop if it wasn't focused
|
||||
*/
|
||||
blurTextInput: function(textFieldID) {
|
||||
blurTextInput: function(textFieldID: string) {
|
||||
if (this._currentlyFocusedID == textFieldID && textFieldID != null) {
|
||||
this._currentlyFocusedID = null;
|
||||
RCTUIManager.blur(textFieldID);
|
||||
|
||||
Reference in New Issue
Block a user