Text #

A React component for displaying text.

Text supports nesting, styling, and touch handling.

In the following example, the nested title and body text will inherit the fontFamily from styles.baseText, but the title provides its own additional styles. The title and body will stack on top of each other on account of the literal newlines:

import React, { Component } from 'react'; import { AppRegistry, Text, StyleSheet } from 'react-native'; class TextInANest extends Component { constructor(props) { super(props); this.state = { titleText: "Bird's Nest", bodyText: 'This is not really a bird nest.' }; } render() { return ( <Text style={styles.baseText}> <Text style={styles.titleText} onPress={this.onPressTitle}> {this.state.titleText}{'\n'}{'\n'} </Text> <Text numberOfLines={5}> {this.state.bodyText} </Text> </Text> ); } } const styles = StyleSheet.create({ baseText: { fontFamily: 'Cochin', }, titleText: { fontSize: 20, fontWeight: 'bold', }, }); // App registration and rendering AppRegistry.registerComponent('TextInANest', () => TextInANest);

Props #

accessible?: bool #

When set to true, indicates that the view is an accessibility element. The default value for a Text element is true.

See the Accessibility guide for more information.

allowFontScaling?: bool #

Specifies whether fonts should scale to respect Text Size accessibility settings. The default is true.

ellipsizeMode?: enum('head', 'middle', 'tail', 'clip') #

When numberOfLines is set, this prop defines how text will be truncated. numberOfLines must be set in conjunction with this prop.

This can be one of the following values:

  • head - The line is displayed so that the end fits in the container and the missing text at the beginning of the line is indicated by an ellipsis glyph. e.g., "...wxyz"
  • middle - The line is displayed so that the beginning and end fit in the container and the missing text in the middle is indicated by an ellipsis glyph. "ab...yz"
  • tail - The line is displayed so that the beginning fits in the container and the missing text at the end of the line is indicated by an ellipsis glyph. e.g., "abcd..."
  • clip - Lines are not drawn past the edge of the text container.

The default is tail.

clip is working only for iOS

numberOfLines?: number #

Used to truncate the text with an ellipsis after computing the text layout, including line wrapping, such that the total number of lines does not exceed this number.

This prop is commonly used with ellipsizeMode.

onLayout?: function #

Invoked on mount and layout changes with

{nativeEvent: {layout: {x, y, width, height}}}

onLongPress?: function #

This function is called on long press.

e.g., onLongPress={this.increaseSize}>

onPress?: function #

This function is called on press.

e.g., onPress={() => console.log('1st')}

pressRetentionOffset?: {top: number, left: number, bottom: number, right: number} #

When the scroll view is disabled, this defines how far your touch may move off of the button, before deactivating the button. Once deactivated, try moving it back and you'll see that the button is once again reactivated! Move it back and forth several times while the scroll view is disabled. Ensure you pass in a constant to reduce memory allocations.

selectable?: bool #

Lets the user select text, to use the native copy and paste functionality.

style?: style #

color color
fontFamily string
fontSize number
fontStyle enum('normal', 'italic')
fontWeight enum('normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900')

Specifies font weight. The values 'normal' and 'bold' are supported for most fonts. Not all fonts have a variant for each of the numeric values, in that case the closest one is chosen.

lineHeight number
textAlign enum('auto', 'left', 'right', 'center', 'justify')

Specifies text alignment. The value 'justify' is only supported on iOS and fallbacks to left on Android.

textDecorationLine enum('none', 'underline', 'line-through', 'underline line-through')
textShadowColor color
textShadowOffset {width: number, height: number}
textShadowRadius number
androidincludeFontPadding bool

Set to false to remove extra font padding intended to make space for certain ascenders / descenders. With some fonts, this padding can make text look slightly misaligned when centered vertically. For best results also set textAlignVertical to center. Default is true.

androidtextAlignVertical enum('auto', 'top', 'bottom', 'center')
iosfontVariant [enum('small-caps', 'oldstyle-nums', 'lining-nums', 'tabular-nums', 'proportional-nums')]
iosletterSpacing number
iostextDecorationColor color
iostextDecorationStyle enum('solid', 'double', 'dotted', 'dashed')
ioswritingDirection enum('auto', 'ltr', 'rtl')

testID?: string #

Used to locate this view in end-to-end tests.

androidselectionColor?: color #

The highlight color of the text.

androidtextBreakStrategy?: enum('simple', 'highQuality', 'balanced') #

Set text break strategy on Android API Level 23+, possible values are simple, highQuality, balanced The default value is highQuality.

