<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Peng</title>
    <description>The latest articles on DEV Community by Peng (@penghuili).</description>
    <link>https://dev.to/penghuili</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F420412%2Fa7e1fcd1-c742-4413-a288-c17731dbcde3.jpeg</url>
      <title>DEV Community: Peng</title>
      <link>https://dev.to/penghuili</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/penghuili"/>
    <language>en</language>
    <item>
      <title>PreCloud version 1.8.1: Improve navigation and the PayPal button</title>
      <dc:creator>Peng</dc:creator>
      <pubDate>Sun, 18 Sep 2022 18:35:02 +0000</pubDate>
      <link>https://dev.to/penghuili/precloud-version-181-improve-navigation-and-the-paypal-button-47p8</link>
      <guid>https://dev.to/penghuili/precloud-version-181-improve-navigation-and-the-paypal-button-47p8</guid>
      <description>&lt;p&gt;In this version, I made the app navigation not swipable, this way I find it more solid when switching between screens.&lt;/p&gt;

&lt;p&gt;I also added a “Copy” item in the menu for each password.&lt;/p&gt;

&lt;p&gt;There is one more secret. You may noticed the PayPal button on the settings screen if you are using Android. It wasn’t showing for iOS. Because apple only allows in app purchases for any kind of payment. If I show it, apple will reject my app.&lt;/p&gt;

&lt;p&gt;What I did in this version is, the PayPal button will only show after 7 days after I submit a new version. Apple normally reviews each version within 2 days, so they won’t see the button while reviewing 🤐&lt;/p&gt;

&lt;p&gt;I will change to 3 days in next version :)&lt;/p&gt;




&lt;p&gt;And feel free to use this button 😆&lt;/p&gt;




&lt;p&gt;Use &lt;code&gt;PreCloudBlog&lt;/code&gt; as password to decrypt this blog:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;PreCloud:wy4ECQMIoVsaaQScQn3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evKUQ==&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;Download the new version: &lt;a href="https://play.google.com/store/apps/details?id=com.precloud"&gt;Play store&lt;/a&gt; or &lt;a href="https://apps.apple.com/us/app/precloud/id1638793841"&gt;App store&lt;/a&gt;&lt;/p&gt;

</description>
      <category>encryption</category>
      <category>privacy</category>
      <category>paypal</category>
      <category>reactnative</category>
    </item>
    <item>
      <title>How much does it cost to build an app</title>
      <dc:creator>Peng</dc:creator>
      <pubDate>Thu, 08 Sep 2022 18:39:53 +0000</pubDate>
      <link>https://dev.to/penghuili/how-much-does-it-cost-to-build-an-app-2e6</link>
      <guid>https://dev.to/penghuili/how-much-does-it-cost-to-build-an-app-2e6</guid>
      <description>&lt;p&gt;Let me show you how much it costs to build an app.&lt;/p&gt;

&lt;p&gt;Recently I built an app called &lt;a href="https://www.peng.kiwi/precloud"&gt;PreCloud: Encrypt before upload&lt;/a&gt;, with which you can encrypt texts and files, then you can upload the encrypted texts and files to wherever you want, making any cloud provider an encrypted storage. It's free and open source. Give it a try :)&lt;/p&gt;




&lt;p&gt;The app is free and open sourced, but these are what I paid for:&lt;br&gt;
Google developer account: 25$ one time;&lt;br&gt;
Apple developer account: 99$ / year;&lt;br&gt;
Domain name (peng.kiwi): 12$ / year;&lt;/p&gt;

&lt;p&gt;And I need a Mac to build the iOS app, but I am using the Mac from work, so I wouldn't count this.&lt;br&gt;
And of course, all the time I spent on this.&lt;/p&gt;

&lt;p&gt;:)&lt;/p&gt;




&lt;p&gt;If you are interested, try the app, to protect your privacy.&lt;br&gt;
&lt;a href="https://play.google.com/store/apps/details?id=com.precloud"&gt;Play store&lt;/a&gt; &lt;br&gt;
&lt;a href="https://apps.apple.com/us/app/precloud/id1638793841"&gt;App store&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;And you can also support me ❤️&lt;br&gt;
&lt;a href="https://paypal.me/penghuili/"&gt;https://paypal.me/penghuili/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>cost</category>
    </item>
    <item>
      <title>How to use nodejs libs in react native?</title>
      <dc:creator>Peng</dc:creator>
      <pubDate>Mon, 05 Sep 2022 20:41:08 +0000</pubDate>
      <link>https://dev.to/penghuili/how-to-use-nodejs-libs-in-react-native-314a</link>
      <guid>https://dev.to/penghuili/how-to-use-nodejs-libs-in-react-native-314a</guid>
      <description>&lt;p&gt;React native is a different javascript running environment from browser and nodejs. If a library works in the browser or nodejs, it doesn't necessarily mean it will work in react native.&lt;/p&gt;

