# ng-ionic-connectedanim

> Connected Animation (Shared Element Transition) for Ionic Framework.

Latest version **0.0.47** (published 2019-07-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install ng-ionic-connectedanim
pnpm add ng-ionic-connectedanim
yarn add ng-ionic-connectedanim
bun add ng-ionic-connectedanim
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.47 |
| Published | 2019-07-23 |
| First published | 2018-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 8 |
| Unpacked size | 5.8 MB |
| Known vulnerabilities | 0 (+16 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 12 |
| Author | WaseemDev |
| Maintainers | waseemdev |
| Keywords | angular, ionic, transition, animation, ng-ionic-connectedanim |

## Links

- npm: https://www.npmjs.com/package/ng-ionic-connectedanim
- Repository: https://github.com/waseemdev/ng-ionic-connectedanim
- Homepage: https://github.com/waseemdev/ng-ionic-connectedanim#readme
- Issues: https://github.com/waseemdev/ng-ionic-connectedanim/issues
- npm.io page: https://npm.io/package/ng-ionic-connectedanim

## Dependencies (8)

- [rxjs](https://npm.io/package/rxjs.md) 5.5.2
- [zone.js](https://npm.io/package/zone.js.md) 0.8.18
- [@angular/core](https://npm.io/package/@angular/core.md) 5.0.3
- [ionic-angular](https://npm.io/package/ionic-angular.md) 3.9.2
- [@angular/forms](https://npm.io/package/@angular/forms.md) 5.0.3
- [@angular/common](https://npm.io/package/@angular/common.md) 5.0.3
- [@angular/platform-browser](https://npm.io/package/@angular/platform-browser.md) 5.0.3
- [@angular/platform-browser-dynamic](https://npm.io/package/@angular/platform-browser-dynamic.md) 5.0.3

## Alternatives

- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K weekly downloads
- [persona-harness](https://npm.io/package/persona-harness.md) — 4.7K weekly downloads
- [@tsparticles/effect-bubble](https://npm.io/package/@tsparticles/effect-bubble.md) — 4.6K weekly downloads
- [f3d](https://npm.io/package/f3d.md) — 730 weekly downloads
- [spark-html-motion](https://npm.io/package/spark-html-motion.md) — 298 weekly downloads

## Recent versions

- 0.0.47 (latest) — 2019-07-23
- 0.0.46 — 2018-09-04
- 0.0.45 — 2018-09-04
- 0.0.44 — 2018-09-04
- 0.0.43 — 2018-09-04
- 0.0.42 — 2018-03-11
- 0.0.41 — 2018-03-11
- 0.0.40 — 2018-03-11
- 0.0.39 — 2018-03-11
- 0.0.38 — 2018-03-11
- 0.0.37 — 2018-03-11
- 0.0.36 — 2018-03-11
- 0.0.35 — 2018-03-10
- 0.0.34 — 2018-03-10
- 0.0.33 — 2018-03-10
- … 32 more at https://npm.io/package/ng-ionic-connectedanim/versions

## README

# Connected Animation for Ionic Framework
Easily add Connected Animation (in UWP) or Shared Element Transition (in Android) to your elements.

# Example Project
[Here is an example](example)


# Setup

1. install via npm:
```
npm i ng-ionic-connectedanim@latest --save
```
2. Import ConnectedAnimationModule in your module
```typescript
import { ConnectedAnimationModule } from "ng-ionic-connectedanim";

@NgModule({
    imports: [
        ConnectedAnimationModule.forRoot(),
        ....
    ]
})
export class AppModule { }
```


# Usage
## 1. Basic example. as easy as:
In Page1.html:
```html
<img [src]="image" [animStart]="'animation-cover'">
<button (click)="push()">Push page2</button>
```
Page1.ts:
```javascript
    push() {
        this.navCtrl.push('Page2');
    }
```

Page2.html:
```html
<img [src]="image" [animEnd]="'animation-cover'">
```

## 2. Multiple connected animation
Page1.html:
```html
<img [src]="image" [animStart]="'anim-image'">
<p class="title" [animStart]="'anim-title'">
<button (click)="push()">Push page2</button>
```
Page1.ts:
```javascript
    push() {
        this.navCtrl.push('Page2');
    }
```
Page2.html:
```html
<img [src]="image" [animEnd]="'anim-image'">
<p class="title" [animEnd]="'anim-title'">
```

**Note:** If you want to use any element other than `img`, the `animStart` element and `animEnd` must be identical in font-*, width, height and text-align, otherwise the animation will not work well.

## 3. Multiple Items as 'animStart'
![Example 1](uploads/preview1.gif)

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.

Page1.html:
```html
<div *ngFor="let item of items; let i = index" (click)="pushPage(i)">
    <img [src]="item.image" [animStart]="'animation-image'" animItem>
</div>
```
Pgae1.ts:
```javascript
import {ConnectedAnimationService} from 'ng-ionic-connectedanim';
export class Page1 {
    constructor(private navCtrl: NavController,
                private connectedAnimationService: ConnectedAnimationService) {
    }

    pushPage(itemIndex) {
        // pass item index
        this.connectedAnimationService.setItemIndex(itemIndex, this);
        // then push page2
        this.navCtrl.push('Page2');
    }
}
```
Page2.html:
```html
<img [src]="image" [animEnd]="'animation-image'">
```

## 4. Manually play animation:
This is useful for elements in the same page.
set autoFire to false in `animOptions`:
```html
<img [src]="image" [animStart]="'animation1'" [animOptions]="{ autoFire: false }">
<button (click)="openModal()">Open</button>

<div class="my-modal">
    <img [src]="image" [animEnd]="'animation1'">
    <button (click)="closeModal()">Close</button>
</div>
```

```javascript
export class Page {
    constructor(private animationService: ConnectedAnimationService) {
    }

    openModal() {
        // 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 */
        this.animationService.playAnimations(this/*, itemIndex*/);
        // or play a specific animation by its name
        //this.animationService.playAnimation('animation1'/*, itemIndex*/);
    }

    closeModal() {
        this.animationService.playAnimationBack(this);
        // then hide the modal...
    }
}
```

![Example 2](uploads/preview2.gif)

# Options
You can pass animation options to `animStart' element.
```html
<img [animStart]="'animation1'" [animOptions]="options">
```

#### 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. |

<br>

---
_Source: https://npm.io/package/ng-ionic-connectedanim · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
