Skip to content

Commit ab9b18b

Browse files
committed
14.8 native camera integration
1 parent d36bd87 commit ab9b18b

File tree

10 files changed

+101
-2
lines changed

10 files changed

+101
-2
lines changed

package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
"@angular/platform-browser-dynamic": "^16.0.0",
2323
"@angular/router": "^16.0.0",
2424
"@capacitor/android": "^5.0.2",
25+
"@capacitor/camera": "^5.0.2",
2526
"@capacitor/core": "5.0.2",
27+
"@capacitor/splash-screen": "^5.0.2",
2628
"@ionic/angular": "^7.0.0",
29+
"@ionic/pwa-elements": "^3.1.1",
2730
"ionicons": "^7.0.0",
2831
"rxjs": "~7.8.0",
2932
"tslib": "^2.3.0",

src/app/app.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@ import { Component } from '@angular/core';
22
import { AuthService } from './auth/auth.service';
33
import { Router } from '@angular/router';
44

5+
import { SplashScreen } from '@capacitor/splash-screen';
6+
import { Platform } from '@ionic/angular'
7+
58
@Component({
69
selector: 'app-root',
710
templateUrl: 'app.component.html',
811
styleUrls: ['app.component.scss'],
912
})
1013
export class AppComponent {
11-
constructor(private auth: AuthService, private router: Router) {}
14+
constructor(private auth: AuthService, private router: Router, private platform: Platform) {
15+
this.initializeApp()
16+
}
17+
18+
initializeApp () {
19+
this.platform.ready().then(async () => {
20+
await SplashScreen.hide();
21+
})
22+
}
1223
onLogout(){
1324
this.auth.logout();
1425
this.router.navigateByUrl('/auth');

src/app/places/offers/new-offer/new-offer.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { IonicModule } from '@ionic/angular';
66
import { NewOfferPageRoutingModule } from './new-offer-routing.module';
77

88
import { NewOfferPage } from './new-offer.page';
9+
import { ImagePickerComponent } from 'src/app/shared/pickers/image-picker/image-picker.component';
910

1011
@NgModule({
1112
imports: [
@@ -14,6 +15,6 @@ import { NewOfferPage } from './new-offer.page';
1415
IonicModule,
1516
NewOfferPageRoutingModule
1617
],
17-
declarations: [NewOfferPage]
18+
declarations: [NewOfferPage, ImagePickerComponent]
1819
})
1920
export class NewOfferPageModule {}

src/app/places/offers/new-offer/new-offer.page.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070
</ion-item>
7171
</ion-col>
7272
</ion-row>
73+
<ion-row>
74+
<ion-col size-sm="3" offset-sm="3">
75+
<app-image-picker (imagePick)="onImagePicked($event)"></app-image-picker>
76+
</ion-col>
77+
</ion-row>
7378
</ion-grid>
7479
</form>
7580
</ion-content>

src/app/places/offers/new-offer/new-offer.page.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,9 @@ export class NewOfferPage implements OnInit {
6868
});
6969
});
7070
}
71+
72+
73+
onImagePicked(imgData) {
74+
75+
}
7176
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="picker">
2+
<ion-img
3+
role="button"
4+
class="image"
5+
(click)="onPickImage()"
6+
[src]="selectedImage"
7+
*ngIf="selectedImage"></ion-img>
8+
<ion-button color="primary" (click)="onPickImage()" *ngIf="!selectedImage">
9+
<ion-icon name="camera" slot="start"></ion-icon>
10+
<ion-label>Take picture</ion-label>
11+
</ion-button>
12+
</div>

src/app/shared/pickers/image-picker/image-picker.component.scss

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
2+
import { Camera, CameraResultType } from '@capacitor/camera';
3+
4+
@Component({
5+
selector: 'app-image-picker',
6+
templateUrl: './image-picker.component.html',
7+
styleUrls: ['./image-picker.component.scss'],
8+
})
9+
export class ImagePickerComponent implements OnInit {
10+
@Output() imagePick = new EventEmitter<string>();
11+
12+
selectedImage: string;
13+
14+
constructor() {}
15+
16+
ngOnInit() {}
17+
18+
onPickImage() {
19+
Camera.getPhoto({
20+
quality: 90,
21+
allowEditing: true,
22+
height: 320,
23+
width: 200,
24+
resultType: CameraResultType.Uri,
25+
})
26+
.then((image) => {
27+
this.selectedImage = image.webPath;
28+
this.imagePick.emit(image.webPath);
29+
})
30+
.catch((err) => {
31+
console.log(err);
32+
return false;
33+
});
34+
}
35+
}

src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
33

44
import { AppModule } from './app/app.module';
55
import { environment } from './environments/environment';
6+
import { defineCustomElements } from '@ionic/pwa-elements/loader';
67

78
if (environment.production) {
89
enableProdMode();
910
}
1011

1112
platformBrowserDynamic().bootstrapModule(AppModule)
1213
.catch(err => console.log(err));
14+
15+
defineCustomElements(window);

0 commit comments

Comments
 (0)