Skip to content

docs(animation): add playground for chained animations #3026

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

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
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
208 changes: 2 additions & 206 deletions docs/utilities/animations.md
Original file line number Diff line number Diff line change
Expand Up @@ -640,213 +640,9 @@ See [Methods](#methods) for a complete list of hooks.

Animations can be chained to run one after the other. The `play` method returns a Promise that resolves when the animation has completed.

### Usage

````mdx-code-block
<Tabs
groupId="framework"
defaultValue="javascript"
values={[
{ value: 'javascript', label: 'JavaScript' },
{ value: 'angular', label: 'Angular' },
{ value: 'react', label: 'React' },
{ value: 'vue', label: 'Vue' },
]
}>
<TabItem value="javascript">

```javascript
const squareA = createAnimation()
.addElement(document.querySelector('.square-a'))
.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 squareB = createAnimation()
.addElement(document.querySelector('.square-b'))
.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' }
]);

const squareC = createAnimation()
.addElement(document.querySelector('.square-c'))
.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' }
]);

await squareA.play();
await squareB.play();
await squareC.play();
```
</TabItem>
<TabItem value="angular">

```javascript
const squareA = this.animationCtrl.create()
.addElement(this.squareA.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 squareB = this.animationCtrl.create()
.addElement(this.squareB.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' }
]);

const squareC = this.animationCtrl.create()
.addElement(this.squareC.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' }
]);

await squareA.play();
await squareB.play();
await squareC.play();
```
</TabItem>
<TabItem value="react">

```tsx
private squareARef: React.RefObject<CreateAnimation> = React.createRef();
private squareBRef: React.RefObject<CreateAnimation> = React.createRef();
private squareCRef: React.RefObject<CreateAnimation> = React.createRef();

...

async componentDidMount() {
const squareA = this.squareARef.current!.animation;
const squareB = this.squareBRef.current!.animation;
const squareC = this.squareCRef.current!.animation;

await squareA.play();
await squareB.play();
await squareC.play();
}

render() {
return (
<>
<CreateAnimation
ref={this.squareARef}
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(0deg)' }
]}
>
<div className="square"></div>
</CreateAnimation>

<CreateAnimation
ref={this.squareBRef}
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' }
]}
>
<div className="square"></div>
</CreateAnimation>

<CreateAnimation
ref={this.squareCRef}
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' }
]}
>
<div className="square"></div>
</CreateAnimation>
</>
)
}
```
</TabItem>
<TabItem value="vue">

```javascript
import { createAnimation } from '@ionic/vue';
import { ref } from 'vue';

...

const squareARef = ref();
const squareBRef = ref();
const squareCRef = ref();

...

const squareA = createAnimation()
.addElement(squareARef.value)
.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 squareB = createAnimation()
.addElement(squareBRef.value)
.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' }
]);

const squareC = createAnimation()
.addElement(squareCRef.value)
.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' }
]);

await squareA.play();
await squareB.play();
await squareC.play();
```
</TabItem>
</Tabs>
````
import Chain from '@site/static/usage/v7/animations/chain/index.md';

<Codepen user="ionic" slug="MWgGrwX" height="460" />
<Chain />

## Gesture Animations

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```html
<ion-card>
<ion-card-content>Card 1</ion-card-content>
</ion-card>

<ion-card>
<ion-card-content>Card 2</ion-card-content>
</ion-card>

<ion-card>
<ion-card-content>Card 3</ion-card-content>
</ion-card>

<ion-button id="play" (click)="play()">Play</ion-button>
<ion-button id="pause" (click)="pause()">Pause</ion-button>
<ion-button id="stop" (click)="stop()">Stop</ion-button>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
```ts
import { Component, ElementRef, ViewChildren } from '@angular/core';
import type { QueryList } from '@angular/core';
import type { Animation } from '@ionic/angular';
import { AnimationController, IonCard } from '@ionic/angular';

@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
})
export class ExampleComponent {
@ViewChildren(IonCard, { read: ElementRef }) cardElements: QueryList<ElementRef<HTMLIonCardElement>>;

private cardA: Animation;
private cardB: Animation;
private cardC: Animation;

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)' },
]);

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.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' },
]);
}

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

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

stop() {
this.cardA.stop();
this.cardB.stop();
this.cardC.stop();
}
}
```
Loading