Skip to content

Commit 8d649af

Browse files
docs: align tutorial, quickstart, and testing pages with the updated starters (#4805)
* docs: align tutorial, quickstart, and testing pages with the updated starters * docs: fix review findings in tutorial, quickstart, and testing pages * docs: register the tabs icon in Angular and key Vue photos by file path * docs: explain the Camera.getPhoto options in the Your First App tutorials * docs: pass native photo data straight to the filesystem in React and Vue * docs(vue): remove the e2e type check when converting to JavaScript --------- Co-authored-by: Brandy Smith <6577830+brandyscarney@users.noreply.github.com>
1 parent dbdc35b commit 8d649af

28 files changed

Lines changed: 591 additions & 302 deletions

‎docs/angular/quickstart.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ This sets up the root of your application, using Ionic's `ion-app` and `ion-rout
112112
Routes are defined in `app.routes.ts`:
113113

114114
```ts title="src/app/app.routes.ts"
115-
import { Routes } from '@angular/router';
115+
import type { Routes } from '@angular/router';
116116

117117
export const routes: Routes = [
118118
{
@@ -382,7 +382,7 @@ export class NewPage implements OnInit {
382382

383383
ngOnInit() {}
384384

385-
scrollToBottom = () => {
385+
scrollToBottom = (): void => {
386386
this.content.scrollToBottom(300);
387387
};
388388
}

‎docs/angular/your-first-app.mdx‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ import { IonicRouteStrategy, provideIonicAngular } from '@ionic/angular';
115115
// CHANGE: Add the following import
116116
import { defineCustomElements } from '@ionic/pwa-elements/loader';
117117

118-
import { routes } from './app/app.routes';
119118
import { AppComponent } from './app/app.component';
119+
import { routes } from './app/app.routes';
120120

121121
// CHANGE: Call the element loader before the `bootstrapApplication` call
122122
defineCustomElements(window);
@@ -195,11 +195,11 @@ We put the visual aspects of our app into `<ion-content>`. In this case, it’s
195195
```html
196196
<ion-header [translucent]="true">
197197
<ion-toolbar>
198-
<ion-title>Photo Gallery</ion-title>
198+
<ion-title> Photo Gallery </ion-title>
199199
</ion-toolbar>
200200
</ion-header>
201201

202-
<ion-content>
202+
<ion-content [fullscreen]="true">
203203
<ion-header collapse="condense">
204204
<ion-toolbar>
205205
<ion-title size="large">Photo Gallery</ion-title>
@@ -243,4 +243,29 @@ Next, open `src/app/tabs/tabs.page.html`. Change the label to "Photos" and the `
243243
</ion-tabs>
244244
```
245245

246+
Then open `src/app/tabs/tabs.page.ts` and register the `images` icon in place of `ellipse`, so the new icon can display:
247+
248+
```ts
249+
import { Component, EnvironmentInjector, inject } from '@angular/core';
250+
import { IonTabs, IonTabBar, IonTabButton, IonIcon, IonLabel } from '@ionic/angular';
251+
import { addIcons } from 'ionicons';
252+
// CHANGE: Update import
253+
import { triangle, images, square } from 'ionicons/icons';
254+
255+
@Component({
256+
selector: 'app-tabs',
257+
templateUrl: 'tabs.page.html',
258+
styleUrls: ['tabs.page.scss'],
259+
imports: [IonTabs, IonTabBar, IonTabButton, IonIcon, IonLabel],
260+
})
261+
export class TabsPage {
262+
public environmentInjector = inject(EnvironmentInjector);
263+
264+
constructor() {
265+
// CHANGE: Register the `images` icon instead of `ellipse`
266+
addIcons({ triangle, images, square });
267+
}
268+
}
269+
```
270+
246271
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.

‎docs/angular/your-first-app/2-taking-photos.mdx‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
4545
})
4646
export class PhotoService {
4747
// CHANGE: Add the gallery method
48-
public async addNewToGallery() {
48+
public async addNewToGallery(): Promise<void> {
4949
// Take a photo
5050
const capturedPhoto = await Camera.getPhoto({
51-
resultType: CameraResultType.Uri,
52-
source: CameraSource.Camera,
53-
quality: 100,
51+
resultType: CameraResultType.Uri, // file-based data; provides best performance
52+
source: CameraSource.Camera, // automatically take a new photo with the camera
53+
quality: 100, // highest quality (0 to 100)
5454
});
5555
}
5656
}
@@ -78,6 +78,7 @@ import {
7878
// CHANGE: Register the camera icon used by the FAB
7979
import { addIcons } from 'ionicons';
8080
import { camera } from 'ionicons/icons';
81+
8182
// CHANGE: Import the PhotoService
8283
import { PhotoService } from '../services/photo.service';
8384

@@ -98,7 +99,7 @@ export class Tab2Page {
9899
}
99100

100101
// CHANGE: Add `addPhotoToGallery()` method
101-
addPhotoToGallery() {
102+
addPhotoToGallery(): void {
102103
this.photoService.addNewToGallery();
103104
}
104105
}
@@ -166,7 +167,7 @@ export class PhotoService {
166167
// CHANGE: Add the `photos` signal
167168
public photos = signal<UserPhoto[]>([]);
168169

169-
public async addNewToGallery() {
170+
public async addNewToGallery(): Promise<void> {
170171
// ...existing code...
171172
}
172173
}
@@ -176,12 +177,12 @@ Over in the `addNewToGallery` method, add the newly captured photo to the beginn
176177

177178
```ts
178179
// CHANGE: Update `addNewToGallery()` method
179-
public async addNewToGallery() {
180+
public async addNewToGallery(): Promise<void> {
180181
// Take a photo
181182
const capturedPhoto = await Camera.getPhoto({
182-
resultType: CameraResultType.Uri,
183-
source: CameraSource.Camera,
184-
quality: 100
183+
resultType: CameraResultType.Uri, // file-based data; provides best performance
184+
source: CameraSource.Camera, // automatically take a new photo with the camera
185+
quality: 100, // highest quality (0 to 100)
185186
});
186187

187188
// CHANGE: Add the new photo to the front of the photos signal
@@ -207,12 +208,12 @@ import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
207208
export class PhotoService {
208209
public photos = signal<UserPhoto[]>([]);
209210
210-
public async addNewToGallery() {
211+
public async addNewToGallery(): Promise<void> {
211212
// Take a photo
212213
const capturedPhoto = await Camera.getPhoto({
213-
resultType: CameraResultType.Uri,
214-
source: CameraSource.Camera,
215-
quality: 100,
214+
resultType: CameraResultType.Uri, // file-based data; provides best performance
215+
source: CameraSource.Camera, // automatically take a new photo with the camera
216+
quality: 100, // highest quality (0 to 100)
216217
});
217218
218219
this.photos.update((photos) => [

‎docs/angular/your-first-app/3-saving-photos.mdx‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ We can use this new method immediately in `addNewToGallery()`.
4747

4848
```ts
4949
import { Injectable, signal } from '@angular/core';
50-
import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera';
50+
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
51+
import type { Photo } from '@capacitor/camera';
5152

5253
@Injectable({
5354
providedIn: 'root',
@@ -56,12 +57,12 @@ export class PhotoService {
5657
public photos = signal<UserPhoto[]>([]);
5758

5859
// CHANGE: Update the `addNewToGallery()` method
59-
public async addNewToGallery() {
60+
public async addNewToGallery(): Promise<void> {
6061
// Take a photo
6162
const capturedPhoto = await Camera.getPhoto({
62-
resultType: CameraResultType.Uri,
63-
source: CameraSource.Camera,
64-
quality: 100,
63+
resultType: CameraResultType.Uri, // file-based data; provides best performance
64+
source: CameraSource.Camera, // automatically take a new photo with the camera
65+
quality: 100, // highest quality (0 to 100)
6566
});
6667

6768
// CHANGE: Add `savedImageFile`
@@ -93,7 +94,7 @@ Then, pass the data to the Filesystem's `writeFile` method. Recall that we displ
9394
Create a new helper method, `base64FromPath()`, to implement the necessary logic for running on the web:
9495

9596
```ts
96-
import { Injectable } from '@angular/core';
97+
import { Injectable, signal } from '@angular/core';
9798
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
9899
import type { Photo } from '@capacitor/camera';
99100
// CHANGE: Add import
@@ -164,12 +165,12 @@ import { Filesystem, Directory } from '@capacitor/filesystem';
164165
export class PhotoService {
165166
public photos = signal<UserPhoto[]>([]);
166167

167-
public async addNewToGallery() {
168+
public async addNewToGallery(): Promise<void> {
168169
// Take a photo
169170
const capturedPhoto = await Camera.getPhoto({
170-
resultType: CameraResultType.Uri,
171-
source: CameraSource.Camera,
172-
quality: 100,
171+
resultType: CameraResultType.Uri, // file-based data; provides best performance
172+
source: CameraSource.Camera, // automatically take a new photo with the camera
173+
quality: 100, // highest quality (0 to 100)
173174
});
174175

175176
// Save the picture and add it to photo collection

‎docs/angular/your-first-app/4-loading-photos.mdx‎

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class PhotoService {
3333
Next, at the end of the `addNewToGallery()` method, add a call to `Preferences.set()` to save the `photos` array. By adding it here, the `photos` array is stored each time a new photo is taken. This way, it doesn’t matter when the app user closes or switches to a different app - all photo data is saved.
3434

3535
```ts
36-
import { Injectable } from '@angular/core';
36+
import { Injectable, signal } from '@angular/core';
3737
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
3838
import type { Photo } from '@capacitor/camera';
3939
import { Filesystem, Directory } from '@capacitor/filesystem';
@@ -47,12 +47,12 @@ export class PhotoService {
4747
// ...existing code...
4848

4949
// CHANGE: Update `addNewToGallery()` method
50-
public async addNewToGallery() {
50+
public async addNewToGallery(): Promise<void> {
5151
// Take a photo
5252
const capturedPhoto = await Camera.getPhoto({
53-
resultType: CameraResultType.Uri,
54-
source: CameraSource.Camera,
55-
quality: 100,
53+
resultType: CameraResultType.Uri, // file-based data; provides best performance
54+
source: CameraSource.Camera, // automatically take a new photo with the camera
55+
quality: 100, // highest quality (0 to 100)
5656
});
5757

5858
const savedImageFile = await this.savePicture(capturedPhoto);
@@ -82,7 +82,7 @@ export class PhotoService {
8282
// ...existing code...
8383

8484
// CHANGE: Add the method to load the photo data
85-
public async loadSaved() {
85+
public async loadSaved(): Promise<void> {
8686
// Retrieve cached photo array data
8787
const { value: photoList } = await Preferences.get({ key: this.PHOTO_STORAGE });
8888
this.photos.set((photoList ? JSON.parse(photoList) : []) as UserPhoto[]);
@@ -97,21 +97,21 @@ export class PhotoService {
9797
// ...existing code...
9898

9999
// CHANGE: Update the `loadSaved()` method
100-
public async loadSaved() {
100+
public async loadSaved(): Promise<void> {
101101
// Retrieve cached photo array data
102102
const { value: photoList } = await Preferences.get({ key: this.PHOTO_STORAGE });
103103
const photos = (photoList ? JSON.parse(photoList) : []) as UserPhoto[];
104104

105105
// CHANGE: Display the photo by reading into base64 format
106106
for (const photo of photos) {
107107
// Read each saved photo's data from the Filesystem
108-
const file = await Filesystem.readFile({
108+
const readFile = await Filesystem.readFile({
109109
path: photo.filepath,
110110
directory: Directory.Data,
111111
});
112112

113113
// Web platform only: Load the photo as base64 data
114-
photo.webviewPath = `data:image/jpeg;base64,${file.data}`;
114+
photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`;
115115
}
116116

117117
// CHANGE: Set the signal so the gallery view updates
@@ -137,12 +137,12 @@ export class PhotoService {
137137

138138
private PHOTO_STORAGE: string = 'photos';
139139

140-
public async addNewToGallery() {
140+
public async addNewToGallery(): Promise<void> {
141141
// Take a photo
142142
const capturedPhoto = await Camera.getPhoto({
143-
resultType: CameraResultType.Uri,
144-
source: CameraSource.Camera,
145-
quality: 100,
143+
resultType: CameraResultType.Uri, // file-based data; provides best performance
144+
source: CameraSource.Camera, // automatically take a new photo with the camera
145+
quality: 100, // highest quality (0 to 100)
146146
});
147147

148148
// Save the picture and add it to photo collection
@@ -192,20 +192,20 @@ export class PhotoService {
192192
});
193193
}
194194

195-
public async loadSaved() {
195+
public async loadSaved(): Promise<void> {
196196
// Retrieve cached photo array data
197197
const { value: photoList } = await Preferences.get({ key: this.PHOTO_STORAGE });
198198
const photos = (photoList ? JSON.parse(photoList) : []) as UserPhoto[];
199199

200200
for (const photo of photos) {
201201
// Read each saved photo's data from the Filesystem
202-
const file = await Filesystem.readFile({
202+
const readFile = await Filesystem.readFile({
203203
path: photo.filepath,
204204
directory: Directory.Data,
205205
});
206206

207207
// Web platform only: Load the photo as base64 data
208-
photo.webviewPath = `data:image/jpeg;base64,${file.data}`;
208+
photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`;
209209
}
210210

211211
this.photos.set(photos);
@@ -223,7 +223,8 @@ Our `PhotoService` can now load the saved images, but we'll need to update `tab2
223223
Update `tab2.page.ts` to look like the following:
224224

225225
```ts
226-
import { Component, OnInit, inject } from '@angular/core';
226+
import type { OnInit } from '@angular/core';
227+
import { Component, inject } from '@angular/core';
227228
import {
228229
IonHeader,
229230
IonToolbar,
@@ -238,6 +239,7 @@ import {
238239
} from '@ionic/angular';
239240
import { addIcons } from 'ionicons';
240241
import { camera } from 'ionicons/icons';
242+
241243
import { PhotoService } from '../services/photo.service';
242244

243245
@Component({
@@ -254,11 +256,11 @@ export class Tab2Page implements OnInit {
254256
}
255257

256258
// CHANGE: Add call to `loadSaved()` when navigating to the Photos tab
257-
async ngOnInit() {
259+
async ngOnInit(): Promise<void> {
258260
await this.photoService.loadSaved();
259261
}
260262

261-
addPhotoToGallery() {
263+
addPhotoToGallery(): void {
262264
this.photoService.addNewToGallery();
263265
}
264266
}

0 commit comments

Comments
 (0)