Skip to content

Commit 978d7e6

Browse files
committed
docs(react): update your first app pages
1 parent cb2cdff commit 978d7e6

File tree

8 files changed

+61
-258
lines changed

8 files changed

+61
-258
lines changed

docs/react/your-first-app.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ sidebar_label: Build Your First App
44
---
55

66
<head>
7-
<title>Build Your First Ionic Mobile App: React Development Tutorial</title>
7+
<title>Build Your First Ionic Mobile App with React | Ionic Capacitor Camera</title>
88
<meta
99
name="description"
10-
content="Ionic's single codebase builds for any platform using just HTML, CSS, & JavaScript. Develop your first mobile app with our step-by-step React tutorial."
10+
content="This React tutorial teaches the fundamentals of Ionic app development by creating a realistic app step-by-step. Learn to run your first Ionic app with React."
1111
/>
1212
</head>
1313

14+
# Your First Ionic App: React
15+
1416
The great thing about Ionic is that with one codebase, you can build for any platform using just HTML, CSS, and JavaScript. Follow along as we learn the fundamentals of Ionic app development by creating a realistic app step by step.
1517

1618
Here’s the finished app running on all 3 platforms:
@@ -34,7 +36,7 @@ Highlights include:
3436
- Deployed as a native iOS and Android mobile app using [Capacitor](https://capacitorjs.com), Ionic's official native app runtime.
3537
- Photo Gallery functionality powered by the Capacitor [Camera](../native/camera.md), [Filesystem](../native/filesystem.md), and [Preferences](../native/preferences.md) APIs.
3638

37-
Find the complete app code referenced in this guide [on GitHub](https://github.com/ionic-team/tutorial-photo-gallery-react).
39+
Find the [complete app code](https://github.com/ionic-team/tutorial-photo-gallery-react) referenced in this guide on GitHub.
3840

3941
## Download Required Tools
4042

@@ -66,7 +68,7 @@ Consider setting up npm to operate globally without elevated permissions. See [R
6668

6769
## Create an App
6870

69-
Next, create an Ionic React app that uses the Tabs starter template and adds Capacitor for native functionality:
71+
Next, create an Ionic React app that uses the "Tabs" starter template and adds Capacitor for native functionality:
7072

7173
```shell
7274
ionic start photo-gallery tabs --type=react --capacitor

docs/react/your-first-app/2-taking-photos.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ sidebar_label: Taking Photos
44
---
55

66
<head>
7-
<title>Build Camera API for iOS, Android & Web | Ionic Capacitor Camera</title>
7+
<title>Take Photos with Camera API for iOS, Android & Web with React | Ionic Capacitor Camera</title>
88
<meta
99
name="description"
1010
content="Add the ability to take photos with your device's camera using the Ionic Capacitor Camera API for mobile iOS, Android, and the web. Learn how here."
1111
/>
1212
</head>
1313

14+
# Taking Photos with the Camera
15+
1416
Now for the fun part - adding the ability to take photos with the device’s camera using the Capacitor [Camera API](../../native/camera.md). We’ll begin with building it for the web, then make some small tweaks to make it work on mobile (iOS and Android).
1517

1618
## Photo Gallery Hook
@@ -45,7 +47,7 @@ export function usePhotoGallery() {
4547

4648
Notice the magic here: there's no platform-specific code (web, iOS, or Android)! The Capacitor Camera plugin abstracts that away for us, leaving just one method call - `getPhoto()` - that will open up the device's camera and allow us to take photos.
4749

48-
Next, in `Tab2.tsx`, import the `usePhotoGallery` method and destructure it to call its `addNewToGallery` method.
50+
Next, in `Tab2.tsx`, import the `usePhotoGallery()` method and destructure it to call its `addNewToGallery()` method.
4951

5052
```tsx
5153
import { camera, trash, close } from 'ionicons/icons';
@@ -112,7 +114,7 @@ After taking a photo, it disappears right away. We need to display it within our
112114

113115
Return to `usePhotoGallery.ts`.
114116

115-
Outside of the `usePhotoGallery` method definition (the very bottom of the file), create a new interface, `UserPhoto`, to hold our photo metadata.
117+
Outside of the `usePhotoGallery()` method definition (the very bottom of the file), create a new interface, `UserPhoto`, to hold our photo metadata.
116118

117119
```ts
118120
export function usePhotoGallery {
@@ -130,14 +132,14 @@ Above the `addNewToGallery()` method, define an array of `UserPhoto`, which will
130132

131133
```ts
132134
export function usePhotoGallery {
133-
// CHANGE: Add the photos array.
135+
// CHANGE: Add the `photos` array.
134136
const [photos, setPhotos] = useState<UserPhoto[]>([]);
135137

136138
// Same old code from before.
137139
}
138140
```
139141

140-
Over in the `addNewToGallery()` method, add the newly captured photo to the beginning of the `photos` array. Then, update the `userPhotoGallery` return statement with the `photos` array.
142+
Over in the `addNewToGallery()` method, add the newly captured photo to the beginning of the `photos` array. Then, update the `userPhotoGallery()` return statement with the `photos` array.
141143

142144
```ts
143145
export function usePhotoGallery() {

docs/react/your-first-app/3-saving-photos.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ title: Saving Photos to the Filesystem
33
sidebar_label: Saving Photos
44
---
55

6+
<head>
7+
<title>Saving Photos to the Filesystem with React | Ionic Capacitor Camera</title>
8+
<meta
9+
name="description"
10+
content="We’re now able to take multiple photos and display them in a photo gallery. Learn how to save these photos to the filesystem using the Ionic Capacitor Filesystem API."
11+
/>
12+
</head>
13+
614
# Saving Photos to the Filesystem
715

816
We’re now able to take multiple photos and display them in a photo gallery on the second tab of our app. These photos, however, are not currently being stored permanently, so when the app is closed, they will be deleted.
@@ -60,12 +68,13 @@ export function usePhotoGallery() {
6068
});
6169

6270
const fileName = Date.now() + '.jpeg';
63-
// CHANGE: Add `savedImageFile()`.
71+
// CHANGE: Add `savedImageFile`.
6472
// Save the picture and add it to photo collection
6573
const savedImageFile = await savePicture(capturedPhoto, fileName);
6674

6775
// CHANGE: Update state with new photo.
68-
setPhotos([savedImageFile, ...photos]);
76+
const newPhotos = [savedImageFile, ...photos];
77+
setPhotos(newPhotos);
6978
};
7079

7180
// CHANGE: Add `savePicture()` method.
@@ -124,7 +133,7 @@ export function usePhotoGallery() {
124133
};
125134
};
126135

127-
// CHANGE: Add the `convertBlobToBase64()` method.
136+
// CHANGE: Add `convertBlobToBase64()` method.
128137
const convertBlobToBase64 = (blob: Blob) => {
129138
return new Promise((resolve, reject) => {
130139
const reader = new FileReader();
@@ -171,7 +180,8 @@ export function usePhotoGallery() {
171180
// Save the picture and add it to photo collection
172181
const savedImageFile = await savePicture(capturedPhoto, fileName);
173182

174-
setPhotos([savedImageFile, ...photos]);
183+
const newPhotos = [savedImageFile, ...photos];
184+
setPhotos(newPhotos);
175185
};
176186

177187
const savePicture = async (photo: Photo, fileName: string): Promise<UserPhoto> => {

docs/react/your-first-app/4-loading-photos.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export function usePhotoGallery() {
5454
useEffect(() => {
5555
// CHANGE: Add `loadSaved()` method.
5656
const loadSaved = async () => {
57-
const { value } = await Preferences.get({ key: PHOTO_STORAGE });
58-
const photosInPreferences = (value ? JSON.parse(value) : []) as UserPhoto[];
57+
const { value: photoList } = await Preferences.get({ key: PHOTO_STORAGE });
58+
const photosInPreferences = (photoList ? JSON.parse(photoList) : []) as UserPhoto[];
5959
};
6060

6161
loadSaved();
@@ -78,8 +78,8 @@ export function usePhotoGallery() {
7878
useEffect(() => {
7979
// CHANGE: Update `loadSaved()` method.
8080
const loadSaved = async () => {
81-
const { value } = await Preferences.get({ key: PHOTO_STORAGE });
82-
const photosInPreferences = (value ? JSON.parse(value) : []) as UserPhoto[];
81+
const { value: photoList } = await Preferences.get({ key: PHOTO_STORAGE });
82+
const photosInPreferences = (photoList ? JSON.parse(photoList) : []) as UserPhoto[];
8383

8484
// CHANGE: Display the photo by reading into base64 format.
8585
for (const photo of photosInPreferences) {
@@ -115,8 +115,8 @@ export function usePhotoGallery() {
115115

116116
useEffect(() => {
117117
const loadSaved = async () => {
118-
const { value } = await Preferences.get({ key: PHOTO_STORAGE });
119-
const photosInPreferences = (value ? JSON.parse(value) : []) as UserPhoto[];
118+
const { value: photoList } = await Preferences.get({ key: PHOTO_STORAGE });
119+
const photosInPreferences = (photoList ? JSON.parse(photoList) : []) as UserPhoto[];
120120

121121
for (const photo of photosInPreferences) {
122122
const file = await Filesystem.readFile({

docs/react/your-first-app/5-adding-mobile.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const savePicture = async (photo: Photo, fileName: string): Promise<UserPhoto> =
8686
Next, add a new bit of logic in the `loadSaved()` method. On mobile, we can directly point to each photo file on the Filesystem and display them automatically. On the web, however, we must read each image from the Filesystem into base64 format. This is because the Filesystem API uses [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) under the hood. Update the `loadSaved()` method:
8787

8888
```ts
89-
// CHANGE: Update the `loadSaved` method.
89+
// CHANGE: Update `loadSaved` method.
9090
const loadSaved = async () => {
9191
const { value: photoList } = await Preferences.get({ key: PHOTO_STORAGE });
9292
const photosInPreferences = (photoList ? JSON.parse(photoList) : []) as UserPhoto[];

docs/react/your-first-app/6-deploying-mobile.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
---
2+
title: Deploying to iOS and Android
23
sidebar_label: Deploying Mobile
34
---
45

6+
<head>
7+
<title>Adding Mobile Support with React | Ionic Capacitor Camera</title>
8+
<meta
9+
name="description"
10+
content="Capacitor is Ionic’s official app runtime to deploy web apps to native platforms like iOS, Android, and more. Read for how to build and deploy Ionic React apps."
11+
/>
12+
</head>
13+
514
# Deploying to iOS and Android
615

7-
Since we added Capacitor to our project when it was first created, there’s only a handful of steps remaining until the Photo Gallery app is on our device! Remember, you can find the complete source code for this app [here](https://github.com/ionic-team/photo-gallery-capacitor-react).
16+
Since we added Capacitor to our project when it was first created, there’s only a handful of steps remaining until the Photo Gallery app is on our device!
17+
18+
:::note
19+
Remember, you can find the complete source code for this app [here](https://github.com/ionic-team/photo-gallery-capacitor-react).
20+
:::
821

922
## Capacitor Setup
1023

@@ -19,8 +32,8 @@ ionic build
1932
Next, create both the iOS and Android projects:
2033

2134
```shell
22-
$ ionic cap add ios
23-
$ ionic cap add android
35+
ionic cap add ios
36+
ionic cap add android
2437
```
2538

2639
Both android and ios folders at the root of the project are created. These are entirely standalone native projects that should be considered part of your Ionic app (i.e., check them into source control, edit them using their native tooling, etc.).
@@ -51,7 +64,7 @@ First, run the Capacitor `open` command, which opens the native iOS project in X
5164
ionic cap open ios
5265
```
5366

54-
In order for some native plugins to work, user permissions must be configured. In our photo gallery app, this includes the Camera plugin: iOS displays a modal dialog automatically after the first time that `Camera.getPhoto()` is called, prompting the user to allow the app to use the Camera. The permission that drives this is labeled Privacy - Camera Usage. To set it, the `Info.plist` file must be modified ([more details here](https://capacitorjs.com/docs/ios/configuration)). To access it, click "Info," then expand "Custom iOS Target Properties."
67+
In order for some native plugins to work, user permissions must be configured. In our photo gallery app, this includes the Camera plugin: iOS displays a modal dialog automatically after the first time that `Camera.getPhoto()` is called, prompting the user to allow the app to use the Camera. The permission that drives this is labeled "Privacy - Camera Usage." To set it, the `Info.plist` file must be modified ([more details here](https://capacitorjs.com/docs/ios/configuration)). To access it, click "Info," then expand "Custom iOS Target Properties."
5568

5669
![The Info.plist file in Xcode showing the NSCameraUsageDescription key added for camera access.](/img/guides/first-app-cap-ng/xcode-info-plist.png 'Xcode Info.plist Configuration')
5770

0 commit comments

Comments
 (0)