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
@@ -4,13 +4,15 @@ sidebar_label: Build Your First App
4
4
---
5
5
6
6
<head>
7
-
<title>React Apps | Build Your First Ionic Framework React Application</title>
7
+
<title>Build Your First Ionic Mobile App with React | Ionic Capacitor Camera</title>
8
8
<meta
9
9
name="description"
10
-
content="Build your first Ionic React App. With one codebase, you can build an Ionic Framework application for any platform using just HTML, CSS, and JavaScript."
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:
@@ -19,9 +21,9 @@ Here’s the finished app running on all 3 platforms:
@@ -30,11 +32,11 @@ We'll create a Photo Gallery app that offers the ability to take photos with you
30
32
31
33
Highlights include:
32
34
33
-
- One React-based codebase that runs on the web, iOS, and Android using Ionic Framework [UI components](https://ionicframework.com/docs/components).
35
+
- One React-based codebase that runs on the web, iOS, and Android using Ionic Framework [UI components](../components.md).
34
36
- Deployed as a native iOS and Android mobile app using [Capacitor](https://capacitorjs.com), Ionic's official native app runtime.
35
-
- Photo Gallery functionality powered by the Capacitor [Camera](https://capacitorjs.com/docs/apis/camera), [Filesystem](https://capacitorjs.com/docs/apis/filesystem), and [Preferences](https://capacitorjs.com/docs/apis/preferences) APIs.
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/photo-gallery-capacitor-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
@@ -43,9 +45,8 @@ Download and install these right away to ensure an optimal Ionic development exp
43
45
-**Node.js** for interacting with the Ionic ecosystem. [Download the LTS version here](https://nodejs.org/en/).
44
46
-**A code editor** for... writing code! We are fans of [Visual Studio Code](https://code.visualstudio.com/).
45
47
-**Command-line interface/terminal (CLI)**:
46
-
-**Windows** users: for the best Ionic experience, we recommend the built-in command line (cmd) or the Powershell
47
-
CLI, running in Administrator mode.
48
-
-**Mac/Linux** users, virtually any terminal will work.
48
+
-**Windows** users: for the best Ionic experience, we recommend the built-in command line (cmd) or the Powershell CLI, running in Administrator mode.
49
+
-**Mac/Linux** users: virtually any terminal will work.
49
50
50
51
## Install Ionic Tooling
51
52
@@ -67,7 +68,7 @@ Consider setting up npm to operate globally without elevated permissions. See [R
67
68
68
69
## Create an App
69
70
70
-
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:
Some Capacitor plugins, including the Camera API, provide the web-based functionality and UI via the Ionic [PWA Elements library](https://github.com/ionic-team/pwa-elements).
93
+
Some Capacitor plugins, including the [Camera API](../native/camera.md), provide the web-based functionality and UI via the Ionic [PWA Elements library](https://github.com/ionic-team/pwa-elements).
93
94
94
95
It's a separate dependency, so install it next:
95
96
96
97
```shell
97
98
npm install @ionic/pwa-elements
98
99
```
99
100
100
-
After installation, open up the project in your code editor of choice.
101
-
102
101
Next, import `@ionic/pwa-elements` by editing `src/main.tsx`.
//CHANGE: Call the element loader before the render call.
108
111
defineCustomElements(window);
112
+
113
+
const container =document.getElementById('root');
114
+
const root =createRoot(container!);
115
+
root.render(
116
+
<React.StrictMode>
117
+
<App />
118
+
</React.StrictMode>
119
+
);
109
120
```
110
121
111
122
That’s it! Now for the fun part - let’s see the app in action.
112
123
113
124
## Run the App
114
125
115
-
Run this command in your shell:
126
+
Run this command next:
116
127
117
128
```shell
118
129
ionic serve
@@ -122,35 +133,52 @@ And voilà! Your Ionic app is now running in a web browser. Most of your app can
122
133
123
134
## Photo Gallery!!!
124
135
125
-
There are three tabs. Click on the Tab2 tab. It’s a blank canvas, aka the perfect spot to transform into a Photo Gallery. The Ionic CLI features Live Reload, so when you make changes and save them, the app is updated immediately!
136
+
There are three tabs. Click on the "Tab2" tab. It’s a blank canvas, aka the perfect spot to transform into a Photo Gallery. The Ionic CLI features Live Reload, so when you make changes and save them, the app is updated immediately!
126
137
127
138

`IonHeader` represents the top navigation and toolbar, with "Tab 2" as the title. Let’s rename it:
170
+
`IonHeader` represents the top navigation and toolbar, with "Tab 2" as the title (there are two of them due to iOS [Collapsible Large Title](../api/title.md#collapsible-large-titles) support). Let’s rename both `IonTitle` elements to:
145
171
146
172
```tsx
147
173
<IonTitle>Photo Gallery</IonTitle>
148
174
```
149
175
150
-
We put the visual aspects of our app into `<IonContent>`. In this case, it’s where we’ll add a button that opens the device’s camera as well as displays the image captured by the camera. Start by adding a [floating action button](https://ionicframework.com/docs/api/fab) (FAB). First, update the imports at the top of the page to include the Camera icon as well as some of the Ionic components we'll use shortly:
176
+
We put the visual aspects of our app into `<IonContent>`. In this case, it’s where we’ll add a button that opens the device’s camera as well as displays the image captured by the camera. Start by adding a [floating action button](../api/fab.md) (FAB) to the bottom of the page and set the camera image as the icon.
151
177
152
178
```tsx
179
+
// CHANGE: Add the following import.
153
180
import { camera, trash, close } from'ionicons/icons';
181
+
// CHANGE: Update the following import.
154
182
import {
155
183
IonContent,
156
184
IonHeader,
@@ -166,39 +194,101 @@ import {
166
194
IonImg,
167
195
IonActionSheet,
168
196
} from'@ionic/react';
197
+
// CHANGE: Remove or comment out `ExploreContainer`.
198
+
// import ExploreContainer from '../components/ExploreContainer';
{/* CHANGE: Remove or comment out `ExploreContainer`. */}
223
+
{/* <ExploreContainer name="Tab 2 page" /> */}
224
+
</IonPage>
225
+
);
226
+
};
227
+
228
+
exportdefaultTab2;
169
229
```
170
230
171
-
Then, add the FAB to the bottom of the page. Use the camera image as the icon, and call the `takePhoto()` function when this button is clicked (to be implemented soon):
/* Ionic styles are not shown in this example to keep it brief but will be included in the Ionic package downloaded for your app. Do not remove them. */
253
+
254
+
const App:React.FC= () => (
255
+
<IonApp>
256
+
<IonReactRouter>
257
+
<IonTabs>
258
+
<IonRouterOutlet>
259
+
<Routeexactpath="/tab1">
260
+
<Tab1 />
261
+
</Route>
262
+
<Routeexactpath="/tab2">
263
+
<Tab2 />
264
+
</Route>
265
+
<Routepath="/tab3">
266
+
<Tab3 />
267
+
</Route>
268
+
<Routeexactpath="/">
269
+
<Redirectto="/tab1" />
270
+
</Route>
271
+
</IonRouterOutlet>
272
+
<IonTabBarslot="bottom">
273
+
<IonTabButtontab="tab1"href="/tab1">
274
+
<IonIconaria-hidden="true"icon={triangle} />
275
+
<IonLabel>Tab 1</IonLabel>
276
+
</IonTabButton>
277
+
<IonTabButtontab="tab2"href="/tab2">
278
+
{/* CHANGE: Update icon. */}
279
+
<IonIconaria-hidden="true"icon={images} />
280
+
{/* CHANGE: Update label. */}
281
+
<IonLabel>Photos</IonLabel>
282
+
</IonTabButton>
283
+
<IonTabButtontab="tab3"href="/tab3">
284
+
<IonIconaria-hidden="true"icon={square} />
285
+
<IonLabel>Tab 3</IonLabel>
286
+
</IonTabButton>
287
+
</IonTabBar>
288
+
</IonTabs>
289
+
</IonReactRouter>
290
+
</IonApp>
291
+
);
189
292
```
190
293
191
-
Within the tab bar (`<IonTabBar>`), change the label to “Photos” and the `ellipse` icon to `images` for the middle tab button:
192
-
193
-
```tsx
194
-
<IonTabButtontab="tab2"href="/tab2">
195
-
<IonIconicon={images} />
196
-
<IonLabel>Photos</IonLabel>
197
-
</IonTabButton>
198
-
```
199
-
200
-
:::note
201
-
In Ionic React, icons are imported individually from `ionicons/icons` and set to the icon prop.
202
-
:::
203
-
204
294
That’s just the start of all the cool things we can do with Ionic. Up next, implement camera taking functionality on the web, then build it for iOS and Android.
0 commit comments