开始使用 React Native
React Native 允许了解 React 的开发者创建原生应用。同时,原生开发者可以使用 React Native 通过编写一次通用功能来获得原生平台之间的奇偶校验。
¥React Native allows developers who know React to create native apps. At the same time, native developers can use React Native to gain parity between native platforms by writing common features once.
我们相信体验 React Native 的最佳方式是通过框架,这是一个包含所有必要 API 的工具箱,可让你构建可用于生产的应用。
¥We believe that the best way to experience React Native is through a Framework, a toolbox with all the necessary APIs to let you build production ready apps.
你也可以在没有框架的情况下使用 React Native,但我们发现大多数开发者都受益于使用像 Expo 这样的 React Native 框架。Expo 提供基于文件的路由、高质量通用库等功能,以及编写修改原生代码的插件而无需管理原生文件的能力。
¥You can also use React Native without a Framework, however we’ve found that most developers benefit from using a React Native Framework like Expo. Expo provides features like file-based routing, high-quality universal libraries, and the ability to write plugins that modify native code without having to manage native files.
Can I use React Native without a Framework?
是。你可以在没有框架的情况下使用 React Native。但是,如果你使用 React Native 构建新应用,我们建议使用框架。
¥Yes. You can use React Native without a Framework. However, if you’re building a new app with React Native, we recommend using a Framework.
简而言之,你将能够花时间编写应用,而不是除了应用之外自己编写整个框架。
¥In short, you’ll be able to spend time writing your app instead of writing an entire Framework yourself in addition to your app.
React Native 社区花费了数年时间改进导航方法、访问原生 API、处理原生依赖等。大多数应用都需要这些核心功能。React Native 框架从应用启动时就提供它们。
¥The React Native community has spent years refining approaches to navigation, accessing native APIs, dealing with native dependencies, and more. Most apps need these core features. A React Native Framework provides them from the start of your app.
如果没有框架,你要么必须编写自己的解决方案来实现核心功能,要么必须拼凑一组预先存在的库来创建框架的骨架。这需要真正的工作,无论是在启动你的应用时,还是在稍后维护它时。
¥Without a Framework, you’ll either have to write your own solutions to implement core features, or you’ll have to piece together a collection of pre-existing libraries to create a skeleton of a Framework. This takes real work, both when starting your app, then later when maintaining it.
如果你的应用有框架无法很好地满足的不寻常约束,或者你更喜欢自己解决这些问题,你可以使用 Android Studio、Xcode 制作不使用框架的 React Native 应用。如果你对这条路径感兴趣,请了解如何 设置你的环境 和如何 无需框架即可开始使用。
¥If your app has unusual constraints that are not served well by a Framework, or you prefer to solve these problems yourself, you can make a React Native app without a Framework using Android Studio, Xcode. If you’re interested in this path, learn how to set up your environment and how to get started without a framework.
使用开始一个新的 React Native 项目展览
¥Start a new React Native project with Expo
Expo 是一个生产级的 React Native 框架。Expo 提供开发者工具,使开发应用更加容易,例如基于文件的路由、标准的原生模块库等等。
¥Expo is a production-grade React Native Framework. Expo provides developer tooling that makes developing apps easier, such as file-based routing, a standard library of native modules, and much more.
Expo 的框架是免费的开源框架,在 GitHub 和 Discord 上拥有活跃的社区。Expo 团队与 Meta 的 React Native 团队密切合作,将最新的 React Native 功能引入 Expo SDK。
¥Expo's Framework is free and open source, with an active community on GitHub and Discord. The Expo team works in close collaboration with the React Native team at Meta to bring the latest React Native features to the Expo SDK.
Expo 团队还提供 Expo 应用服务 (EAS),这是一组可选服务,可在开发过程的每个步骤中补充 Expo 框架。
¥The team at Expo also provides Expo Application Services (EAS), an optional set of services that complements Expo, the Framework, in each step of the development process.
要创建新的 Expo 项目,请在你的终端中运行以下命令:
¥To create a new Expo project, run the following in your terminal:
npx create-expo-app@latest
创建应用后,请查看 Expo 的其余入门指南以开始开发应用。
¥Once you’ve created your app, check out the rest of Expo’s getting started guide to start developing your app.