Custom Ionic Animation On Page Transition

Hello,
We want to make animation for ion-content and prevent the ion-header to be animated

let do it fast 😀

Create a Directive Module

ionic generate module directive

ionic generate directive page-animation –module directive


This content originally appeared on DEV Community and was authored by timsar2

Hello,
We want to make animation for ion-content and prevent the ion-header to be animated

ionic animation directive

let do it fast :D

Create a Directive Module

ionic generate module directive
ionic generate directive page-animation --module directive

This is PageAnimationDirective :

import { Directive, ElementRef } from '@angular/core';
import { createAnimation  } from '@ionic/core';
import { AnimationController } from '@ionic/angular';

@Directive({
  selector: '[appPageAnimation]'
})
export class PageAnimationDirective {

  constructor(private animationCtrl: AnimationController, private el: ElementRef) {
    this.dropIn();
  }

  private dropIn() {
    const animation = createAnimation()
              .addElement(this.el.nativeElement)
              .duration(500)
              .iterations(1)
              .fromTo('transform', 'translateY(-10%)', 'translateY(0%)');
    animation.play();
  }
}

Export PageAnimationDirective from DirectiveModule:

@NgModule({
  declarations: [PageAnimationDirective],
  imports: [
    CommonModule
  ],
  exports: [PageAnimationDirective]
})
export class DirectiveModule { }

Import DirectiveModule to Component.Module.ts of each component you want to be animated like this:

@NgModule({
  imports: [FormsModule, DirectiveModule],
  declarations: [FolderPage]
})

From you component.html add appPageAnimation directive to ion-content:

<ion-content [fullscreen]="true" appPageAnimation>

To Prevent ion-header, tabs, etc.. to be animated on page transition, make animate flag to false from app.module:

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    ...
    IonicModule.forRoot({ animated: false  }),
    ...
}

Enjoy It :D


This content originally appeared on DEV Community and was authored by timsar2


Print Share Comment Cite Upload Translate Updates
APA

timsar2 | Sciencx (2021-09-22T21:04:43+00:00) Custom Ionic Animation On Page Transition. Retrieved from https://www.scien.cx/2021/09/22/custom-ionic-animation-on-page-transition/

MLA
" » Custom Ionic Animation On Page Transition." timsar2 | Sciencx - Wednesday September 22, 2021, https://www.scien.cx/2021/09/22/custom-ionic-animation-on-page-transition/
HARVARD
timsar2 | Sciencx Wednesday September 22, 2021 » Custom Ionic Animation On Page Transition., viewed ,<https://www.scien.cx/2021/09/22/custom-ionic-animation-on-page-transition/>
VANCOUVER
timsar2 | Sciencx - » Custom Ionic Animation On Page Transition. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/22/custom-ionic-animation-on-page-transition/
CHICAGO
" » Custom Ionic Animation On Page Transition." timsar2 | Sciencx - Accessed . https://www.scien.cx/2021/09/22/custom-ionic-animation-on-page-transition/
IEEE
" » Custom Ionic Animation On Page Transition." timsar2 | Sciencx [Online]. Available: https://www.scien.cx/2021/09/22/custom-ionic-animation-on-page-transition/. [Accessed: ]
rf:citation
» Custom Ionic Animation On Page Transition | timsar2 | Sciencx | https://www.scien.cx/2021/09/22/custom-ionic-animation-on-page-transition/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.