5.0.4 • Published 3 years ago

nativescript-lottie v5.0.4

Weekly downloads
603
License
MIT
Repository
github
Last release
3 years ago

Changelog

All notable changes to this project will be documented in the changelog.

Demo Screen

The .gif does not do the fluid animations justice

LottieView

Installation

To install execute:

NativeScript Version 7+:

ns plugin add nativescript-lottie

NativeScript Version prior to 7:

tns plugin add nativescript-lottie@4.0.1

Usage

NativeScript (Core)

XML

<Page
    xmlns="http://schemas.nativescript.org/tns.xsd"
    xmlns:Lottie="nativescript-lottie" navigatingTo="navigatingTo" class="page">
    <StackLayout>
        <Lottie:LottieView src="PinJump.json" height="130" loop="true" autoPlay="true" loaded="yourLoadedEvent" />
    </StackLayout>
</Page>

TS

import { LottieView } from "nativescript-lottie";

public yourLoadedEvent(args) {
    this._myLottie = args.object as LottieView; /// this is the instance of the LottieAnimationView
    this._myLottie.loop = false; // to get the completionBlock to fire the animation can not be looping because then it will never "complete"
    this._myLottie.completionBlock = (bool) => {
        console.log('lottie animaton complete', bool);
    }
}

NativeScript Angular

XML

<StackLayout>
    <LottieView width="100" height="150" [src]="src" [loop]="loop" [autoPlay]="autoPlay" (loaded)="lottieViewLoaded($event)"></LottieView>
</StackLayout>

Component

import { Component } from '@angular/core';
import { registerElement } from '@nativescript/angular';
import { LottieView } from 'nativescript-lottie';

registerElement('LottieView', () => LottieView);

@Component({
  templateUrl: 'home.component.html',
  moduleId: module.id
})
export class HomeComponent {
  public loop: boolean = true;
  public src: string;
  public autoPlay: boolean = true;
  public animations: Array<string>;

  private _lottieView: LottieView;

  constructor() {
    this.animations = [
      'Mobilo/A.json',
      'Mobilo/D.json',
      'Mobilo/N.json',
      'Mobilo/S.json'
    ];
    this.src = this.animations[0];
  }

  lottieViewLoaded(event) {
    this._lottieView = <LottieView>event.object;
    this._myLottie.loop = false; // to get the completionBlock to fire the animation can not be looping because then it will never "complete"
    this._myLottie.completionBlock = bool => {
      console.log('lottie animaton complete', bool);
    };
  }
}

NativeScript Vue

Bootstrap (probably in app.js)

Vue.registerElement(
  'LottieView',
  () => require('nativescript-lottie').LottieView
);

Component

<template>
    <Page class="page">
        <StackLayout>
            <LottieView height="130" src="PinJump.json" :loop="true" :autoPlay="true" @loaded="lottieViewLoaded"></LottieView>
        </StackLayout>
    </page
</template>

<script>
    export default {
        methods: {
            lottieViewLoaded(args) {
                this._lottieView = args.object;
            },
        },
        data() {
            return {
                _lottieView: null,
            }
        }
    };
</script>

Assets

:fire: You can find animations in the sample-effects folder.

Android

Place your animation files in the NS app's app/App_Resources/Android/src/main/assets folder.

Note: In a nativescript-vue project the above folder may not exist. Place the files in platforms/android/app/src/main/assets.

iOS

Place your animations files in your app/App_Resources/iOS/ folder.

Properties (bindable)

PropertyTypeDefaultDescription
autoPlaybooleanfalseStart LottieView animation on load if true.
loopbooleanfalseLoop continuously animation if true.
srcstringnullAnimation path to .json file.

Properties

PropertyTypeDefaultDescription
completionBlock(boolean) => voidnullCompletion block to be executed upon completion of the animation. The animation is considered complete when it finishes playing and is no longer looping.
durationnumbernullGet the duration of the animation.
progressnumber0Get/set the progress of the animation.
speednumber1Get/set the speed of the animation.

Methods

MethodReturnParametersDescription
cancelAnimationvoidNonePauses the animation for the LottieView instance.
isAnimatingbooleanNoneReturns true if the LottieView is animating, else false.
playAnimationvoidNonePlays the animation for the LottieView instance.
playAnimationFromProgressToProgressvoidstartProgress, endProgressPlays the animation for the LottieView instance from the specified start and end progress values (between 0 and 1).
setColorValueDelegateForKeyPathvoidvalue, keyPathSets the provided color value on each property that matches the specified keyPath in the LottieView instance.
setOpacityValueDelegateForKeyPathvoidvalue, keyPathSets the provided opacity value (0 - 1) on each property that matches the specified keyPath in the LottieView instance.

Contributors

bradmartinNathanWalkerrhanbHamdiWanis
itstheceomudlabs

Contributing

  1. Fork and clone the repository
  2. cd nativescript-lottie && npm run demo.android (or demo.ios)
  3. Changes in the src directory of the plugin will sync to the demo app for testing changes.
  4. Create a PR with proposed changes.
5.0.4

3 years ago

5.0.3

3 years ago

5.0.2

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.0.1

4 years ago

4.0.0

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.1.2

5 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.4.0

6 years ago

1.3.1

6 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.10

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago