Basic description of 1.TextInput components:
TextInput is a basic component that allows users to enter text through the keyboard in the app. The properties of this component provide configuration for a variety of features, such as auto-complete, auto-case, placeholder text, and many different keyboard types, such as a pure numeric keypad, and so on.
The simplest use is to throw a TextInput into the application and subscribe to its onchangetext event to read the user's input. It also has some other events, such as onsubmitediting and onfocus. A simple example is as follows:
<textinput
STYLE={{HEIGHT:40, bordercolor: ' Gray ', borderwidth:1}}
onchangetext={(text) = this. SetState ({text})}
value={this. State.text}
/>
Note that some properties are valid only when Multiline is true or false. Also, when Multiline=false , adding a border style to one side of an element (for example:borderbottomcolor, borderLeftWidth, and so on) will not take effect. To be able to achieve the effect you can use a View to wrap the TextInput:
<view style={{borderbottomcolor: ' #000000 ', borderbottomwidth:1,}}>
<textinput {... props}/>
</View>
2> Property
The attribute autocapitalize enum (' None ', ' sentences ', ' words ', ' characters ') controls whether the TextInput will automatically switch a particular character to uppercase: characters: all characters. Words: The first character of each word. Sentences: The first character of each sentence (default). None: Do not automatically toggle any characters to uppercase. autoCorrect bool If False, automatic spelling correction is turned off. The default value is true. autoFocus BOOL If true, the focus will be given after Componentdidmount. The default value is False. bluronsubmit BOOL If true, the text box will lose focus at the time of submission. The default value for a single-line input box is true, and multiple lines are false. Note: For multi-line input boxes, if Bluronsubmit is set to true, losing focus while hitting enter will trigger the Onsubmitediting event instead of wrapping. DefaultValue string provides the initial value in a text box. When the user starts typing, the value can be changed. In some simple use cases, if you do not want to listen to the message and then update the Value property of the method to maintain the properties and state synchronization, you can use DefaultValue instead. editable bool If False, the text box is not editable. The default value is true. Keyboardtype enum ("Default", ' Numeric ', ' email-address ', ' ascii-capable ', ' numbers-and-punctuation ', ' url ', ' Number-pad ', ' phone-pad ', ' name-phone-pad ', ' decimal-pad ', ' Twitter ', ' web-search ') decide what kind of soft keyboard pops up, such as numeric (a purely numeric keypad). These values are available on all platforms: Defaultnumericemail-addressmaxlength number restricts the maximum numbers of characters in the text box. Using this attribute without the use of JS logic to achieve, you can avoid flickering phenomenon. multiline bool If true, multiple lines of text can be entered in the text box. The default value is False. OnBlur function calls this callback when the text box loses focus. OnChange function as a textThis callback function is called when the contents of this box change. Onchangetext function calls this callback when the contents of the text box change. The changed text content is passed as a parameter. onendediting function calls this callback when the text input is finished. onfocus functions Call this callback function when the text box gets the focus. The OnLayout function is called when the component is mounted or the layout changes, with the parameters {x, y, width, height}. onsubmitediting function This callback function is called when the OK/submit button of the soft keyboard is pressed. If Multiline={true}, this property is not available. Placeholder string If there is no literal input, it will be displayed. Placeholdertextcolor a string placeholder string that displays the text color. securetextentry BOOL If true, the text box obscures the text you entered earlier, so sensitive text like passwords can be more secure. The default value is False. selecttextonfocus bool If true, all text will be selected when the focus is obtained. SelectionColor string sets the color of the input box when it is highlighted (also includes the cursor on iOS) style Text#style: This means that this component inherits the style of all Text. The literal content in the Value string text box. TextInput is a constrained (controlled) component, meaning that if the Value property is supplied, the native value is forced to be consistent with the Value property. This works well in most cases, but in some cases it can cause some flicker-a common reason is to prevent users from editing by not changing the value. If you want to prevent user input, consider setting Editable={false}; If you want to limit the length of the input, consider setting the MaxLength property, neither of which will cause flicker. Iosclearbuttonmode enum (' Never ', ' while-editing ', ' unless-editing ', ' always ') displays the "Clear" button on the right side of the text box. ioscleartextonfocus BOOL If true, the contents of the text box will be cleared each time you start typing. iosenablesreturnkeyautomatically BOOL If True,The keyboard disables the Confirm button when there is no text in the text box. The default value is False. ioskeyboardappearance enum (' Default ', ' Light ', ' dark ') specifies the color of the keyboard. iosonkeypress function invokes this callback when a key is pressed. The pressed key is passed as a parameter to the callback function. will be called before onchange. Iosreturnkeytype enum (' Default ', ' Go ', ' Google ', ' join ', ' next ', ' Route ', ' Search ', ' send ', ' Yahoo ', ' done ', ' emergency-c All ') determines what the OK button displays. Iosselectionstate documentselectionstate See documentselectionstate.js, you can control which text in a document is selected. Androidnumberoflines numbers sets the number of rows in the input box. When Multiline is set to true, it is used to occupy the corresponding number of rows. Androidunderlinecolorandroid the underline color of the string text box: If you want to remove the border from the text box, set this property to transparent transparent.
3> Method:
IsFocused (): Boolean #返回值表明当前输入框是否获得了焦点. Clear () empties the contents of the input box.
4> implementation:
/** * Sample React Native App *https://github.com/facebook/react-native* @flow*/import React, {Component} from 'react'; import {appregistry, StyleSheet, Text, View, TextInput,} from 'react-native';classViewdemo extends Component {render () {return ( //Be sure to set the style and width of the textinput to be displayed.<view Style ={styles.container}> <TextInput Style={Styles.inputstyle}//Keyboard TypeKeyboardtype = {'Number-pad'} //Default text Note The default text cannot be deletedValue = {'I am the default text'} // //Multi-line displayMultiline = {true} // //password input attention and multiline conflictPassword = {true} // //placeholder CharactersPalceholder = {"Please enter"} // //Clear ButtonClearbuttonmode = {' always'} /> </View> ); }}ConstStyles =stylesheet.create ({container: {flex:1, BackgroundColor:'#f5fcff',}, Inputstyle: {//spacingMarginTop: -, //Background ColorBackgroundColor:'Red', //BorderBorderWidth:1, //widthWidth -, //HeightHeight -, BorderColor:'#ebebeb' },}); Appregistry.registercomponent ('Viewdemo', () = Viewdemo);
Common Properties for TextInput components