React Native (RN) 是一个开源的移动应用开发框架,它主要使用JavaScript和React来构建iOS和Android应用。以下是一个简单的React Native应用实例,它创建了一个显示“Hello, World!”的简单屏幕。
首先,确保你已经安装了Node.js和npm,然后安装React Native CLI:
npm install -g react-native-cli创建一个新的React Native项目:
react-native init HelloWorld进入项目目录:
cd HelloWorld打开HelloWorld/App.js文件,并替换内容如下:
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
 
export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>Hello, World!</Text>
      </View>
    );
  }
}
 
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
});在模拟器上运行应用:
react-native run-android
# 或者
react-native run-ios这个例子展示了如何在React Native中创建一个简单的应用,并在屏幕上显示文本。