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
ArrayBuffer
containing a json or zip file as bytes. After the animation has been loaded theload
event is fired. - By default the
autoPlay
property 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 theload
event fired.
- Whether the animation is currently playing. A
playing
value oftrue
translates to being in any of the statesplay
,resume
orrepeat
.
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 astateChanged
event.
- 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
repeatCount
can 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
scaleMode
allows to change the size of the animation when it does not match the bounds of theLottieView
. - The default value
auto
scales the animation to match theWidget
bounds but does not scale the animation up. The valuefill
scales 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 thescaleMode
in the Tabris.jsImageView
. - To retrieve the size of a loaded animation in dp the
composition
offers thewidth
andheight
properties.
- Allows to render the animation larger or smaller by multiplying the animation dimension with the
scale
factor. E.g. ascale
of0.5
shows the animation at half its size. - The
scale
factor can also be used when an animation shows performance problems. In such a scenario one could set thescale
to a value less than 1 (e.g.0.5
) and set thescaleMode
tofill
. 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
composition
provides static meta-data about a loaded animation. It is available after theload
event has fired. Setting a newanimation
sets thecomposition
tonull
. Thecomposition
provides 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 theframe
changes aframeChanged
event is fired.
- The
minFrame
specifies the beginning frame when rendering an animation. - An animation is only rendered between its
minFrame
andmaxFrame
boundaries. This also affects the way an animation is repeated by also limiting its playback to the range given by theminFrame
andmaxFrame
. - 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
maxFrame
specifies the end frame when rendering an animation. If not provided it is set tocomposition.frames
after an animation is loaded, so that by default the entire animation is played. - An animation is only rendered between its
minFrame
andmaxFrame
boundaries. This also affects the way an animation is repeated by also limiting its playback to the range given by theminFrame
andmaxFrame
. - 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
animation
is set and has finished loading. At this point thecomposition
property is available.
composition
: object- Contains static information about the properties of the loaded animation. See the
composition
property 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
value
field contains the new playback state. See thestate
property for details.
- The event objects
- Fired when the
LottieView
is displaying a new frame.
event
: object- The event objects
value
field contains the currently rendered frame index. See theframe
property for details.
- The event objects
- Starts playing a loaded animation from the first
frame
as given byminFrame
. Can be invoked before the animation has finished loading, so that the playback will start as soon as possible ifautoPlay
is set tofalse
.
- Pauses the a running animation and lets the
LottieView
show the current frame.
- Continues playback at the current location.
- Stops the current playback and resets the current
frame
to 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-android
The environment variable is consumed in the gradle projects build.gradle file.
See LICENSE notice.