Skip to content

Commit

Permalink
docs(animations): update angular to standalone (#3911)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandyscarney authored Dec 30, 2024
1 parent 5c0f307 commit 70ae31d
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 218 deletions.
13 changes: 7 additions & 6 deletions static/usage/v7/animations/basic/angular/example_component_ts.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
```ts
import { Component, ElementRef, ViewChildren, ViewChild } from '@angular/core';
import type { QueryList } from '@angular/core';
import type { Animation } from '@ionic/angular';
import { AnimationController, IonCard } from '@ionic/angular';
import { Component, ElementRef, ViewChild } from '@angular/core';
import { AnimationController, IonButton, IonCard, IonCardContent } from '@ionic/angular/standalone';
import type { Animation } from '@ionic/angular/standalone';

@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonButton, IonCard, IonCardContent],
})
export class ExampleComponent {
@ViewChild(IonCard, { read: ElementRef }) card: ElementRef<HTMLIonCardElement>;
@ViewChild(IonCard, { read: ElementRef }) card!: ElementRef<HTMLIonCardElement>;

private animation: Animation;
private animation!: Animation;

constructor(private animationCtrl: AnimationController) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
```ts
import { Component, ElementRef, ViewChildren } from '@angular/core';
import { AnimationController, IonButton, IonCard, IonCardContent } from '@ionic/angular/standalone';
import type { QueryList } from '@angular/core';
import type { Animation } from '@ionic/angular';
import { AnimationController, IonCard } from '@ionic/angular';
import type { Animation } from '@ionic/angular/standalone';

@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonButton, IonCard, IonCardContent],
})
export class ExampleComponent {
@ViewChildren(IonCard, { read: ElementRef }) cardElements: QueryList<ElementRef<HTMLIonCardElement>>;
@ViewChildren(IonCard, { read: ElementRef }) cardElements!: QueryList<ElementRef<HTMLIonCardElement>>;

private animation: Animation;
private animation!: Animation;

constructor(private animationCtrl: AnimationController) {}

ngAfterViewInit() {
const card = this.animationCtrl
.create()
.addElement(this.cardElements.get(0).nativeElement)
.duration(2000)
.beforeStyles({
filter: 'invert(75%)',
})
.beforeClearStyles(['box-shadow'])
.afterStyles({
'box-shadow': 'rgba(255, 0, 50, 0.4) 0px 4px 16px 6px',
})
.afterClearStyles(['filter'])
.keyframes([
{ offset: 0, transform: 'scale(1)' },
{ offset: 0.5, transform: 'scale(1.5)' },
{ offset: 1, transform: 'scale(1)' },
]);

this.animation = this.animationCtrl.create().duration(2000).addAnimation([card]);
const cardEl = this.cardElements.get(0);

const card = cardEl
? this.animationCtrl
.create()
.addElement(cardEl.nativeElement)
.duration(2000)
.beforeStyles({
filter: 'invert(75%)',
})
.beforeClearStyles(['box-shadow'])
.afterStyles({
'box-shadow': 'rgba(255, 0, 50, 0.4) 0px 4px 16px 6px',
})
.afterClearStyles(['filter'])
.keyframes([
{ offset: 0, transform: 'scale(1)' },
{ offset: 0.5, transform: 'scale(1.5)' },
{ offset: 1, transform: 'scale(1)' },
])
: null;

if (card) {
this.animation = this.animationCtrl.create().duration(2000).addAnimation([card]);
}
}

play() {
Expand Down
104 changes: 58 additions & 46 deletions static/usage/v7/animations/chain/angular/example_component_ts.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,85 @@
```ts
import { Component, ElementRef, ViewChildren } from '@angular/core';
import { AnimationController, IonButton, IonCard, IonCardContent } from '@ionic/angular/standalone';
import type { QueryList } from '@angular/core';
import type { Animation } from '@ionic/angular';
import { AnimationController, IonCard } from '@ionic/angular';
import type { Animation } from '@ionic/angular/standalone';

@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonButton, IonCard, IonCardContent],
})
export class ExampleComponent {
@ViewChildren(IonCard, { read: ElementRef }) cardElements: QueryList<ElementRef<HTMLIonCardElement>>;
@ViewChildren(IonCard, { read: ElementRef }) cardElements!: QueryList<ElementRef<HTMLIonCardElement>>;

private cardA: Animation;
private cardB: Animation;
private cardC: Animation;
private cardA!: Animation | null;
private cardB!: Animation | null;
private cardC!: Animation | null;

constructor(private animationCtrl: AnimationController) {}

ngAfterViewInit() {
this.cardA = this.animationCtrl
.create()
.addElement(this.cardElements.get(0).nativeElement)
.fill('none')
.duration(1000)
.keyframes([
{ offset: 0, transform: 'scale(1) rotate(0)' },
{ offset: 0.5, transform: 'scale(1.2) rotate(45deg)' },
{ offset: 1, transform: 'scale(1) rotate(0)' },
]);
const cardElA = this.cardElements.get(0);
const cardElB = this.cardElements.get(1);
const cardElC = this.cardElements.get(2);

this.cardB = this.animationCtrl
.create()
.addElement(this.cardElements.get(1).nativeElement)
.fill('none')
.duration(1000)
.keyframes([
{ offset: 0, transform: 'scale(1)', opacity: '1' },
{ offset: 0.5, transform: 'scale(1.2)', opacity: '0.3' },
{ offset: 1, transform: 'scale(1)', opacity: '1' },
]);
this.cardA = cardElA
? this.animationCtrl
.create()
.addElement(cardElA.nativeElement)
.fill('none')
.duration(1000)
.keyframes([
{ offset: 0, transform: 'scale(1) rotate(0)' },
{ offset: 0.5, transform: 'scale(1.2) rotate(45deg)' },
{ offset: 1, transform: 'scale(1) rotate(0)' },
])
: null;

this.cardC = this.animationCtrl
.create()
.addElement(this.cardElements.get(2).nativeElement)
.fill('none')
.duration(1000)
.keyframes([
{ offset: 0, transform: 'scale(1)', opacity: '0.5' },
{ offset: 0.5, transform: 'scale(0.8)', opacity: '1' },
{ offset: 1, transform: 'scale(1)', opacity: '0.5' },
]);
this.cardB = cardElB
? this.animationCtrl
.create()
.addElement(cardElB.nativeElement)
.fill('none')
.duration(1000)
.keyframes([
{ offset: 0, transform: 'scale(1)', opacity: '1' },
{ offset: 0.5, transform: 'scale(1.2)', opacity: '0.3' },
{ offset: 1, transform: 'scale(1)', opacity: '1' },
])
: null;

this.cardC = cardElC
? this.animationCtrl
.create()
.addElement(cardElC.nativeElement)
.fill('none')
.duration(1000)
.keyframes([
{ offset: 0, transform: 'scale(1)', opacity: '0.5' },
{ offset: 0.5, transform: 'scale(0.8)', opacity: '1' },
{ offset: 1, transform: 'scale(1)', opacity: '0.5' },
])
: null;
}

async play() {
await this.cardA.play();
await this.cardB.play();
await this.cardC.play();
await this.cardA?.play();
await this.cardB?.play();
await this.cardC?.play();
}

pause() {
this.cardA.pause();
this.cardB.pause();
this.cardC.pause();
this.cardA?.pause();
this.cardB?.pause();
this.cardC?.pause();
}

stop() {
this.cardA.stop();
this.cardB.stop();
this.cardC.stop();
async stop() {
await this.cardA?.stop();
await this.cardB?.stop();
await this.cardC?.stop();
}
}
```
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
```ts
import { Component, ElementRef, ViewChildren, ViewChild } from '@angular/core';
import { AnimationController, GestureController, IonCard } from '@ionic/angular';
import type { Animation, Gesture, GestureDetail } from '@ionic/angular';
import { Component, ElementRef, ViewChild } from '@angular/core';
import { AnimationController, GestureController, IonCard, IonCardContent } from '@ionic/angular/standalone';
import type { Animation, Gesture, GestureDetail } from '@ionic/angular/standalone';

@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonCard, IonCardContent],
})
export class ExampleComponent {
@ViewChild(IonCard, { read: ElementRef }) card: ElementRef<HTMLIonCardElement>;
@ViewChild(IonCard, { read: ElementRef }) card!: ElementRef<HTMLIonCardElement>;

private animation: Animation;
private gesture: Gesture;
private animation!: Animation;
private gesture!: Gesture;
private started = false;
private initialStep = 0;

Expand Down
20 changes: 11 additions & 9 deletions static/usage/v7/animations/group/angular/example_component_ts.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
```ts
import { Component, ElementRef, ViewChildren } from '@angular/core';
import { AnimationController, IonButton, IonCard, IonCardContent } from '@ionic/angular/standalone';
import type { QueryList } from '@angular/core';
import type { Animation } from '@ionic/angular';
import { AnimationController, IonCard } from '@ionic/angular';
import type { Animation } from '@ionic/angular/standalone';

@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonButton, IonCard, IonCardContent],
})
export class ExampleComponent {
@ViewChildren(IonCard, { read: ElementRef }) cardElements: QueryList<ElementRef<HTMLIonCardElement>>;
@ViewChildren(IonCard, { read: ElementRef }) cardElements!: QueryList<ElementRef<HTMLIonCardElement>>;

private animation: Animation;
private animation!: Animation;

constructor(private animationCtrl: AnimationController) {}

ngAfterViewInit() {
const cardA = this.animationCtrl
.create()
.addElement(this.cardElements.get(0).nativeElement)
.addElement(this.cardElements.get(0)!.nativeElement)
.keyframes([
{ offset: 0, transform: 'scale(1) rotate(0)' },
{ offset: 0.5, transform: 'scale(1.5) rotate(45deg)' },
{ offset: 1, transform: 'scale(1) rotate(0) ' },
{ offset: 1, transform: 'scale(1) rotate(0)' },
]);

const cardB = this.animationCtrl
.create()
.addElement(this.cardElements.get(1).nativeElement)
.addElement(this.cardElements.get(1)!.nativeElement)
.keyframes([
{ offset: 0, transform: 'scale(1)', opacity: '1' },
{ offset: 0.5, transform: 'scale(1.5)', opacity: '0.3' },
Expand All @@ -36,7 +38,7 @@ export class ExampleComponent {

const cardC = this.animationCtrl
.create()
.addElement(this.cardElements.get(2).nativeElement)
.addElement(this.cardElements.get(2)!.nativeElement)
.duration(5000)
.keyframes([
{ offset: 0, transform: 'scale(1)', opacity: '0.5' },
Expand All @@ -48,7 +50,7 @@ export class ExampleComponent {
.create()
.duration(2000)
.iterations(Infinity)
.addAnimation([cardA, cardB, cardC]);
.addAnimation([cardA, cardB, cardC].filter(Boolean) as Animation[]);
}

play() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
```ts
import { Component, ElementRef, ViewChild } from '@angular/core';
import type { Animation } from '@ionic/angular';
import { AnimationController, IonCard, IonCardContent } from '@ionic/angular';
import { AnimationController, IonButton, IonCard, IonCardContent } from '@ionic/angular/standalone';
import type { Animation } from '@ionic/angular/standalone';

@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonButton, IonCard, IonCardContent],
})
export class ExampleComponent {
@ViewChild(IonCard, { read: ElementRef }) card: ElementRef<HTMLIonCardElement>;
@ViewChild(IonCard, { read: ElementRef }) card!: ElementRef<HTMLIonCardElement>;

private animation: Animation;
private animation!: Animation;

constructor(private animationCtrl: AnimationController) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
```ts
import { Component, ViewChild } from '@angular/core';
import type { IonModal } from '@ionic/angular';
import { AnimationController } from '@ionic/angular';
import {
AnimationController,
IonButton,
IonButtons,
IonContent,
IonHeader,
IonModal,
IonTitle,
IonToolbar,
} from '@ionic/angular/standalone';

@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonButton, IonButtons, IonContent, IonHeader, IonModal, IonTitle, IonToolbar],
})
export class ExampleComponent {
@ViewChild('modal', { static: true }) modal: IonModal;
@ViewChild('modal', { static: true }) modal!: IonModal;

constructor(private animationCtrl: AnimationController) {}

ngOnInit() {
const enterAnimation = (baseEl: HTMLElement) => {
const root = baseEl.shadowRoot;

const backdropElement = root?.querySelector('ion-backdrop');
const wrapperElement = root?.querySelector('.modal-wrapper');

const backdropAnimation = this.animationCtrl
.create()
.addElement(root.querySelector('ion-backdrop'))
.addElement(backdropElement || baseEl)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');

const wrapperAnimation = this.animationCtrl
.create()
.addElement(root.querySelector('.modal-wrapper'))
.keyframes([
const wrapperAnimation = this.animationCtrl.create();

if (wrapperElement) {
wrapperAnimation.addElement(wrapperElement).keyframes([
{ offset: 0, opacity: '0', transform: 'scale(0)' },
{ offset: 1, opacity: '0.99', transform: 'scale(1)' },
]);
}

return this.animationCtrl
.create()
Expand Down
Loading

0 comments on commit 70ae31d

Please sign in to comment.