You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/react/your-first-app.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,15 @@ sidebar_label: Build Your First App
4
4
---
5
5
6
6
<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>
8
8
<meta
9
9
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."
11
11
/>
12
12
</head>
13
13
14
+
# Your First Ionic App: React
15
+
14
16
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.
15
17
16
18
Here’s the finished app running on all 3 platforms:
@@ -34,7 +36,7 @@ Highlights include:
34
36
- Deployed as a native iOS and Android mobile app using [Capacitor](https://capacitorjs.com), Ionic's official native app runtime.
35
37
- Photo Gallery functionality powered by the Capacitor [Camera](../native/camera.md), [Filesystem](../native/filesystem.md), and [Preferences](../native/preferences.md) APIs.
36
38
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.
38
40
39
41
## Download Required Tools
40
42
@@ -66,7 +68,7 @@ Consider setting up npm to operate globally without elevated permissions. See [R
66
68
67
69
## Create an App
68
70
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:
Copy file name to clipboardExpand all lines: docs/react/your-first-app/2-taking-photos.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,15 @@ sidebar_label: Taking Photos
4
4
---
5
5
6
6
<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>
8
8
<meta
9
9
name="description"
10
10
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."
11
11
/>
12
12
</head>
13
13
14
+
# Taking Photos with the Camera
15
+
14
16
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).
15
17
16
18
## Photo Gallery Hook
@@ -45,7 +47,7 @@ export function usePhotoGallery() {
45
47
46
48
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.
47
49
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.
49
51
50
52
```tsx
51
53
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
112
114
113
115
Return to `usePhotoGallery.ts`.
114
116
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.
116
118
117
119
```ts
118
120
exportfunction usePhotoGallery {
@@ -130,14 +132,14 @@ Above the `addNewToGallery()` method, define an array of `UserPhoto`, which will
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.
Copy file name to clipboardExpand all lines: docs/react/your-first-app/3-saving-photos.md
+14-4Lines changed: 14 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,14 @@ title: Saving Photos to the Filesystem
3
3
sidebar_label: Saving Photos
4
4
---
5
5
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
+
6
14
# Saving Photos to the Filesystem
7
15
8
16
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() {
60
68
});
61
69
62
70
const fileName =Date.now() +'.jpeg';
63
-
// CHANGE: Add `savedImageFile()`.
71
+
// CHANGE: Add `savedImageFile`.
64
72
// Save the picture and add it to photo collection
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:
Copy file name to clipboardExpand all lines: docs/react/your-first-app/6-deploying-mobile.md
+17-4Lines changed: 17 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,23 @@
1
1
---
2
+
title: Deploying to iOS and Android
2
3
sidebar_label: Deploying Mobile
3
4
---
4
5
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
+
5
14
# Deploying to iOS and Android
6
15
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
+
:::
8
21
9
22
## Capacitor Setup
10
23
@@ -19,8 +32,8 @@ ionic build
19
32
Next, create both the iOS and Android projects:
20
33
21
34
```shell
22
-
$ ionic cap add ios
23
-
$ ionic cap add android
35
+
ionic cap add ios
36
+
ionic cap add android
24
37
```
25
38
26
39
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
51
64
ionic cap open ios
52
65
```
53
66
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."
55
68
56
69

0 commit comments