如何将React App转换为React Native

I have been working on a lot of mobile projects lately — including Cordova, PhoneGap, React Native, some Ionic and Swift — but I have to say, React Native is by far the best experience in mobile development I have had so far. It has great, web-like developer tools, lets me use NPM packages plus a lot of great react-native ones, and also produces faster, smoother apps than Cordova or Ionic. It shares the same workflow as a React application for the web which is pretty easy to reason about and find where things are quickly.

我最近一直在从事许多移动项目的工作,包括Cordova,PhoneGap,React Native,一些Ionic和Swift,但是我不得不说,React Native是迄今为止迄今为止在移动开发方面最好的经验。 它具有出色的,类似于Web的开发人员工具,可让我使用NPM软件包以及许多出色的react-native软件包,并且还比Cordova或Ionic生成更快,更流畅的应用程序。 它与Web上的React应用程序共享相同的工作流程,这很容易推理和快速找到问题所在。

Now I am building an app to gamify recycling in Indiana. I have a web app completed in alpha, however, the app required the use of geolocation, augmented reality, and some other features, so I am building a mobile app to complement the one for the web. Since the web app is in React, I figured it would be easier to build the Native version in iOS and Android at the same time using React Native.

现在,我正在构建一个应用程序,以游戏化印第安纳州的回收利用。 我有一个用Alpha完成的Web应用程序,但是该应用程序需要使用地理位置,增强现实和其他一些功能,因此我正在构建一款移动应用程序以补充该Web应用程序。 由于该Web应用程序位于React中,因此我认为使用React Native在iOS和Android中同时构建Native版本会更容易。

Here are some mockups to give you an idea.

这里有一些样机可以给你一个想法。

设置React Native App (Setting Up the React Native App)

Where React Native outdoes React is on it’s simple set up for apps. One command creates a folder with all your Xcode and Android set up as well as a starter app ready for the emulator.

React Native胜过React的地方是它为应用程序的简单设置。 一个命令将创建一个文件夹,其中包含您所有的Xcode和Android设置以及一个可供模拟器使用的入门应用程序。

Link to simple set up instructions.

链接到简单的设置说明 。

After getting it to run in the simulator, I create a ‘src’ directory to put all my code in. Then I turn on live reload (command + D opens the dev menu on iOS and control + D on Android) and begin developing!

在模拟器中运行它之后,我创建一个“ src”目录来放入我的所有代码。然后打开实时重新加载(在iOS上,命令+ D打开dev菜单,在Android上使用control + D)并开始开发!

A quick note about React-style applications: If you are new to this, it can feel a little strange to return your view from your .js files.

关于React风格应用程序的快速说明:如果您不熟悉此功能,从.js文件返回视图可能会有些奇怪。

React, in its simplest form is a way to write modular, reusable code. Each component is broken down into sub components wherever it makes sense. Each component is encapsulated as a function or class in its own file, meaning you only import what you need. The function then return its view — the content to display on the screen from the component.

最简单的形式React是一种编写模块化,可重用代码的方法。 只要有意义,每个组件都会分解为子组件。 每个组件都作为函数或类封装在其自己的文件中,这意味着您仅导入所需的内容。 然后,该函数返回其视图-内容从组件显示在屏幕上。

I have a menu on the web, but I need to change the location for mobile. I wanted the user to be able to swipe or click to open the menu. There are a surprising number of React Native libraries out there to cover most mobile needs.

我在网上有一个菜单,但是我需要更改手机的位置。 我希望用户能够滑动或单击以打开菜单。 有数量惊人的React Native库可以满足大多数移动需求。

react-native-side-menu is a great little library that was pretty easy to set up. I tested out the swiping to make sure it was smooth and then added links to the side menu.

react-native-side-menu是一个很棒的小库,很容易设置。 我测试了滑动以确保滑动流畅,然后将链接添加到侧面菜单。

RN doesn’t come with a built in navigation solution, so I added react-native-router-flux. It works great, even if you are not using a traditional flux (flux was similar in concept to Redux) state management system and it’s easy to set up.

RN没有内置的导航解决方案,因此我添加了react-native-router-flux 。 即使您没有使用传统的流量(流量在概念上与Redux类似)状态管理系统,它也很有效,并且易于设置。

A Scene is a ‘view’ or a ‘page’ in the application (you can see how the navigation works together in the short video clip at the end). The titleattribute shows up in the header at the top, the key is used for navigating to the specific page, and the component is the actual Javascript file that contains the React Native component to display on that page. So, I created a component for each page with placeholder content:

Scene是应用程序中的“视图”或“页面”(您可以在末尾的短片中看到导航的工作方式)。 title属性显示在顶部的标题中,该key用于导航到特定页面,该component是实际的Javascript文件,其中包含要在该页面上显示的React Native组件。 因此,我为每个带有占位符内容的页面创建了一个组件:

Now, there is a menu and basic dummy pages and the user has the ability to navigate around the app. That was pretty quick and easy —I just installed a few modules and wrote a minimal amount of code.

现在,有一个菜单和基本的虚拟页面,用户可以在应用程序中导航。 那是非常快速和容易的—我只安装了几个模块并编写了最少的代码。

列表视图 (List Views)

Most of the components I made I was able to copy from my web app and just update the UI.

我制作的大多数组件都可以从Web应用程序复制并只需更新UI。

For this app, I have an ever-growing array of various characters that I wanted to display in a scrollable list on mobile. React Native offers ScrollView and ListView as build in solutions for handling infinite scroll.

对于这个应用程序,我有各种各样的字符,我想在移动设备上的滚动列表中显示这些数组。 React Native提供ScrollView和ListView作为内置解决方案来处理无限滚动。

Each one of the animals above can be clicked on and viewed on an individual page:

上面的每个动物都可以单击并在单独的页面上查看:

I set the ‘Amici Info’ page as a scene in the router and populate it with the information of the creature that was clicked on.

我将“ Amici Info”页面设置为路由器中的一个场景,并在其中填充了被单击的生物的信息。

可重复使用的组件 (Reusable Components)

I can also make wrappers around components with styles and basic functionality of common mobile solutions. eg cards, I can update the colors and padding slightly for each project.

我还可以使用常见移动解决方案的样式和基本功能来围绕组件包装。 例如卡片,我可以为每个项目稍微更新颜色和填充。

通过Redux移植 (Porting Over Redux)

Fortunately, most of my redux and API calls are the same. The app doesn’t need quite as much data as the website, so I could remove a few functions.

幸运的是,我的大多数redux和API调用都是相同的。 该应用程序不需要与网站一样多的数据,因此我可以删除一些功能。

The only thing I am doing so far is fetching the character objects from DynamoDB (AWS).

到目前为止,我唯一要做的就是从DynamoDB(AWS)获取字符对象。

This is the reducer to match this action:

这是匹配此操作的减速器:

That’s basically the state of Redux so far. I still have a lot more work to do on the Redux part but this is a good start. Next up: I need to set up a map component and display the locations for users to see.

到目前为止,这基本上是Redux的状态。 在Redux方面,我还有很多工作要做,但这是一个好的开始。 下一步:我需要设置一个地图组件并显示位置以供用户查看。

调试和开发工具 (Debugging and Dev Tools)

One of the best features of React Native is the dev tooling. Command + D gives me a dev menu:

React Native的最佳功能之一是开发工具。 Command + D给我一个开发菜单:

It’s one click to open up Chrome Developer Tools or use an inspector similar to the inspect element option when right-clicking in a browser.

在浏览器中单击鼠标右键时,只需单击一下即可打开Chrome开发者工具或使用类似于inspect element选项的inspect element器。

结语 (Wrapping Up)

For an MVP, I think it’s coming along well so far.

对于MVP,我认为到目前为止进展顺利。

I really enjoy working in React Native and I will continue to use it whenever possible until something better comes along.

我真的很喜欢在React Native中工作,我会尽可能继续使用它,直到出现更好的情况为止。

If I’m missing any information in this article or you have any questions, let me know :)

如果我缺少本文中的任何信息,或者您有任何疑问,请告诉我 :)

翻译自: https://www.freecodecamp.org/news/converting-a-react-app-to-react-native/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/396325.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

HTTP状态码:400\500 错误代码

转自:http://blog.sina.com.cn/s/blog_59b052fa0100it74.html一些常见的状态码为:200 - 服务器成功返回网页404 - 请求的网页不存在503 - 服务不可用详细分解:1xx(临时响应)表示临时响应并需要请求者继续执行操作的状态…

dhcp服务

安装与配置 配置文件 修改配置文件 复制这个文件到另一端 打开另一端的配置文件 原端输入这些命令可以去掉英文 然后vim进入另一端配置文件 全局配置不在{}内的 分发范围是指哪个ip到哪个ip的范围 指定固定电脑获取固定位置 原端修改配置文件 下面进行启动dhcp 克隆一台虚拟机&…

python数据结构与算法40题_Python数据结构与算法40:递归编程练习题3:ASCII谢尔宾斯基地毯...

注:本文如涉及到代码,均经过Python 3.7实际运行检验,保证其严谨性。本文阅读时间约为7分钟。递归编程练习题3:ASCII谢尔宾斯基地毯谢尔宾斯基地毯谢尔宾斯基地毯是形如上图的正方形分形图案,每个地毯可分为等大小的9份…

使用Python发送电子邮件

by Arjun Krishna Babu通过Arjun Krishna Babu 如何使用Python发送电子邮件 (How to send emails using Python) As a learning exercise, I recently dug into Python 3 to see how I could fire off a bunch of emails. There may be more straightforward methods of doing…

此blog不更了

1转载于:https://www.cnblogs.com/ybai62868/p/5384097.html

Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart)

在接触WebService时值得收藏的一篇文章: 在调试Axis1.4访问WebService服务时,出现以下错误: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart) 有错误找到错误原因以及发现值得收藏的…

java遍历树结构数据_Java数据结构——二叉树的遍历(汇总)

二叉树的遍历分为深度优先遍历(DFS)和广度优先遍历(BFS)DFS遍历主要有:前序遍历中序遍历后序遍历一、递归实现DFSNode.java:public class Node {private Object data;Node richild;Node lechild;public Object getData() {return data;}public void setData(Object …

vue 移动端头像裁剪_使用vue-cropper裁剪正方形上传头像-阿里云开发者社区

引用方式在组件内使用import { VueCropper } from vue-croppercomponents: {VueCropper,},main.js里面使用import VueCropper from vue-cropperVue.use(VueCropper)基本使用方法ref"cropper":img"option.img":autoCrop"true":fixedNumber"[…

规则引擎 设计 git_引擎盖下的Git

规则引擎 设计 gitby Wassim Chegham由Wassim Chegham 引擎盖下的Git (Git under the hood) Let’s explore some common Git commands, and dive into its internals to see what Git does when you run them.让我们探索一些常见的Git命令,并深入了解其内部&#…

练习题之死锁

public class PrintMain {public static String obj1"obj1";public static String obj2"obj2";public static void main(String[] args) {new Thread(new Runnable() {public void run() {System.out.println(new Date().toString "LockA开始执行&qu…

启用或禁用对 Exchange Server 中的邮箱的 POP3 或 IMAP4 访问

https://docs.microsoft.com/zh-cn/Exchange/clients/pop3-and-imap4/configure-mailbox-access?viewexchserver-2019 记录下转载于:https://www.cnblogs.com/amoy9812/p/9875426.html

java有什么压力_编程语言的心智负担!你学编程得有多大的压力快来测试一下...

很多编程语言对比的文章,总喜欢比较各种编程语言的性能、语法、IO模型。本文将从心智负担这个角度去比较下不同的编程语言和技术。内存越界如:C语言、C(C with class)C/C可以直接操作内存,但编程必须要面对内存越界问题。发生内存越界后&…

什么叫有效物理网卡_如何区分虚拟网卡和物理网卡?-阿里云开发者社区

一、什么是物理网卡和虚拟网卡?图示如下:红色部分包含VMWare的为虚拟网卡。通常,我们部署VMWare虚拟机、VMSphere虚拟集群、XenCenter虚拟集群是都会涉及虚拟网卡。二、辨别物理网卡和虚拟网卡的应用场景场景一:一般部署虚拟集群的…

算法复杂度的表示法_用简单的英语算法:时间复杂度和Big-O表示法

算法复杂度的表示法by Michael Olorunnisola通过Michael Olorunnisola 用简单的英语算法:时间复杂度和Big-O表示法 (Algorithms in plain English: time complexity and Big-O notation) Every good developer has time on their mind. They want to give their us…

Android Studio 开始运行错误

/********************************************************************************* Android Studio 开始运行错误* 说明:* 打开Android Studio就抛出这个错误。* * 2017-4-1 深圳 南…

IOS 计步器

这篇博客介绍的是当前比较流行的“计步器”-只是简单的知识点 计步器的实现在IOS8开始进行了改变。 但是我会对之前之后的都进行简单介绍。 IOS 8 - // // ViewController.m // CX 计步器 // // Created by ma c on 16/4/12. // Copyright © 2016年 bjsxt. All rights…

vue学习之二ECMAScript6标准

一、ECMAScript6标准简述 ECMAScript 6.0(以下简称 ES6)是 JavaScript 语言的下一代标准,已经在 2015 年 6 月正式发布了。它的目标,是使得 JavaScript 语言可以用来编写复杂的大型应用程序,成为企业级开发语言。 1.1E…

抖音吸粉_抖音吸粉5大实用方法首次分享!轻松实现粉丝10000+

抖音,是一款可以拍短视频的音乐创意短视频社交软件,该软件于2016年9月上线,是一个专注年轻人音乐短视频社区。用户可以通过这款软件选择歌曲,拍摄音乐短视频,形成自己的作品。抖音APP仅推出半年,用户量就突…

mapper mysql 主键_实现通用mapper主键策略兼容mysql和oracle

【原创文章,转载请注明原文章地址,谢谢!】1.直接用官方提供的注解方法是无法达到兼容效果的2.跟踪源码看看是否有其他方法3.这里有个genSql,可以看一下这个类4.创建一个自定义的处理类实现GenSql(代码中是我实际项目中用到的策略&…

权限分配界面 纯手工 仅用到bootstrap的架构 以及 c标签

<div class"form-group"> <div class"row"> <label class"col-sm-2 control-label">配置权限</label> <div class"col-sm-10"> <c:forEach var"m" items…