iosadjustsFontSizeToFit?: bool #

Specifies whether font should be scaled down automatically to fit given style constraints.

iosminimumFontScale?: number #

Specifies smallest possible scale a font can reach when adjustsFontSizeToFit is enabled. (values 0.01-1.0).

iossuppressHighlighting?: bool #

When true, no visual change is made when text is pressed down. By default, a gray oval highlights the text on press down.

You can edit the content above on GitHub and send us a pull request!

Description #

Nested Text #

Both iOS and Android allow you to display formatted text by annotating ranges of a string with specific formatting like bold or colored text (NSAttributedString on iOS, SpannableString on Android). In practice, this is very tedious. For React Native, we decided to use web paradigm for this where you can nest text to achieve the same effect.

import React, { Component } from 'react'; import { AppRegistry, Text } from 'react-native'; class BoldAndBeautiful extends Component { render() { return ( <Text style={{fontWeight: 'bold'}}> I am bold <Text style={{color: 'red'}}> and red </Text> </Text> ); } } AppRegistry.registerComponent('BoldAndBeautiful', () => BoldAndBeautiful);

Behind the scenes, React Native converts this to a flat NSAttributedString or SpannableString that contains the following information:

"I am bold and red" 0-9: bold 9-17: bold, red

Nested Views (iOS Only) #

On iOS, you can nest views within your Text component. Here's an example:

import React, { Component } from 'react'; import { AppRegistry, Text, View } from 'react-native'; class BlueIsCool extends Component { render() { return ( <Text> There is a blue square <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} /> in between my text. </Text> ); } } AppRegistry.registerComponent('BlueIsCool', () => BlueIsCool);

In order to use this feature, you must give the view a width and a height.

Containers #

The <Text> element is special relative to layout: everything inside is no longer using the flexbox layout but using text layout. This means that elements inside of a <Text> are no longer rectangles, but wrap when they see the end of the line.

<Text> <Text>First part and </Text> <Text>second part</Text> </Text> // Text container: all the text flows as if it was one // |First part | // |and second | // |part | <View> <Text>First part and </Text> <Text>second part</Text> </View> // View container: each text is its own block // |First part | // |and | // |second part|

Limited Style Inheritance #

On the web, the usual way to set a font family and size for the entire document is to take advantage of inherited CSS properties like so:

