A Lottie widget for Tabris.js, allowing to display and control Lottie animations. The plugin currently supports Android.
The plugin currently supports Android.
The following table shows the plugin branches and the minimum required Tabris.js version:
| Version | Branch | Minimum Tabris.js version |
|---|---|---|
| 1.0.0 | master |
3.3.0 |
The following snippet shows how the tabris-plugin-lottie plugin can be used in a Tabris.js app:
new eslottie.LottieView({
left: 0, right: 0, top: 0, bottom: 0,
animation: 'lottie-file.json'
}).appendTo(tabris.contentView);A more elaborate example can be found in the example folder. It provides a Tabris.js project that demonstrates the various features of the tabris-plugin-lottie plugin. Consult the README of the example for build instructions.
The Tabris.js website provides detailed information on how to integrate custom widgets in your Tabris.js app. To add the plugin to your app add the following entry in your apps config.xml:
<!-- Not yet on npm -->
<!-- <plugin name="tabris-plugin-lottie" spec="^1.0.0" /> -->To fetch the latest development version use the GitHub URL:
<plugin name="tabris-plugin-lottie" spec="https://github.com/eclipsesource/tabris-plugin-lottie.git" />The plugin api consists of the eslottie.LottieView Widget with the following properties, methods and events.
- Loads a Lottie animation from either an uri pointing to a json or zip file, or from an
ArrayBuffercontaining a json or zip file as bytes. After the animation has been loaded theloadevent is fired. - By default the
autoPlayproperty is set totrue, starting the animation immediately. Otherwise the animation has to be started explicitly (by e.g. callingplay()). When not started the first frame is rendered.
- If set to
true, the animation starts playing immediately after the animation has been loaded and theloadevent fired.
- Whether the animation is currently playing. A
playingvalue oftruetranslates to being in any of the statesplay,resumeorrepeat.
state : string, read only, supported values: play, finish, pause, resume, cancel, repeat, default: finish
- Represents the current playback state. Using any of the
play()/pause()etc. methods or letting the animation reach the end fires astateChangedevent.
- Sets the playback speed. If speed < 0, the animation will play backwards.
- The number of times the animation should be repeated. By default the animation is played only once. To repeat the animation indefinitely the
repeatCountcan be set toInfinity.
- Specifies how to repeat the animation. Either by playing it again from the beginning or by playing it backwards when the end has been reached.
- The
scaleModeallows to change the size of the animation when it does not match the bounds of theLottieView. - The default value
autoscales the animation to match theWidgetbounds but does not scale the animation up. The valuefillscales the animation to the bounds of theLottieView, making it fit inside but not changing its proportions. The two modes work in the same manor as thescaleModein the Tabris.jsImageView. - To retrieve the size of a loaded animation in dp the
compositionoffers thewidthandheightproperties.
- Allows to render the animation larger or smaller by multiplying the animation dimension with the
scalefactor. E.g. ascaleof0.5shows the animation at half its size. - The
scalefactor can also be used when an animation shows performance problems. In such a scenario one could set thescaleto a value less than 1 (e.g.0.5) and set thescaleModetofill. This would render the animation shrunken down but display it larger. The results would be less cpu usage but also a degradation of visual quality.
-
A
compositionprovides static meta-data about a loaded animation. It is available after theloadevent has fired. Setting a newanimationsets thecompositiontonull. Thecompositionprovides the following properties:width: number - the horizontal size of the animation in dpheight: number - the vertical size of the animation in dpframes: number - the number of total frames in the animationframeRate: number - the length of one frame in the animationduration: _number: - the total duration of the animation in milliseconds
- The current frame that is rendered in the
LottieView. When theframechanges aframeChangedevent is fired.
- The
minFramespecifies the beginning frame when rendering an animation. - An animation is only rendered between its
minFrameandmaxFrameboundaries. This also affects the way an animation is repeated by also limiting its playback to the range given by theminFrameandmaxFrame. - The limiting boundaries can be used to control an animation that consists of different phases. E.g. a progress spinner which morphs into a checkmark after the work is done.
- The
maxFramespecifies the end frame when rendering an animation. If not provided it is set tocomposition.framesafter an animation is loaded, so that by default the entire animation is played. - An animation is only rendered between its
minFrameandmaxFrameboundaries. This also affects the way an animation is repeated by also limiting its playback to the range given by theminFrameandmaxFrame. - The limiting boundaries can be used to control an animation that consists of different phases. E.g. a progress spinner which morphs into a checkmark after the work is done.
- Fired when an
animationis set and has finished loading. At this point thecompositionproperty is available.
composition: object- Contains static information about the properties of the loaded animation. See the
compositionproperty for details about the provided information.
- Contains static information about the properties of the loaded animation. See the
- Fired when the animation is played, paused, resumed, canceled, repeated or finished. The event is fired either when the animation triggered it (by e.g. reaching the animation end) or when manually invoking
play()/pause()etc.
event: object- The event objects
valuefield contains the new playback state. See thestateproperty for details.
- The event objects
- Fired when the
LottieViewis displaying a new frame.
event: object- The event objects
valuefield contains the currently rendered frame index. See theframeproperty for details.
- The event objects
- Starts playing a loaded animation from the first
frameas given byminFrame. Can be invoked before the animation has finished loading, so that the playback will start as soon as possible ifautoPlayis set tofalse.
- Pauses the a running animation and lets the
LottieViewshow the current frame.
- Continues playback at the current location.
- Stops the current playback and resets the current
frameto the starting position given byminFrame.
While not required by the consumer or the widget, this repository provides a project folder that contains platform specific development artifacts. These artifacts allow to more easily consume the native source code when developing the native parts of the widget.
The project provides a gradle based build configuration, which also allows to import the project into Android Studio.
In order to reference the Tabris.js specific APIs, the environment variable TABRIS_ANDROID_PLATFORM has to point to the Tabris.js Android Cordova platform root directory.
export TABRIS_ANDROID_PLATFORM=/home/user/tabris-androidThe environment variable is consumed in the gradle projects build.gradle file.
See LICENSE notice.
