diff --git a/docs/utilities/animations.md b/docs/utilities/animations.md index d53bfbca0e5..8527237f474 100644 --- a/docs/utilities/animations.md +++ b/docs/utilities/animations.md @@ -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 - - - -```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(); -``` - - - -```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(); -``` - - - -```tsx -private squareARef: React.RefObject = React.createRef(); -private squareBRef: React.RefObject = React.createRef(); -private squareCRef: React.RefObject = 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 ( - <> - -
-
- - -
-
- - -
-
- - ) -} -``` -
- - -```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(); -``` - -
-```` +import Chain from '@site/static/usage/v7/animations/chain/index.md'; - + ## Gesture Animations diff --git a/static/usage/v7/animations/chain/angular/example_component_html.md b/static/usage/v7/animations/chain/angular/example_component_html.md new file mode 100644 index 00000000000..bb61611b10c --- /dev/null +++ b/static/usage/v7/animations/chain/angular/example_component_html.md @@ -0,0 +1,17 @@ +```html + + Card 1 + + + + Card 2 + + + + Card 3 + + +Play +Pause +Stop +``` diff --git a/static/usage/v7/animations/chain/angular/example_component_ts.md b/static/usage/v7/animations/chain/angular/example_component_ts.md new file mode 100644 index 00000000000..6c6acbef993 --- /dev/null +++ b/static/usage/v7/animations/chain/angular/example_component_ts.md @@ -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>; + + 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(); + } +} +``` diff --git a/static/usage/v7/animations/chain/demo.html b/static/usage/v7/animations/chain/demo.html new file mode 100644 index 00000000000..a16169156ff --- /dev/null +++ b/static/usage/v7/animations/chain/demo.html @@ -0,0 +1,96 @@ + + + + + + Animation + + + + + + + + + + +
+ + Card 1 + + + + Card 2 + + + + Card 3 + + +
+ Play + Pause + Stop +
+
+ + diff --git a/static/usage/v7/animations/chain/index.md b/static/usage/v7/animations/chain/index.md new file mode 100644 index 00000000000..58d8c2c888b --- /dev/null +++ b/static/usage/v7/animations/chain/index.md @@ -0,0 +1,25 @@ +import Playground from '@site/src/components/global/Playground'; + +import javascript from './javascript.md'; +import react from './react.md'; +import vue from './vue.md'; + +import angular_example_component_html from './angular/example_component_html.md'; +import angular_example_component_ts from './angular/example_component_ts.md'; + + diff --git a/static/usage/v7/animations/chain/javascript.md b/static/usage/v7/animations/chain/javascript.md new file mode 100644 index 00000000000..26011045834 --- /dev/null +++ b/static/usage/v7/animations/chain/javascript.md @@ -0,0 +1,67 @@ +```html + + Card 1 + + + + Card 2 + + + + Card 3 + + +Play +Pause +Stop + + +``` diff --git a/static/usage/v7/animations/chain/react.md b/static/usage/v7/animations/chain/react.md new file mode 100644 index 00000000000..b559f038d7b --- /dev/null +++ b/static/usage/v7/animations/chain/react.md @@ -0,0 +1,95 @@ +```tsx +import React, { useEffect, useRef } from 'react'; +import { IonButton, IonCard, IonCardContent, createAnimation } from '@ionic/react'; +import type { Animation } from '@ionic/react'; + +function Example() { + const cardAEl = useRef(null); + const cardBEl = useRef(null); + const cardCEl = useRef(null); + + const cardA = useRef(); + const cardB = useRef(); + const cardC = useRef(); + + useEffect(() => { + if (!cardA.current) { + cardA.current = createAnimation() + .addElement(cardAEl.current!) + .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)' }, + ]); + } + + if (!cardB.current) { + cardB.current = createAnimation() + .addElement(cardBEl.current!) + .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' }, + ]); + } + if (!cardC.current) { + cardC.current = createAnimation() + .addElement(cardCEl.current!) + .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' }, + ]); + } + }, [cardAEl, cardBEl, cardCEl]); + + const play = async () => { + await cardA.current?.play(); + await cardB.current?.play(); + await cardC.current?.play(); + }; + const pause = () => { + cardA.current?.pause(); + cardB.current?.pause(); + cardC.current?.pause(); + }; + const stop = () => { + cardA.current?.stop(); + cardB.current?.stop(); + cardC.current?.stop(); + }; + + return ( + <> + + Card 1 + + + + Card 2 + + + + Card 3 + + + + Play + + + Pause + + + Stop + + + ); +} +export default Example; +``` diff --git a/static/usage/v7/animations/chain/vue.md b/static/usage/v7/animations/chain/vue.md new file mode 100644 index 00000000000..67077e8efa1 --- /dev/null +++ b/static/usage/v7/animations/chain/vue.md @@ -0,0 +1,100 @@ +```html + + + +```