如何將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.pswp.cn/news/396325.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/396325.shtml
英文地址,請注明出處:http://en.pswp.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…