React Native Knowledge 2-Text components, react2-text
Text is a React component used to display Text. It also supports nesting, style, and touch processing. In the following example, the nested title and text will inherit the fontFamily font style from styles. baseText, but its own extra style will be appended to the title. The title and text are stacked on the top of the document and separated by line breaks embedded in the code.
I. Attributes
1: allowFontScaling bool (exclusive to iOS): controls whether the font should be scaled according to iOS's "text size" Auxiliary options.
2: numberOfLines number: Used to crop text when the text is too long. The total number of rows, including the line breaks generated by folding, does not exceed the limit of this attribute;
3: onLayout function: called after mounting or layout change, the parameter is as follows: {nativeEvent: {layout: {x, y, width, height }}}
4: onPress function: This callback function is called when the text is clicked.
5: testID string: used to mark this view in an end-to-end test.
6: suppressHighlighting bool (iOS-specific): If it is set to true, if the text is pressed, there is no visual effect. By default, a gray, elliptical highlight is displayed when the text is pressed.
Ii. style
1: color string
2: fontFamily string
3: fontSize number
4: fontStyle enum ('normal', 'italic ')
5: fontWeight enum ("normal", 'bold ', '000000', '000000', '000000', '000000', '000000', '000000 ', '123', '123', '123 ')
Specifies the font width. Most fonts support 'normal' and 'bold 'values. Not all fonts support all numeric values. If a value is not supported, the nearest value is automatically selected.
6: letterSpacing number Character Spacing
7: lineHeight number Row Height
8: textAlign enum ("auto", 'left', 'right', 'center', 'justify ')
Specifies the text alignment. The 'justify 'value is only supported by iOS.
9 :( android) textAlignVertical enum ('auto', 'top', 'bottom ', 'center ')
10 :( ios) textDecorationColor string line color
11: textDecorationLine enum ("none", 'underline', 'Line-passthrough ', 'underlineline-pass') Position
12 :( ios) textDecorationStyle enum ("solid", 'double', 'dotted', 'dashed') Line Style
13 :( ios) writingDirection enum ("auto", 'ltr', 'rtl ')Text direction
Iii. instance code:
1: use of Text attributes
Import React, {Component} from 'react '; import {AppRegistry, StyleSheet, AlertIOS, Text, View} from 'react-native'; class ReactNativeProject extends Component {render () {return (<View style = {styles. container }> <Text style = {styles. textTopStyle}> I started to learn react native content. This example describes how to use Text, including related attributes and events. </Text> <Text style = {styles. textCenterStyle} numberOfLines = {2}> numberOfLines: the value of this attribute is a number that specifies the maximum number of rows to be displayed. If this value is exceeded, the ellipsis (...) is used (...) similar to native </Text> <Text style = {styles. textBottomStyle} onPress = {() => AlertIOS. prompt ('Secure text', null, null, 'secure-text')}> Click Event usage </Text> <text style ={{ fontWeight: 'bold ', marginTop: 40 }> I am using <Text style = {color: 'red' }}> nested Text </Text>; </Text> </View>) ;}} const styles = StyleSheet. create ({container: {flex: 1, height: 300, justifyContent: 'center'}, textTopStyle: {fontSize: 20, fontWeight: 'bold ', textAlign: 'center ', color: 'red'}, textCenterStyle: {fontSize: 14, textAlign: 'center', color: 'blue'}, textBottomStyle: {fontSize: 17, textAlign: 'right ', color: 'red', marginTop: 50, marginRight: 20, borderWidth: 1, borderColor: 'red'}); AppRegistry. registerComponent ('reactnativeproject', () => ReactNativeProject );
:
2: common text styles
<Text style={{textDecorationLine: 'underline', textDecorationStyle: 'solid'}}>Solid underline</Text><Text style={{textDecorationLine: 'underline', textDecorationStyle: 'double', textDecorationColor: '#ff0000'}}>Double underline with custom color</Text><Text style={{textDecorationLine: 'underline', textDecorationStyle: 'dashed', textDecorationColor: '#9CDC40'}}>Dashed underline with custom color</Text><Text style={{textDecorationLine: 'underline', textDecorationStyle: 'dotted', textDecorationColor: 'blue'}}>Dotted underline with custom color</Text><Text style={{textDecorationLine: 'none'}}>None textDecoration</Text><Text style={{textDecorationLine: 'line-through', textDecorationStyle: 'solid'}}>Solid line-through</Text><Text style={{textDecorationLine: 'line-through', textDecorationStyle: 'double', textDecorationColor: '#ff0000'}}>Double line-through with custom color</Text><Text style={{textDecorationLine: 'line-through', textDecorationStyle: 'dashed', textDecorationColor: '#9CDC40'}}>Dashed line-through with custom color</Text><Text style={{textDecorationLine: 'line-through', textDecorationStyle: 'dotted', textDecorationColor: 'blue'}}>Dotted line-through with custom color</Text><Text style={{textDecorationLine: 'underline line-through'}}>Both underline and line-through</Text>
:
4. knowledge points
1: Text can be used as a container. <Text> elements are different from other components in layout: Elements in Text do not use flexbox layout, but use Text layout. This means that the elements in <Text> are no longer rectangles, but may be folded at the end of the line.
2: You cannot directly put a piece of Text under <View>. Instead, you must include a <Text> </Text> in <View> </View>, then, place the text content in Textj;