我今天开始使用React-Native。我正在关注网络教程。
Windows机器上的所有安装是否正确:
然后安装本机
npm install -g react-native-cli
终于是一个世界你好项目
react-native init albums
我没有任何错误。我的应用可以完美地在Android手机上运行(基本上可以加载)。
app.js取决于平台选择:
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from 'react'; import { Platform, StyleSheet, Text, View } from 'react-native'; const instructions = Platform.select({ ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', android: 'Double tap R on your keyboard to reload,\n' + 'Shake or press menu button for dev menu', }); export default class App extends Component<{}> { render() { return ( <View style={styles.container}> <Text style={styles.welcome}> Welcome to React Native! </Text> <Text style={styles.instructions}> To get started, edit App.js </Text> <Text style={styles.instructions}> {instructions} </Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, });
我只想知道这是否正常就不会生成那些文件。我应该创建这两个索引文件吗?还是最新的react- native不需要2个单独的文件?(我正在关注的教程是2017年1月)
这是添加到react-native的新功能。现在,新的项目模板不包含两个单独的文件。如果愿意,您仍然可以像以前一样创建和使用,但是按原样使用是正常的。这只是您的偏好和项目的要求。您可以在此处找到有关更改的更多信息。
从提交笔记
此更改(最初在 react-community / create-react-native- app#26中进行了讨论)将HelloWorld项目模板从两个几乎相同的入口点(index.android.js和index.ios.js)移至单个最小 index.js入口点。根组件在中创建App.js。这统一了react-native init和Create React Native App 之间的项目结构,并允许CRNA的弹出窗口使用HelloWorld模板中的入口点,而无需任何黑客来对其进行自定义。同样,可以App.js在HelloWorld和CRNA应用程序中以相同的方式将文档中的示例复制粘贴为相同的方式,而无需先了解 AppRegistry.registerComponent。
index.android.js
index.ios.js
index.js
App.js
react-native init
AppRegistry.registerComponent