Skip to content

Display text in ReactNative

   

This is a sample of displaying Text with ReactNative.

react-native: 0.56.0

alt

import React, {Component} from 'react';
import {AppRegistry} from 'react-native';
import {
StyleSheet,
View,
Text,
Alert
} from 'react-native';
import {name as appName} from './app.json';
export class App extends Component {
showAlert(text) {
Alert.alert('Hello')
}
render() {
return (
<View style={styles.container}>
<Text
style={styles.text}
onPress={() => this.showAlert()}>
HelloHelloHelloHelloHelloHello
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
text: {
color: 'red',
fontWeight: 'bold',
backgroundColor: 'gray',
textAlign: 'center',
fontSize: 20,
paddingTop: 40,
paddingBottom: 20,
},
});
AppRegistry.registerComponent(appName, () => App);
view raw index.js hosted with ❤ by GitHub

  1. A note on the commands that are only used occasionally in ReactNative
  2. Show the indicator in ReactNative
  3. Display an image with ReactNative
  4. Specifying the size of the View in FlexBox
  5. Displaying a FlatList in ReactNative
  6. Display the button with ReactNative