Connected Animation for Ionic Framework v4
Easily add Connected Animation (in UWP) or Shared Element Transition (in Android) to your elements.
Example Project
Setup
- install via npm:
npm i ng-ionic4-connectedanim@latest --save
- Import ConnectedAnimationModule in your module:
;
Usage
1. Basic example. as easy as:
In Page1.html:
Push page2
Page1.ts:
{ thisrouter; }
Page2.html:
2. Multiple connected animation
Page1.html:
Push page2
Page1.ts:
{ thisnavCtrl; }
Page2.html:
Note: If you want to use any element other than img
, the animStart
and animEnd
elements must be identical in font-*, width, height and text-align, otherwise the animation will not work well.
3. Multiple Items as 'animStart'
When you have a list of items in the first page, it is important to pass the element index before navigating to the second page, so animation can be played correctly.
Also add animItem
attribute to animated element.
list-page.html:
list-page.ts:
;; { } { // pass item index thisconnectedAnimationService; // then push DetailPage thisrouter; }
DetailPage.html:
4. Manually play animation:
This is useful for elements in the same page.
set autoFire to false in animOptions
:
Open Close
{ } { // first show your modal // Make sure its 'style.display' is not 'none' before playing animation. //let itemIndex = 0; /* Send element index if you are using ngFor */ thisanimationService; // or play a specific animation by its name //this.animationService.playAnimation('animation1'/*, itemIndex*/); } { thisanimationService; // then hide the modal... }
Options
You can pass animation options to `animStart' element.
Options:
Option | Desc. |
---|---|
autoFire | Set autoFire to false to manually play the animation by calling animationService.playAnimation(), default is true. |
type | Animation type, e.g.: 'ease', 'ease-in'... |
delay | Animation delay. |
duration | Animation duration. |
targetRect | Target element ('animEnd' element) position or offset. |