&lt;p&gt;Recently I built an app called &lt;a href="https://www.peng.kiwi/precloud"&gt;PreCloud: Encrypt before upload&lt;/a&gt;, with which you can encrypt texts and files, then you can upload the encrypted texts and files to wherever you want, making any cloud provider an encrypted storage. It's free and &lt;a href="https://github.com/penghuili/PreCloud"&gt;open source&lt;/a&gt;. Give it a try :)&lt;/p&gt;

&lt;p&gt;I used &lt;a href="https://github.com/openpgpjs/openpgpjs/"&gt;openpgpjs&lt;/a&gt; to do all the encryption and decryption. It works perfectly in the browser and nodejs, but not in react native :(&lt;/p&gt;

&lt;p&gt;There is a &lt;a href="https://github.com/orhan/react-native-openpgp"&gt;react-native-openpgp&lt;/a&gt;, but it's not very popular and seems under heavy development still.&lt;/p&gt;




&lt;p&gt;While I read the source code of the &lt;a href="https://github.com/FilenCloudDienste/filen-mobile"&gt;Filen app&lt;/a&gt;, I came across &lt;a href="https://github.com/nodejs-mobile/nodejs-mobile-react-native"&gt;nodejs-mobile-react-native&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;The project will build a nodejs into your app, then you can use almost all nodejs libraries in your react native app, it's very cool.&lt;/p&gt;

&lt;p&gt;The nodejs part lives in a &lt;code&gt;nodejs-assets&lt;/code&gt; folder, and it communicates with react native through events.&lt;/p&gt;

&lt;p&gt;Very easy to setup, check their &lt;a href="https://github.com/nodejs-mobile/nodejs-mobile-react-native#readme"&gt;readme&lt;/a&gt;, or see how it works in &lt;a href="https://github.com/penghuili/PreCloud"&gt;my app&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Drawback:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It will make your app size much bigger. For a normal app, the apk or the iOS build can be 80+Mb. (The android aab file will be smaller though, 20+Mb). But it's so helpful, I accept it;&lt;/li&gt;
&lt;li&gt;It only supports nodejs 12 for now. But they are looking to &lt;a href="https://github.com/nodejs-mobile/nodejs-mobile/pull/3"&gt;upgrade it to node 16&lt;/a&gt;;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;And if you are interested, try my &lt;a href="https://www.peng.kiwi/precloud"&gt;PreCloud&lt;/a&gt; app, to protect your privacy.&lt;br&gt;
Play store: &lt;a href="https://play.google.com/store/apps/details?id=com.precloud"&gt;https://play.google.com/store/apps/details?id=com.precloud&lt;/a&gt;&lt;br&gt;
App store: &lt;a href="https://apps.apple.com/us/app/precloud/id1638793841"&gt;https://apps.apple.com/us/app/precloud/id1638793841&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Like I said in the beginning, it's free, open source, and has no tracking and no server.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>node</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Internal and external storage in react native</title>
      <dc:creator>Peng</dc:creator>
      <pubDate>Tue, 30 Aug 2022 20:39:18 +0000</pubDate>
      <link>https://dev.to/penghuili/internal-and-external-storage-in-react-native-1jjm</link>
      <guid>https://dev.to/penghuili/internal-and-external-storage-in-react-native-1jjm</guid>
      <description>&lt;p&gt;I have been working with react native at work for 3 years, but I haven't touched the file system.&lt;/p&gt;

&lt;p&gt;Recently I built an app called &lt;a href="https://www.peng.kiwi/precloud"&gt;PreCloud: Encrypt before upload&lt;/a&gt;, with which you can encrypt texts and files, then you can upload the encrypted texts and files to wherever you want, making any cloud provider an encrypted storage. It's free and &lt;a href="https://github.com/penghuili/PreCloud"&gt;open source&lt;/a&gt;. Give it a try :)&lt;/p&gt;

&lt;p&gt;In this post I will share about managing files with react native.&lt;/p&gt;




&lt;h2&gt;
  
  
  Libraries used
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/rnmods/react-native-document-picker"&gt;react-native-document-picker&lt;/a&gt;: Pick files from phone;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/itinance/react-native-fs"&gt;react-native-fs&lt;/a&gt;: Manage files in the internal storage of your app, more on this later;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/react-native-share/react-native-share"&gt;react-native-share&lt;/a&gt;: Share files to other apps;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/vinzscam/react-native-file-viewer"&gt;react-native-file-viewer&lt;/a&gt;: View file in your app;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Two kinds of storage
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Intertal storage
&lt;/h3&gt;

&lt;p&gt;Every app has its own storage, that other apps don't have access to. For example this is the &lt;code&gt;Cache&lt;/code&gt; folder of my app in Simulator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/Users/penghui/Library/Developer/CoreSimulator/Devices/5BAEC586-2BA0-42A0-B615-926F1A4D59A0/data/Containers/Data/Application/EBB8401E-3B16-4A3E-98A1-D2DDC3900A90/Library/Caches
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this is the &lt;code&gt;Documents&lt;/code&gt; folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/Users/penghui/Library/Developer/CoreSimulator/Devices/5BAEC586-2BA0-42A0-B615-926F1A4D59A0/data/Containers/Data/Application/EBB8401E-3B16-4A3E-98A1-D2DDC3900A90/Documents
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are other folders, but I am only instersted in these 2 for now. You can check the full list in the &lt;a href="https://github.com/itinance/react-native-fs#constants"&gt;react-native-fs&lt;/a&gt; doc, with more explanation.&lt;/p&gt;

&lt;p&gt;I think these are the places where Spotify saves your downloaded music and where Youtube saves your downloaded videos.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/itinance/react-native-fs"&gt;react-native-fs&lt;/a&gt; is the perfect tool to handle files in internal storage, you can check their doc to find the functions you need.&lt;/p&gt;

&lt;p&gt;But like mentioned before, files in the internal storage can't be viewed by your phones &lt;code&gt;Files&lt;/code&gt; app or &lt;code&gt;Photos&lt;/code&gt; app, and you also can't just read files from external storage.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. External storage
&lt;/h3&gt;

&lt;p&gt;This is the normal storage you see on your phone, it's what you see in the &lt;code&gt;Files&lt;/code&gt; app, both for iOS and Android.&lt;/p&gt;




&lt;h2&gt;
  
  
  Moving files around
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. From external to internal
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/itinance/react-native-fs"&gt;react-native-fs&lt;/a&gt; is (&lt;strong&gt;almost&lt;/strong&gt;) only for processing internal files. So before it can do something with the file, you need to move it from external storage.&lt;/p&gt;

&lt;p&gt;For this we need &lt;a href="https://github.com/rnmods/react-native-document-picker"&gt;react-native-document-picker&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We need the &lt;a href="https://github.com/rnmods/react-native-document-picker"&gt;pick&lt;/a&gt; function, which will open the file picker. We can specify the &lt;a href="https://github.com/rnmods/react-native-document-picker#ios-and-android-only-copytocachesdirectory--documentdirectory"&gt;copyTo&lt;/a&gt; param, it supports 2 values: &lt;code&gt;cachesDirectory&lt;/code&gt; and &lt;code&gt;documentDirectory&lt;/code&gt;, what it does is, after users pick a file / multiple files in the file picker, the picked file/files will be copied to the &lt;code&gt;Caches&lt;/code&gt; or &lt;code&gt;Documents&lt;/code&gt; folder of your app's internal storage. Ta-da.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;a href="https://github.com/rnmods/react-native-document-picker"&gt;react-native-document-picker&lt;/a&gt; can pick all external files on Android (your images, files etc.), but on iOS, it can only pick files in the &lt;code&gt;Files&lt;/code&gt; app, it can't pick images in the &lt;code&gt;Photos&lt;/code&gt; app. You need to firstly "share" an image with the "Save to Files" option, then the image will be moved to &lt;code&gt;Files&lt;/code&gt;, then you can pick it with react-native-document-picker.&lt;/p&gt;

&lt;p&gt;If you need to pick images, there are some other libraries, I haven't tried them, but should be straightforward.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. From internal to external
&lt;/h3&gt;

&lt;p&gt;The file is moved to the internal storage, and you did some fancy processing (For me, I encrypt the file, see some code &lt;a href="https://github.com/penghuili/PreCloud/blob/how-to-files/nodejs-assets/nodejs-project/main.js"&gt;here&lt;/a&gt;), then you want to move the processed file to external storage.&lt;/p&gt;

&lt;h4&gt;
  
  
  Android
&lt;/h4&gt;

&lt;p&gt;On Android, it's easy, &lt;a href="https://github.com/itinance/react-native-fs"&gt;react-native-fs&lt;/a&gt; can do the job (remember the "almost" in "react-native-fs is almost only for processing internal files"?) It has a &lt;a href="https://github.com/itinance/react-native-fs#constants"&gt;DownloadDirectoryPath&lt;/a&gt;, which is only available on Android.&lt;/p&gt;

&lt;p&gt;You can use the &lt;a href="https://github.com/itinance/react-native-fs#copyfilefilepath-string-destpath-string-promisevoid"&gt;copyFile&lt;/a&gt; function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  await RNFS.copyFile(internalFilePath, `RNFS.DownloadDirectoryPath/${fileName}`);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the file will be copied to the &lt;code&gt;Download&lt;/code&gt; folder of the external storage. Done.&lt;/p&gt;

&lt;p&gt;You can see some real code &lt;a href="https://github.com/penghuili/PreCloud/blob/how-to-files/src/components/FileItem.js#L41"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  iOS
&lt;/h4&gt;

&lt;p&gt;But on iOS, I haven't found an easy way to move a file like that.&lt;/p&gt;

&lt;p&gt;I ended up using &lt;a href="https://github.com/react-native-share/react-native-share"&gt;react-native-share&lt;/a&gt;. It will open a share files bottom toolbox, then you can choose the "Save to Files" options to download it to the &lt;code&gt;Files&lt;/code&gt; app.&lt;/p&gt;

&lt;p&gt;react-native-share also works on Android of course.&lt;/p&gt;

&lt;p&gt;And I mis-used the &lt;a href="https://react-native-share.github.io/react-native-share/docs/share-open#supported-options"&gt;saveToFiles&lt;/a&gt; option :) The flag is only available for iOS. If it's false, and for example you are sharing an image, the opened share toolbox will have other options, like add the image to an album; But when &lt;code&gt;saveToFiles&lt;/code&gt; is true, the toolbox will only show the "Save to Files" option.&lt;/p&gt;

&lt;p&gt;So in my app, I have 2 icons under a file, one download icon, for which I set the &lt;code&gt;saveToFiles&lt;/code&gt; flag to true, and one share icon, for which I set the &lt;code&gt;saveToFiles&lt;/code&gt; flag to false.&lt;/p&gt;

&lt;p&gt;There is actually another way I found in &lt;a href="https://stackoverflow.com/a/56356490/5508710"&gt;this answer&lt;/a&gt;, which is you set the &lt;code&gt;UISupportsDocumentBrowser&lt;/code&gt; flag in the &lt;code&gt;Info.plist&lt;/code&gt; to true, and you use react-native-fs to save files to the &lt;code&gt;Documents&lt;/code&gt; folder of the internal storage, then the files will be accessible by the &lt;code&gt;Files&lt;/code&gt; app, that's it!&lt;br&gt;
I tried it, it works, but I don't like it, I feel I have less control.&lt;/p&gt;

&lt;p&gt;If you know a better way to download files on iOS, please let me know!&lt;/p&gt;




&lt;h2&gt;
  
  
  Bonus: view internal files in your app
&lt;/h2&gt;

&lt;p&gt;You can use the &lt;a href="https://github.com/vinzscam/react-native-file-viewer"&gt;react-native-file-viewer&lt;/a&gt; lib to open internal files, like an image, a PDF file etc. It's very easy to use, have a try.&lt;/p&gt;




&lt;p&gt;You can check all my app's code in &lt;a href="https://github.com/penghuili/PreCloud/tree/master"&gt;github&lt;/a&gt;;&lt;/p&gt;

&lt;p&gt;And if you are interested, try my &lt;a href="https://www.peng.kiwi/precloud"&gt;PreCloud&lt;/a&gt; app, to protect your privacy.&lt;br&gt;
Play store: &lt;a href="https://play.google.com/store/apps/details?id=com.precloud"&gt;https://play.google.com/store/apps/details?id=com.precloud&lt;/a&gt;&lt;br&gt;
App store: &lt;a href="https://apps.apple.com/us/app/precloud/id1638793841"&gt;https://apps.apple.com/us/app/precloud/id1638793841&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Like I said in the beginning, it's free, open source, and has no tracking and no server.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>file</category>
      <category>storage</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
