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,10 +4,10 @@ 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
@@ -30,11 +30,11 @@ We'll create a Photo Gallery app that offers the ability to take photos with you
30
30
31
31
Highlights include:
32
32
33
-
- One React-based codebase that runs on the web, iOS, and Android using Ionic Framework [UI components](https://ionicframework.com/docs/components).
33
+
- One React-based codebase that runs on the web, iOS, and Android using Ionic Framework [UI components](../components.md).
34
34
- 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.
35
+
- Photo Gallery functionality powered by the Capacitor [Camera](../native/camera.md), [Filesystem](../native/filesystem.md), and [Preferences](../native/preferences.md) APIs.
36
36
37
-
Find the complete app code referenced in this guide [on GitHub](https://github.com/ionic-team/photo-gallery-capacitor-react).
37
+
Find the [complete app code](https://github.com/ionic-team/tutorial-photo-gallery-react) referenced in this guide on GitHub.
38
38
39
39
## Download Required Tools
40
40
@@ -43,9 +43,8 @@ Download and install these right away to ensure an optimal Ionic development exp
43
43
-**Node.js** for interacting with the Ionic ecosystem. [Download the LTS version here](https://nodejs.org/en/).
44
44
-**A code editor** for... writing code! We are fans of [Visual Studio Code](https://code.visualstudio.com/).
45
45
-**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.
46
+
-**Windows** users: for the best Ionic experience, we recommend the built-in command line (cmd) or the Powershell CLI, running in Administrator mode.
47
+
-**Mac/Linux** users: virtually any terminal will work.
49
48
50
49
## Install Ionic Tooling
51
50
@@ -67,10 +66,10 @@ Consider setting up npm to operate globally without elevated permissions. See [R
67
66
68
67
## Create an App
69
68
70
-
Next, create an Ionic React app that uses the “Tabs” starter template and adds Capacitor for native functionality:
69
+
Next, create an Ionic React app that uses the "Tabs" starter template and adds Capacitor for native functionality:
This starter project comes complete with three pre-built pages and best practices for Ionic development. With common building blocks already in place, we can add more features easily!
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).
91
+
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
92
94
93
It's a separate dependency, so install it next:
95
94
96
95
```shell
97
96
npm install @ionic/pwa-elements
98
97
```
99
98
100
-
After installation, open up the project in your code editor of choice.
101
-
102
99
Next, import `@ionic/pwa-elements` by editing `src/main.tsx`.
//CHANGE: Call the element loader before the render call
108
109
defineCustomElements(window);
110
+
111
+
const container =document.getElementById('root');
112
+
const root =createRoot(container!);
113
+
root.render(
114
+
<React.StrictMode>
115
+
<App />
116
+
</React.StrictMode>
117
+
);
109
118
```
110
119
111
120
That’s it! Now for the fun part - let’s see the app in action.
112
121
113
122
## Run the App
114
123
115
-
Run this command in your shell:
124
+
Run this command next:
116
125
117
126
```shell
118
127
ionic serve
119
128
```
120
129
121
130
And voilà! Your Ionic app is now running in a web browser. Most of your app can be built and tested right in the browser, greatly increasing development and testing speed.
122
131
123
-
## Photo Gallery!!!
132
+
## Photo Gallery
124
133
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!
134
+
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
135
127
136

`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:
169
+
131
170
```tsx
132
171
<IonPage>
133
172
<IonHeader>
134
173
<IonToolbar>
135
-
<IonTitle>Tab 2</IonTitle>
174
+
{/* CHANGE: Update title */}
175
+
<IonTitle>Photo Gallery</IonTitle>
136
176
</IonToolbar>
137
177
</IonHeader>
138
178
<IonContent>
139
-
<!-- some filler -->
179
+
<IonHeadercollapse="condense">
180
+
<IonToolbar>
181
+
{/* CHANGE: Update title */}
182
+
<IonTitlesize="large">Photo Gallery</IonTitle>
183
+
</IonToolbar>
184
+
</IonHeader>
185
+
186
+
{/* ...existing code... */}
140
187
</IonContent>
141
188
</IonPage>
142
189
```
143
190
144
-
`IonHeader` represents the top navigation and toolbar, with "Tab 2" as the title. Let’s rename it:
191
+
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.
{/* CHANGE: Remove or comment out `ExploreContainer` */}
225
+
{/* <ExploreContainer name="Tab 2 page" /> */}
226
+
</IonContent>
227
+
</IonPage>
228
+
);
229
+
};
230
+
231
+
exportdefaultTab2;
148
232
```
149
233
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:
234
+
Next, open `src/App.tsx`. Change the label to "Photos" and the `ellipse`icon to `images` for the middle tab button.
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):
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
299
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