From 02ac4012781784923e522ddf7acd35647a377ba3 Mon Sep 17 00:00:00 2001 From: Andrei Coman Date: Fri, 27 Mar 2015 11:44:43 -0700 Subject: [PATCH] [react_native] Sync D1939291 --- .../{TextInput.ios.js => TextInput.js} | 60 ++++++++++++++++++- 1 file changed, 57 insertions(+), 3 deletions(-) rename Libraries/Components/TextInput/{TextInput.ios.js => TextInput.js} (90%) diff --git a/Libraries/Components/TextInput/TextInput.ios.js b/Libraries/Components/TextInput/TextInput.js similarity index 90% rename from Libraries/Components/TextInput/TextInput.ios.js rename to Libraries/Components/TextInput/TextInput.js index 02fec4d5a..a44d61adf 100644 --- a/Libraries/Components/TextInput/TextInput.ios.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -15,6 +15,7 @@ var DocumentSelectionState = require('DocumentSelectionState'); var EventEmitter = require('EventEmitter'); var NativeMethodsMixin = require('NativeMethodsMixin'); var RCTUIManager = require('NativeModules').UIManager; +var Platform = require('Platform'); var PropTypes = require('ReactPropTypes'); var React = require('React'); var ReactChildren = require('ReactChildren'); @@ -27,12 +28,10 @@ var TouchableWithoutFeedback = require('TouchableWithoutFeedback'); var createReactIOSNativeComponentClass = require('createReactIOSNativeComponentClass'); var emptyFunction = require('emptyFunction'); -var getObjectValues = require('getObjectValues'); var invariant = require('invariant'); var merge = require('merge'); var autoCapitalizeConsts = RCTUIManager.UIText.AutocapitalizationType; -var clearButtonModeConsts = RCTUIManager.UITextField.clearButtonMode; var RCTTextViewAttributes = merge(ReactIOSViewAttributes.UIView, { autoCorrect: true, @@ -66,6 +65,23 @@ var notMultiline = { onSubmitEditing: true, }; +var TextInputAndroidAttributes = { + autoCapitalize: true, + autoCorrect: true, + autoFocus: true, + keyboardType: true, + multiline: true, + password: true, + placeholder: true, + value: true, + testID: true, +}; + +var AndroidTextInput = createReactIOSNativeComponentClass({ + validAttributes: TextInputAndroidAttributes, + uiViewClassName: 'AndroidTextInput', +}); + type DefaultProps = { bufferDelay: number; }; @@ -157,10 +173,15 @@ var TextInput = React.createClass({ * * Callback that is called when the text input's text changes. */ + onChange: PropTypes.func, onChangeText: PropTypes.func, onEndEditing: PropTypes.func, onSubmitEditing: PropTypes.func, + /** + * If true, the TextInput will be a password field. Default value is false. + */ + password: PropTypes.bool, /** * The string that will be rendered before text input has been entered */ @@ -202,6 +223,10 @@ var TextInput = React.createClass({ ]), style: Text.propTypes.style, + /** + * Used to locate this view in end-to-end tests. + */ + testID: PropTypes.string, }, /** @@ -313,10 +338,18 @@ var TextInput = React.createClass({ }, render: function() { + if (Platform.OS === 'ios') { + return this._renderIOs(); + } else if (Platform.OS === 'android') { + return this._renderAndroid(); + } + }, + + _renderIOs: function() { var textContainer; var autoCapitalize = autoCapitalizeConsts[this.props.autoCapitalize]; - var clearButtonMode = clearButtonModeConsts[this.props.clearButtonMode]; + var clearButtonMode = RCTUIManager.UITextField.clearButtonMode[this.props.clearButtonMode]; if (!this.props.multiline) { for (var propKey in onlyMultiline) { @@ -398,6 +431,27 @@ var TextInput = React.createClass({ ); }, + _renderAndroid: function() { + var autoCapitalize = autoCapitalizeConsts[this.props.autoCapitalize]; + return ( + + ); + }, + _onFocus: function(event: Event) { if (this.props.onFocus) { this.props.onFocus(event);