/* CSS, *not* React Native */ html { font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 11px; color: #141823; }

All elements in the document will inherit this font unless they or one of their parents specifies a new rule.

In React Native, we are more strict about it: you must wrap all the text nodes inside of a <Text> component; you cannot have a text node directly under a <View>.

// BAD: will raise exception, can't have a text node as child of a <View> <View> Some text </View> // GOOD <View> <Text> Some text </Text> </View>

You also lose the ability to set up a default font for an entire subtree. The recommended way to use consistent fonts and sizes across your application is to create a component MyAppText that includes them and use this component across your app. You can also use this component to make more specific components like MyAppHeaderText for other kinds of text.

<View> <MyAppText>Text styled with the default font for the entire application</MyAppText> <MyAppHeaderText>Text styled as a header</MyAppHeaderText> </View>

Assuming that MyAppText is a component that simply renders out its children into a Text component with styling, then MyAppHeaderText can be defined as follows:

class MyAppHeaderText extends Component { render() { <MyAppText> <Text style={{fontSize: 20}}> {this.props.children} </Text> </MyAppText> } }

Composing MyAppText in this way ensures that we get the styles from a top-level component, but leaves us the ability to add / override them in specific use cases.

React Native still has the concept of style inheritance, but limited to text subtrees. In this case, the second part will be both bold and red.

<Text style={{fontWeight: 'bold'}}> I am bold <Text style={{color: 'red'}}> and red </Text> </Text>

We believe that this more constrained way to style text will yield better apps:

  • (Developer) React components are designed with strong isolation in mind: You should be able to drop a component anywhere in your application, trusting that as long as the props are the same, it will look and behave the same way. Text properties that could inherit from outside of the props would break this isolation.

  • (Implementor) The implementation of React Native is also simplified. We do not need to have a fontFamily field on every single element, and we do not need to potentially traverse the tree up to the root every time we display a text node. The style inheritance is only encoded inside of the native Text component and doesn't leak to other components or the system itself.

You can edit the content above on GitHub and send us a pull request!

Examples #

IOS #

Edit on GitHub
'use strict'; const Platform = require('Platform'); var React = require('react'); var ReactNative = require('react-native'); var { Image, StyleSheet, Text, View, LayoutAnimation, } = ReactNative; class Entity extends React.Component { render() { return ( <Text style={{fontWeight: '500', color: '#527fe4'}}> {this.props.children} </Text> ); } } class AttributeToggler extends React.Component { state = {fontWeight: 'bold', fontSize: 15}; toggleWeight = () => { this.setState({ fontWeight: this.state.fontWeight === 'bold' ? 'normal' : 'bold' }); }; increaseSize = () => { this.setState({ fontSize: this.state.fontSize + 1 }); }; render() { var curStyle = {fontWeight: this.state.fontWeight, fontSize: this.state.fontSize}; return ( <View> <Text style={curStyle}> Tap the controls below to change attributes. </Text> <Text> <Text>See how it will even work on <Text style={curStyle}>this nested text</Text></Text> </Text> <Text style={{backgroundColor: '#ffaaaa', marginTop: 5}} onPress={this.toggleWeight}> Toggle Weight </Text> <Text style={{backgroundColor: '#aaaaff', marginTop: 5}} onPress={this.increaseSize}> Increase Size </Text> </View> ); } } var AdjustingFontSize = React.createClass({ getInitialState: function() { return {dynamicText:'', shouldRender: true,}; }, reset: function() { LayoutAnimation.easeInEaseOut(); this.setState({ shouldRender: false, }); setTimeout(()=>{ LayoutAnimation.easeInEaseOut(); this.setState({ dynamicText: '', shouldRender: true, }); }, 300); }, addText: function() { this.setState({ dynamicText: this.state.dynamicText + (Math.floor((Math.random() * 10) % 2) ? ' foo' : ' bar'), }); }, removeText: function() { this.setState({ dynamicText: this.state.dynamicText.slice(0, this.state.dynamicText.length - 4), }); }, render: function() { if (!this.state.shouldRender) { return (<View/>); } return ( <View> <Text lineBreakMode="tail" numberOfLines={1} style={{fontSize: 36, marginVertical:6}}> Truncated text is baaaaad. </Text> <Text numberOfLines={1} adjustsFontSizeToFit={true} style={{fontSize: 40, marginVertical:6}}> Shrinking to fit available space is much better! </Text> <Text adjustsFontSizeToFit={true} numberOfLines={1} style={{fontSize:30, marginVertical:6}}> {'Add text to me to watch me shrink!' + ' ' + this.state.dynamicText} </Text> <Text adjustsFontSizeToFit={true} numberOfLines={4} style={{fontSize:20, marginVertical:6}}> {'Multiline text component shrinking is supported, watch as this reeeeaaaally loooooong teeeeeeext grooooows and then shriiiinks as you add text to me! ioahsdia soady auydoa aoisyd aosdy ' + ' ' + this.state.dynamicText} </Text> <Text adjustsFontSizeToFit={true} numberOfLines={1} style={{marginVertical:6}}> <Text style={{fontSize:14}}> {'Differently sized nested elements will shrink together. '} </Text> <Text style={{fontSize:20}}> {'LARGE TEXT! ' + this.state.dynamicText} </Text> </Text> <View style={{flexDirection:'row', justifyContent:'space-around', marginTop: 5, marginVertical:6}}> <Text style={{backgroundColor: '#ffaaaa'}} onPress={this.reset}> Reset </Text> <Text style={{backgroundColor: '#aaaaff'}} onPress={this.removeText}> Remove Text </Text> <Text style={{backgroundColor: '#aaffaa'}} onPress={this.addText}> Add Text </Text> </View> </View> ); } }); exports.title = '<Text>'; exports.description = 'Base component for rendering styled text.'; exports.displayName = 'TextExample'; exports.examples = [ { title: 'Wrap', render: function() { return ( <Text> The text should wrap if it goes on multiple lines. See, this is going to the next line. </Text> ); }, }, { title: 'Padding', render: function() { return ( <Text style={{padding: 10}}> This text is indented by 10px padding on all sides. </Text> ); }, }, { title: 'Font Family', render: function() { return ( <View> <Text style={{fontFamily: (Platform.isTVOS ? 'Times' : 'Cochin')}}> Cochin </Text> <Text style={{fontFamily: (Platform.isTVOS ? 'Times' : 'Cochin'), fontWeight: 'bold'}}> Cochin bold </Text> <Text style={{fontFamily: 'Helvetica'}}> Helvetica </Text> <Text style={{fontFamily: 'Helvetica', fontWeight: 'bold'}}> Helvetica bold </Text> <Text style={{fontFamily: (Platform.isTVOS ? 'Courier' : 'Verdana')}}> Verdana </Text> <Text style={{fontFamily: (Platform.isTVOS ? 'Courier' : 'Verdana'), fontWeight: 'bold'}}> Verdana bold </Text> </View> ); }, }, { title: 'Font Size', render: function() { return ( <View> <Text style={{fontSize: 23}}> Size 23 </Text> <Text style={{fontSize: 8}}> Size 8 </Text> </View> ); }, }, { title: 'Color', render: function() { return ( <View> <Text style={{color: 'red'}}> Red color </Text> <Text style={{color: 'blue'}}> Blue color </Text> </View> ); }, }, { title: 'Font Weight', render: function() { return ( <View> <Text style={{fontSize: 20, fontWeight: '100'}}> Move fast and be ultralight </Text> <Text style={{fontSize: 20, fontWeight: '200'}}> Move fast and be light </Text> <Text style={{fontSize: 20, fontWeight: 'normal'}}> Move fast and be normal </Text> <Text style={{fontSize: 20, fontWeight: 'bold'}}> Move fast and be bold </Text> <Text style={{fontSize: 20, fontWeight: '900'}}> Move fast and be ultrabold </Text> </View> ); }, }, { title: 'Font Style', render: function() { return ( <View> <Text style={{fontStyle: 'normal'}}> Normal text </Text> <Text style={{fontStyle: 'italic'}}> Italic text </Text> </View> ); }, }, { title: 'Selectable', render: function() { return ( <View> <Text selectable={true}> This text is <Text style={{fontWeight: 'bold'}}>selectable</Text> if you click-and-hold. </Text> </View> ); }, }, { title: 'Text Decoration', render: function() { return ( <View> <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> </View> ); }, }, { title: 'Nested', description: 'Nested text components will inherit the styles of their ' + 'parents (only backgroundColor is inherited from non-Text parents). ' + '<Text> only supports other <Text> and raw text (strings) as children.', render: function() { return ( <View> <Text> (Normal text, <Text style={{fontWeight: 'bold'}}> (and bold <Text style={{fontSize: 11, color: '#527fe4'}}> (and tiny inherited bold blue) </Text> ) </Text> ) </Text> <Text style={{opacity:0.7}}> (opacity <Text> (is inherited <Text style={{opacity:0.7}}> (and accumulated <Text style={{backgroundColor:'#ffaaaa'}}> (and also applies to the background) </Text> ) </Text> ) </Text> ) </Text> <Text style={{fontSize: 12}}> <Entity>Entity Name</Entity> </Text> </View> ); }, }, { title: 'Text Align', render: function() { return ( <View> <Text> auto (default) - english LTR </Text> <Text> أحب اللغة العربية auto (default) - arabic RTL </Text> <Text style={{textAlign: 'left'}}> left left left left left left left left left left left left left left left </Text> <Text style={{textAlign: 'center'}}> center center center center center center center center center center center </Text> <Text style={{textAlign: 'right'}}> right right right right right right right right right right right right right </Text> <Text style={{textAlign: 'justify'}}> justify: this text component{"'"}s contents are laid out with "textAlign: justify" and as you can see all of the lines except the last one span the available width of the parent container. </Text> </View> ); }, }, { title: 'Letter Spacing', render: function() { return ( <View> <Text style={{letterSpacing: 0}}> letterSpacing = 0 </Text> <Text style={{letterSpacing: 2, marginTop: 5}}> letterSpacing = 2 </Text> <Text style={{letterSpacing: 9, marginTop: 5}}> letterSpacing = 9 </Text> <Text style={{letterSpacing: -1, marginTop: 5}}> letterSpacing = -1 </Text> </View> ); }, }, { title: 'Spaces', render: function() { return ( <Text> A {'generated'} {' '} {'string'} and some &nbsp;&nbsp;&nbsp; spaces </Text> ); }, }, { title: 'Line Height', render: function() { return ( <Text> <Text style={{lineHeight: 35}}> A lot of space between the lines of this long passage that should wrap once. </Text> </Text> ); }, }, { title: 'Empty Text', description: 'It\'s ok to have Text with zero or null children.', render: function() { return ( <Text /> ); }, }, { title: 'Toggling Attributes', render: function(): React.Element<any> { return <AttributeToggler />; }, }, { title: 'backgroundColor attribute', description: 'backgroundColor is inherited from all types of views.', render: function() { return ( <Text style={{backgroundColor: 'yellow'}}> Yellow container background, <Text style={{backgroundColor: '#ffaaaa'}}> {' '}red background, <Text style={{backgroundColor: '#aaaaff'}}> {' '}blue background, <Text> {' '}inherited blue background, <Text style={{backgroundColor: '#aaffaa'}}> {' '}nested green background. </Text> </Text> </Text> </Text> </Text> ); }, }, { title: 'numberOfLines attribute', render: function() { return ( <View> <Text numberOfLines={1}> Maximum of one line, no matter how much I write here. If I keep writing, it{"'"}ll just truncate after one line. </Text> <Text numberOfLines={2} style={{marginTop: 20}}> Maximum of two lines, no matter how much I write here. If I keep writing, it{"'"}ll just truncate after two lines. </Text> <Text style={{marginTop: 20}}> No maximum lines specified, no matter how much I write here. If I keep writing, it{"'"}ll just keep going and going. </Text> </View> ); }, }, { title: 'Text highlighting (tap the link to see highlight)', render: function() { return ( <View> <Text>Lorem ipsum dolor sit amet, <Text suppressHighlighting={false} style={{backgroundColor: 'white', textDecorationLine: 'underline', color: 'blue'}} onPress={() => null}>consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud</Text> exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</Text> </View> ); }, }, { title: 'allowFontScaling attribute', render: function() { return ( <View> <Text> By default, text will respect Text Size accessibility setting on iOS. It means that all font sizes will be increased or descreased depending on the value of Text Size setting in {" "}<Text style={{fontWeight: 'bold'}}>Settings.app - Display & Brightness - Text Size</Text> </Text> <Text style={{marginTop: 10}}> You can disable scaling for your Text component by passing {"\""}allowFontScaling={"{"}false{"}\""} prop. </Text> <Text allowFontScaling={false} style={{marginTop: 20}}> This text will not scale. </Text> </View> ); }, }, { title: 'Inline views', render: function() { return ( <View> <Text> This text contains an inline blue view <View style={{width: 25, height: 25, backgroundColor: 'steelblue'}} /> and an inline image <Image source={require('./flux.png')} style={{width: 30, height: 11, resizeMode: 'cover'}}/>. Neat, huh? </Text> </View> ); }, }, { title: 'Text shadow', render: function() { return ( <View> <Text style={{fontSize: 20, textShadowOffset: {width: 2, height: 2}, textShadowRadius: 1, textShadowColor: '#00cccc'}}> Demo text shadow </Text> </View> ); }, }, { title: 'Ellipsize mode', render: function() { return ( <View> <Text numberOfLines={1}> This very long text should be truncated with dots in the end. </Text> <Text ellipsizeMode="middle" numberOfLines={1}> This very long text should be truncated with dots in the middle. </Text> <Text ellipsizeMode="head" numberOfLines={1}> This very long text should be truncated with dots in the beginning. </Text> <Text ellipsizeMode="clip" numberOfLines={1}> This very looooooooooooooooooooooooooooong text should be clipped. </Text> </View> ); }, }, { title: 'Font variants', render: function() { return ( <View> <Text style={{fontVariant: ['small-caps']}}> Small Caps{'\n'} </Text> <Text style={{fontFamily: (Platform.isTVOS ? 'Times' : 'Hoefler Text'), fontVariant: ['oldstyle-nums']}}> Old Style nums 0123456789{'\n'} </Text> <Text style={{fontFamily: (Platform.isTVOS ? 'Times' : 'Hoefler Text'), fontVariant: ['lining-nums']}}> Lining nums 0123456789{'\n'} </Text> <Text style={{fontVariant: ['tabular-nums']}}> Tabular nums{'\n'} 1111{'\n'} 2222{'\n'} </Text> <Text style={{fontVariant: ['proportional-nums']}}> Proportional nums{'\n'} 1111{'\n'} 2222{'\n'} </Text> </View> ); }, }, { title: 'Dynamic Font Size Adjustment', render: function(): React.Element<any> { return <AdjustingFontSize />; }, }];

ANDROID #

Edit on GitHub
'use strict'; var React = require('react'); var ReactNative = require('react-native'); var { Image, StyleSheet, Text, View, } = ReactNative; var UIExplorerBlock = require('./UIExplorerBlock'); var UIExplorerPage = require('./UIExplorerPage'); class Entity extends React.Component { render() { return ( <Text style={{fontWeight: 'bold', color: '#527fe4'}}> {this.props.children} </Text> ); } } class AttributeToggler extends React.Component { state = {fontWeight: 'bold', fontSize: 15}; toggleWeight = () => { this.setState({ fontWeight: this.state.fontWeight === 'bold' ? 'normal' : 'bold' }); }; increaseSize = () => { this.setState({ fontSize: this.state.fontSize + 1 }); }; render() { var curStyle = {fontWeight: this.state.fontWeight, fontSize: this.state.fontSize}; return ( <View> <Text style={curStyle}> Tap the controls below to change attributes. </Text> <Text> <Text>See how it will even work on <Text style={curStyle}>this nested text</Text></Text> </Text> <Text> <Text onPress={this.toggleWeight}>Toggle Weight</Text> {' (with highlight onPress)'} </Text> <Text onPress={this.increaseSize} suppressHighlighting={true}> Increase Size (suppressHighlighting true) </Text> </View> ); } } class TextExample extends React.Component { static title = '<Text>'; static description = 'Base component for rendering styled text.'; render() { return ( <UIExplorerPage title="<Text>"> <UIExplorerBlock title="Wrap"> <Text> The text should wrap if it goes on multiple lines. See, this is going to the next line. </Text> </UIExplorerBlock> <UIExplorerBlock title="Padding"> <Text style={{padding: 10}}> This text is indented by 10px padding on all sides. </Text> </UIExplorerBlock> <UIExplorerBlock title="Font Family"> <Text style={{fontFamily: 'sans-serif'}}> Sans-Serif </Text> <Text style={{fontFamily: 'sans-serif', fontWeight: 'bold'}}> Sans-Serif Bold </Text> <Text style={{fontFamily: 'serif'}}> Serif </Text> <Text style={{fontFamily: 'serif', fontWeight: 'bold'}}> Serif Bold </Text> <Text style={{fontFamily: 'monospace'}}> Monospace </Text> <Text style={{fontFamily: 'monospace', fontWeight: 'bold'}}> Monospace Bold (After 5.0) </Text> </UIExplorerBlock> <UIExplorerBlock title="Android Material Design fonts"> <View style={{flexDirection: 'row', alignItems: 'flex-start'}}> <View style={{flex: 1}}> <Text style={{fontFamily: 'sans-serif'}}> Roboto Regular </Text> <Text style={{fontFamily: 'sans-serif', fontStyle: 'italic'}}> Roboto Italic </Text> <Text style={{fontFamily: 'sans-serif', fontWeight: 'bold'}}> Roboto Bold </Text> <Text style={{fontFamily: 'sans-serif', fontStyle: 'italic', fontWeight: 'bold'}}> Roboto Bold Italic </Text> <Text style={{fontFamily: 'sans-serif-light'}}> Roboto Light </Text> <Text style={{fontFamily: 'sans-serif-light', fontStyle: 'italic'}}> Roboto Light Italic </Text> <Text style={{fontFamily: 'sans-serif-thin'}}> Roboto Thin (After 4.2) </Text> <Text style={{fontFamily: 'sans-serif-thin', fontStyle: 'italic'}}> Roboto Thin Italic (After 4.2) </Text> <Text style={{fontFamily: 'sans-serif-condensed'}}> Roboto Condensed </Text> <Text style={{fontFamily: 'sans-serif-condensed', fontStyle: 'italic'}}> Roboto Condensed Italic </Text> <Text style={{fontFamily: 'sans-serif-condensed', fontWeight: 'bold'}}> Roboto Condensed Bold </Text> <Text style={{ fontFamily: 'sans-serif-condensed', fontStyle: 'italic', fontWeight: 'bold'}}> Roboto Condensed Bold Italic </Text> <Text style={{fontFamily: 'sans-serif-medium'}}> Roboto Medium (After 5.0) </Text> <Text style={{fontFamily: 'sans-serif-medium', fontStyle: 'italic'}}> Roboto Medium Italic (After 5.0) </Text> </View> </View> </UIExplorerBlock> <UIExplorerBlock title="Custom Fonts"> <View style={{flexDirection: 'row', alignItems: 'flex-start'}}> <View style={{flex: 1}}> <Text style={{fontFamily: 'notoserif'}}> NotoSerif Regular </Text> <Text style={{fontFamily: 'notoserif', fontStyle: 'italic', fontWeight: 'bold'}}> NotoSerif Bold Italic </Text> <Text style={{fontFamily: 'notoserif', fontStyle: 'italic'}}> NotoSerif Italic (Missing Font file) </Text> </View> </View> </UIExplorerBlock> <UIExplorerBlock title="Font Size"> <Text style={{fontSize: 23}}> Size 23 </Text> <Text style={{fontSize: 8}}> Size 8 </Text> </UIExplorerBlock> <UIExplorerBlock title="Color"> <Text style={{color: 'red'}}> Red color </Text> <Text style={{color: 'blue'}}> Blue color </Text> </UIExplorerBlock> <UIExplorerBlock title="Font Weight"> <Text style={{fontWeight: 'bold'}}> Move fast and be bold </Text> <Text style={{fontWeight: 'normal'}}> Move fast and be bold </Text> </UIExplorerBlock> <UIExplorerBlock title="Font Style"> <Text style={{fontStyle: 'italic'}}> Move fast and be bold </Text> <Text style={{fontStyle: 'normal'}}> Move fast and be bold </Text> </UIExplorerBlock> <UIExplorerBlock title="Font Style and Weight"> <Text style={{fontStyle: 'italic', fontWeight: 'bold'}}> Move fast and be bold </Text> </UIExplorerBlock> <UIExplorerBlock title="Text Decoration"> <Text style={{textDecorationLine: 'underline'}}> Solid underline </Text> <Text style={{textDecorationLine: 'none'}}> None textDecoration </Text> <Text style={{textDecorationLine: 'line-through', textDecorationStyle: 'solid'}}> Solid line-through </Text> <Text style={{textDecorationLine: 'underline line-through'}}> Both underline and line-through </Text> <Text> Mixed text with <Text style={{textDecorationLine: 'underline'}}>underline</Text> and <Text style={{textDecorationLine: 'line-through'}}>line-through</Text> text nodes </Text> </UIExplorerBlock> <UIExplorerBlock title="Nested"> <Text onPress={() => console.log('1st')}> (Normal text, <Text style={{fontWeight: 'bold'}} onPress={() => console.log('2nd')}> (and bold <Text style={{fontStyle: 'italic', fontSize: 11, color: '#527fe4'}} onPress={() => console.log('3rd')}> (and tiny bold italic blue <Text style={{fontWeight: 'normal', fontStyle: 'normal'}} onPress={() => console.log('4th')}> (and tiny normal blue) </Text> ) </Text> ) </Text> ) </Text> <Text style={{fontFamily: 'serif'}} onPress={() => console.log('1st')}> (Serif <Text style={{fontStyle: 'italic', fontWeight: 'bold'}} onPress={() => console.log('2nd')}> (Serif Bold Italic <Text style={{fontFamily: 'monospace', fontStyle: 'normal', fontWeight: 'normal'}} onPress={() => console.log('3rd')}> (Monospace Normal <Text style={{fontFamily: 'sans-serif', fontWeight: 'bold'}} onPress={() => console.log('4th')}> (Sans-Serif Bold <Text style={{fontWeight: 'normal'}} onPress={() => console.log('5th')}> (and Sans-Serif Normal) </Text> ) </Text> ) </Text> ) </Text> ) </Text> <Text style={{fontSize: 12}}> <Entity>Entity Name</Entity> </Text> </UIExplorerBlock> <UIExplorerBlock title="Text Align"> <Text> auto (default) - english LTR </Text> <Text> أحب اللغة العربية auto (default) - arabic RTL </Text> <Text style={{textAlign: 'left'}}> left left left left left left left left left left left left left left left </Text> <Text style={{textAlign: 'center'}}> center center center center center center center center center center center </Text> <Text style={{textAlign: 'right'}}> right right right right right right right right right right right right right </Text> </UIExplorerBlock> <UIExplorerBlock title="Unicode"> <View> <View style={{flexDirection: 'row'}}> <Text style={{backgroundColor: 'red'}}> 星际争霸是世界上最好的游戏。 </Text> </View> <View> <Text style={{backgroundColor: 'red'}}> 星际争霸是世界上最好的游戏。 </Text> </View> <View style={{alignItems: 'center'}}> <Text style={{backgroundColor: 'red'}}> 星际争霸是世界上最好的游戏。 </Text> </View> <View> <Text style={{backgroundColor: 'red'}}> 星际争霸是世界上最好的游戏。星际争霸是世界上最好的游戏。星际争霸是世界上最好的游戏。星际争霸是世界上最好的游戏。 </Text> </View> </View> </UIExplorerBlock> <UIExplorerBlock title="Spaces"> <Text> A {'generated'} {' '} {'string'} and some &nbsp;&nbsp;&nbsp; spaces </Text> </UIExplorerBlock> <UIExplorerBlock title="Line Height"> <Text style={{lineHeight: 35}}> Holisticly formulate inexpensive ideas before best-of-breed benefits. <Text style={{fontSize: 20}}>Continually</Text> expedite magnetic potentialities rather than client-focused interfaces. </Text> </UIExplorerBlock> <UIExplorerBlock title="Empty Text"> <Text /> </UIExplorerBlock> <UIExplorerBlock title="Toggling Attributes"> <AttributeToggler /> </UIExplorerBlock> <UIExplorerBlock title="backgroundColor attribute"> <Text style={{backgroundColor: '#ffaaaa'}}> Red background, <Text style={{backgroundColor: '#aaaaff'}}> {' '}blue background, <Text> {' '}inherited blue background, <Text style={{backgroundColor: '#aaffaa'}}> {' '}nested green background. </Text> </Text> </Text> </Text> <Text style={{backgroundColor: 'rgba(100, 100, 100, 0.3)'}}> Same alpha as background, <Text> Inherited alpha from background, <Text style={{backgroundColor: 'rgba(100, 100, 100, 0.3)'}}> Reapply alpha </Text> </Text> </Text> </UIExplorerBlock> <UIExplorerBlock title="containerBackgroundColor attribute"> <View style={{flexDirection: 'row', height: 85}}> <View style={{backgroundColor: '#ffaaaa', width: 150}} /> <View style={{backgroundColor: '#aaaaff', width: 150}} /> </View> <Text style={[styles.backgroundColorText, {top: -80}]}> Default containerBackgroundColor (inherited) + backgroundColor wash </Text> <Text style={[styles.backgroundColorText, {top: -70, backgroundColor: 'transparent'}]}> {"containerBackgroundColor: 'transparent' + backgroundColor wash"} </Text> </UIExplorerBlock> <UIExplorerBlock title="numberOfLines attribute"> <Text numberOfLines={1}> Maximum of one line no matter now much I write here. If I keep writing it{"'"}ll just truncate after one line </Text> <Text numberOfLines={2} style={{marginTop: 20}}> Maximum of two lines no matter now much I write here. If I keep writing it{"'"}ll just truncate after two lines </Text> <Text style={{marginTop: 20}}> No maximum lines specified no matter now much I write here. If I keep writing it{"'"}ll just keep going and going </Text> </UIExplorerBlock> <UIExplorerBlock title="selectable attribute"> <Text selectable> This text is selectable if you click-and-hold, and will offer the native Android selection menus. </Text> </UIExplorerBlock> <UIExplorerBlock title="selectionColor attribute"> <Text selectable selectionColor="orange"> This text will have a orange highlight on selection. </Text> </UIExplorerBlock> <UIExplorerBlock title="Inline images"> <Text> This text contains an inline image <Image source={require('./flux.png')}/>. Neat, huh? </Text> </UIExplorerBlock> <UIExplorerBlock title="Text shadow"> <Text style={{fontSize: 20, textShadowOffset: {width: 2, height: 2}, textShadowRadius: 1, textShadowColor: '#00cccc'}}> Demo text shadow </Text> </UIExplorerBlock> <UIExplorerBlock title="Ellipsize mode"> <Text numberOfLines={1}> This very long text should be truncated with dots in the end. </Text> <Text ellipsizeMode="middle" numberOfLines={1}> This very long text should be truncated with dots in the middle. </Text> <Text ellipsizeMode="head" numberOfLines={1}> This very long text should be truncated with dots in the beginning. </Text> </UIExplorerBlock> <UIExplorerBlock title="Include Font Padding"> <View style={{flexDirection: 'row', justifyContent: 'space-around', marginBottom: 10}}> <View style={{alignItems: 'center'}}> <Text style={styles.includeFontPaddingText}> Ey </Text> <Text>Default</Text> </View> <View style={{alignItems: 'center'}}> <Text style={[styles.includeFontPaddingText, {includeFontPadding: false, marginLeft: 10}]}> Ey </Text> <Text>includeFontPadding: false</Text> </View> </View> <Text>By default Android will put extra space above text to allow for upper-case accents or other ascenders. With some fonts, this can make text look slightly misaligned when centered vertically.</Text> </UIExplorerBlock> </UIExplorerPage> ); } } var styles = StyleSheet.create({ backgroundColorText: { left: 5, backgroundColor: 'rgba(100, 100, 100, 0.3)' }, includeFontPaddingText: { fontSize: 120, fontFamily: 'sans-serif', backgroundColor: '#EEEEEE', color: '#000000', textAlignVertical: 'center', alignSelf: 'center', } }); module.exports = TextExample;