React Native 项目,未生成 index.ios.js 或 index.android.js [英] React Native project, index.ios.js or index.android.js not generated

查看:18
本文介绍了React Native 项目,未生成 index.ios.js 或 index.android.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天开始使用 React-Native.我正在学习网络教程.

I started with React-Native today. And I am following a web tutorial.

是否在我的 Windows 机器上正确安装了所有:

Did all the installations correctly on my Windows machine:

  • Java Jdk
  • 安卓工作室
  • 节点/NPM
  • 纱线

然后安装 react-native

then installed react-native

npm install -g react-native-cli

终于有一个hello world项目了

finally a hello world project

react-native init albums

我没有收到任何错误.我的应用程序在我的 Android 手机上完美运行(基本上加载).

I am not getting any errors. My app runs (basically loads up) on my Android phone perfectly.

app.js 有点受平台选择的限制:

The app.js is bit conditional on platform choice:

 /**
 * 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 月的)

I just want to know if this is normal to not get those files generated. Shall I create those 2 index files? Or the latest react-native does not need 2 separate files? (The tutorial I am following is of Jan 2017)

推荐答案

这是添加到 react-native 的新功能.新项目模板现在不包含两个单独的文件.如果您愿意,您仍然可以像以前一样创建和使用,但按原样使用它只是正常的.它只是您的项目的偏好和要求.您可以在此处上找到有关更改的更多信息.

This is a new feature added to react-native. The new project template now doesn't contain two separate files. You can still create and use like before if you prefer but its just normal to use it as it is. Its just a preference and the requirement of your project. You can find more info about the change on here.

来自提交说明

此更改(最初在react-community/create-react-native-app#26) 移动 HelloWorld来自两个几乎相同的入口点的项目模板(index.android.jsindex.ios.js) 到单个最小index.js 入口点.根组件在 App.js 中创建.这统一了 react-native init 和创建React Native App并允许CRNA的eject使用入口点来自 HelloWorld 模板,无需任何技巧来自定义它.还文档中的示例可以以相同的方式复制粘贴到 App.js在 HelloWorld 和 CRNA 应用程序中,而无需先了解AppRegistry.registerComponent.

This change (initially discussed in react-community/create-react-native-app#26) moves the HelloWorld project template from two nearly identical entry points (index.android.js and index.ios.js) to a single, minimal index.js entry point. The root component is created in App.js. This unifies the project structure between react-native init and Create React Native App and allows CRNA's eject to use the entry point from the HelloWorld template without any hacks to customize it. Also examples in the docs can be just copy-pasted to App.js the same way in both HelloWorld and CRNA apps without having to first learn about AppRegistry.registerComponent.

这篇关于React Native 项目,未生成 index.ios.js 或 index.android.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