src/app/core/pwa-install/pwa-install.component.ts

Implements

OnInit

Metadata

Relationships

Used by

Depends on

  • MatButtonModule
  • Angulartics2Module
  • FontAwesomeModule
  • OnInit

Index

Properties
Methods
Accessors

Methods

pwaInstallButtonClicked
pwaInstallButtonClicked()
Returns : void

Properties

_showPWAInstallButton
Type : unknown
Default value : false
snackBar
Type : unknown
Default value : inject(MatSnackBar)
templateIOSInstallInstructions
Type : TemplateRef<any>
Decorators :
@ViewChild('iOSInstallInstructions')

Accessors

showPWAInstallButton
setshowPWAInstallButton(value: boolean)
Parameters :
Name Type Optional
value boolean No
Returns : void
import {
  ChangeDetectionStrategy,
  ChangeDetectorRef,
  Component,
  OnInit,
  TemplateRef,
  ViewChild,
  inject,
} from "@angular/core";
import { MatSnackBar } from "@angular/material/snack-bar";
import { PwaInstallService, PWAInstallType } from "./pwa-install.service";
import { MatButtonModule } from "@angular/material/button";
import { Angulartics2Module } from "angulartics2";
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";

@Component({
  selector: "app-pwa-install",
  templateUrl: "./pwa-install.component.html",
  styleUrls: ["./pwa-install.component.scss"],
  imports: [MatButtonModule, Angulartics2Module, FontAwesomeModule],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PwaInstallComponent implements OnInit {
  snackBar = inject(MatSnackBar);
  private pwaInstallService = inject(PwaInstallService);
  private changeDetector = inject(ChangeDetectorRef);

  @ViewChild("iOSInstallInstructions")
  templateIOSInstallInstructions: TemplateRef<any>;

  set showPWAInstallButton(value: boolean) {
    this._showPWAInstallButton = value;
    this.changeDetector.detectChanges();
  }

  _showPWAInstallButton = false;

  private pwaInstallType: PWAInstallType;

  ngOnInit() {
    this.pwaInstallType = this.pwaInstallService.getPWAInstallType();
    if (this.pwaInstallType === PWAInstallType.ShowiOSInstallInstructions) {
      this.showPWAInstallButton = true;
    }
    this.pwaInstallService.canInstallDirectly?.then(() => {
      this.showPWAInstallButton = true;
    });
  }

  pwaInstallButtonClicked() {
    if (this.pwaInstallType === PWAInstallType.ShowiOSInstallInstructions) {
      this.snackBar.openFromTemplate(this.templateIOSInstallInstructions);
    } else {
      this.pwaInstallService.installPWA().then((choice) => {
        if (choice.outcome === "accepted") {
          this.showPWAInstallButton = false;
        }
      });
    }
  }
}
@if (_showPWAInstallButton) {
  <button
    mat-flat-button
    class="pwa-install-button"
    color="primary"
    angulartics2On="click"
    angularticsCategory="UserAction"
    angularticsAction="install_app"
    (click)="pwaInstallButtonClicked()"
  >
    <fa-icon
      icon="cloud-download-alt"
      class="standard-icon-with-text"
    ></fa-icon>
    <span i18n="PWA Install Button Label">Install App</span>
  </button>
}

<ng-template #iOSInstallInstructions>
  <ng-container i18n="PWA iOS Install Instructions - Line 1">
    To install the app
  </ng-container>
  <button
    mat-button
    style="position: absolute; right: -10px; top: 0"
    (click)="snackBar.dismiss()"
  >
    <fa-icon icon="window-close" class="nav-icon"></fa-icon>
  </button>
  <ol>
    <li>
      <ng-container i18n="PWA iOS Install Instructions - Line 2-1">
        tap on
      </ng-container>
      <fa-icon icon="arrow-up-from-bracket" class="nav-icon"></fa-icon>
      <ng-container i18n="PWA iOS Install Instructions - Line 2-2">
        at the bottom
      </ng-container>
    </li>
    <li>
      <ng-container i18n="PWA iOS Install Instructions - Line 3-1">
        and then tap on
      </ng-container>
      <fa-icon icon="plus-square" class="nav-icon"></fa-icon>
      <ng-container i18n="PWA iOS Install Instructions - Line 3-2">
        (Add to Homescreen).
      </ng-container>
    </li>
  </ol>
</ng-template>

./pwa-install.component.scss

@use "variables/colors";

.pwa-install-button {
  border-top: solid 1px rgba(0, 0, 0, 0.12);
  border-radius: 0;
  overflow: hidden;
  width: 100%;
  color: white;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""