nativescript Implementing Animations in Nativescript Use of animation timing function and animation properties.

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

pages/main.component.ts

import {Component, ElementRef, ViewChild} from "@angular/core";
import {View} from "ui/core/view";
import {AnimationCurve} from "ui/enums";

@Component({
    selector: "main",
    template: `
        <StackLayout>
          <Image #img src="~/assets/images/user-shape.png"></Image>
          <Button text="Apply Changes" (tap)="animateImage()"></Button>
        </StackLayout>
    `,
    styleUrls: ["pages/main/main-common.css"],
})

export class MainComponent {
    @ViewChild("img") img: ElementRef;
    animateImage() {
        let img = <View>this.img.nativeElement;
        img.animate({
            translate: { x: 0, y: 120 },
            duration: 2000,
            curve: AnimationCurve.easeIn
        });
    }
}

#snippet for other animation properties

You can also write your own timing function using cubicBezier.

  1. Use of cubicBezier
img.animate({
        translate: { x: 0, y: 120 },
        duration: 2000,
        curve: AnimationCurve.cubicBezier(0.1, 0.2, 0.1, 1)
  });
  1. Animation Properties

Opacity

img.animate({
    opacity: 0,
    duration: 2000
});

Translate

img.animate({
    translate: { x: 120, y: 0},
    duration: 2000
});

Scale

img.animate({
    scale: { x: 1.5, y: 1.5},
    duration: 2000
});

Rotate

img.animate({
    rotate: 270,
    duration: 2000
});


Got any nativescript Question?