使用React Native实现原生级别的APP:实战案例分享
warning:
这篇文章距离上次修改已过187天,其中的内容可能已经有所变动。
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
class HelloWorldApp extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.hello}>Hello, World!</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
hello: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
});
AppRegistry.registerComponent('HelloWorldApp', () => HelloWorldApp);
这段代码展示了如何使用React Native创建一个简单的Hello World应用程序。它定义了一个名为HelloWorldApp
的React组件,该组件在一个View
容器中渲染了一个Text
元素。StyleSheet
用于定义文本和容器的样式。最后,我们通过AppRegistry.registerComponent
将应用程序注册到全局变量,使其能够在设备或模拟器上运行。这是学习React Native的一个基本例子,展示了如何开始构建原生级别的应用程序。
评论已关闭