Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(custom-camera): back button behaves as expected on Android #2092

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/app/features/home/custom-camera/custom-camera.page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable no-console */
import { Location } from '@angular/common';
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Capacitor, PluginListenerHandle } from '@capacitor/core';
import { NavController, Platform } from '@ionic/angular';
import { UntilDestroy } from '@ngneat/until-destroy';
import { CaptureResult, PreviewCamera } from '@numbersprotocol/preview-camera';
import { BehaviorSubject } from 'rxjs';
import { BehaviorSubject, Subscription } from 'rxjs';
import { ErrorService } from '../../../shared/error/error.service';
import { UserGuideService } from '../../../shared/user-guide/user-guide.service';
import { GoProBluetoothService } from '../../settings/go-pro/services/go-pro-bluetooth.service';
Expand Down Expand Up @@ -48,6 +49,8 @@ export class CustomCameraPage implements OnInit, OnDestroy {
maxZoomFactor = 0;
curZoomFactor = 0;

private backButtonPrioritySubscription?: Subscription;

get canZoomInOut() {
return this.minZoomFactor < this.maxZoomFactor;
}
Expand All @@ -62,7 +65,8 @@ export class CustomCameraPage implements OnInit, OnDestroy {
private readonly goProBluetoothService: GoProBluetoothService,
private readonly errorService: ErrorService,
private readonly userGuideService: UserGuideService,
private readonly ref: ChangeDetectorRef
private readonly platform: Platform,
private readonly navCtrl: NavController
) {}

ngOnInit() {
Expand All @@ -86,6 +90,19 @@ export class CustomCameraPage implements OnInit, OnDestroy {
async ionViewDidEnter() {
await this.userGuideService.showUserGuidesOnCustomCameraPage();
await this.userGuideService.setHasOpenedCustomCameraPage(true);

this.backButtonPrioritySubscription =
this.platform.backButton.subscribeWithPriority(1, () => {
if (this.mode$.value === 'pre-publish') {
this.discardCurrentCapture();
} else {
this.navCtrl.back();
}
});
}

ionViewWillLeave() {
this.backButtonPrioritySubscription?.unsubscribe();
}

ngOnDestroy(): void {
Expand Down Expand Up @@ -179,9 +196,11 @@ export class CustomCameraPage implements OnInit, OnDestroy {
}

discardCurrentCapture() {
this.mode$.next('capture');
this.startPreviewCamera();
this.removeCurrentCapture();
if (this.mode$.value === 'pre-publish') {
this.mode$.next('capture');
this.startPreviewCamera();
this.removeCurrentCapture();
}
}

async confirmCurrentCapture() {
Expand Down