npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nativescript-community/tween

v0.0.15

Published

Natively wraps tween.js, a tweening engine for easy animations, incorporating optimized Robert Penner's equations

Downloads

99

Readme

NativeScript Tween

npm downloads npm downloads npm

A NativeScript plugin that natively wraps tween.js, a tweening engine for easy animations, incorporating optimized Robert Penner's equations.

| | | | --- | ----------- | | iOS Demo | Android Demo |

Table of Contents

  1. Installation
  2. Configuration
  3. API
  4. Usage in Angular
  5. Usage in Vue
  6. Usage in Svelte
  7. Usage in React
  8. Demos

Installation

Run the following command from the root of your project:

ns plugin add @nativescript-community/tween

Configuration

No futher configuration is needed.

API

This plugin exports the same API as tween.js.

Refer to the offical tween.js user guide additional examples and information.

For now grouping, chaining, repeating... are not supported. Just basic tweening.

Any view property that is a number should technically be able to be tweened. All of these have not been tested, but some of the common ones that work are:

  • width
  • height
  • rotate
  • scaleX
  • scaleY
  • translateX
  • translateY
  • opacity

The following are available tween easing options:

  • TWEEN.Easing.Linear.None
  • TWEEN.Easing.Quadratic.In
  • TWEEN.Easing.Quadratic.Out
  • TWEEN.Easing.Cubic.In
  • TWEEN.Easing.Cubic.Out
  • TWEEN.Easing.Quartic.In
  • TWEEN.Easing.Quartic.Out
  • TWEEN.Easing.Quintic.In
  • TWEEN.Easing.Quintic.Out
  • TWEEN.Easing.Sinusoidal.In
  • TWEEN.Easing.Sinusoidal.Out
  • TWEEN.Easing.Exponential.In
  • TWEEN.Easing.Exponential.Out
  • TWEEN.Easing.Circular.In
  • TWEEN.Easing.Circular.Out
  • TWEEN.Easing.Elastic.In
  • TWEEN.Easing.Elastic.Out
  • TWEEN.Easing.Back.In
  • TWEEN.Easing.Back.Out
  • TWEEN.Easing.Bounce.In
  • TWEEN.Easing.Bounce.Out

Usage in Angular

The following is a very simple example of getting tweens to run in your Angular project.

Create a view that you would like to animate as well as a button to trigger it in your component's HTML file.

<StackLayout>
    <Button text="Start Animation" (tap)="startTween()" verticalAlignment="top"></Button>

    <AbsoluteLayout #box width="30" height="30" backgroundColor="red" horizontalAlignment="center" verticalAlignment="center"></AbsoluteLayout>
</StackLayout>

Reference the view you want to animate in your component's typescript file with the following (and add required imports):

boxRef: AbsoluteLayout;
@ViewChild("box", { static: true }) boxElementRef: ElementRef;

ngOnInit(): void {
    this.boxRef = this.boxElementRef.nativeElement;
}

Import the tween module in your component's typescript file:

import { TWEEN } from '@nativescript-community/tween';

Create a function that will contain the call to run the tween.

startTween() {
    new TWEEN.Tween({ value: 30 })
        .easing(TWEEN.Easing.Quadratic.In)
        .to({ value: 300 }, 1000)
        .onStart(() => {
            console.log("The tween has stated...");
        })
        .onComplete(() => {
            console.log("The tween has completed...");
        })
        .onUpdate(obj => {
            this.boxRef.width = obj.value;
        })
        .start();
}

That should be all you need! Now, when you tap the button Start Animation, the box's width should go from 30 to 300.

Look in the demo-ng directory for a more advanced demo.

Usage in Vue

The following is a very simple example of getting tweens to run in your Vue project.

Create a view that you would like to animate as well as a button to trigger it.

<StackLayout>
    <Button text="Start Animation" @tap="startTween" />
    <AbsoluteLayout ref="box" width="30" height="30" backgroundColor="red" horizontalAlignment="center" verticalAlignment="center"></AbsoluteLayout>
</StackLayout>

Reference the view you want to animate in your component computed section:

// ...
computed: {
    boxRef(){
        return this.$refs.box.nativeView;
    }     
},
// ...

Import the tween module in your component:

import { TWEEN } from '@nativescript-community/tween';

Create a function that will contain the call to run the tween.

startTween() {
    new TWEEN.Tween({ value: 30 })
        .easing(TWEEN.Easing.Quadratic.In)
        .to({ value: 300 }, 1000)
        .onStart(() => {
            console.log("The tween has stated...");
        })
        .onComplete(() => {
            console.log("The tween has completed...");
        })
        .onUpdate(obj => {
            this.boxRef.width = obj.value;
        })
        .start();
}

That should be all you need! Now, when you tap the button Start Animation, the box's width should go from 30 to 300.

Look in the demo-vue directory for a more advanced demo.

Usage in Svelte

The following is a very simple example of getting tweens to run in your Svelte project.

Create a view that you would like to animate as well as a button to trigger it.

<stackLayout>
    <button text="Start Animation" on:tap="{startTween}" />
    <absoluteLayout bind:this="{boxRef}" width="30" height="30" backgroundColor="red" horizontalAlignment="center" verticalAlignment="center"></absoluteLayout>
</stackLayout>

Reference the view you want to animate in your component.

let boxRef: AbsoluteLayout;
onMount(() => {
    boxRef = boxRef.nativeView;
})

Import the tween module in your component:

import { TWEEN } from '@nativescript-community/tween';

Create a function that will contain the call to run the tween.

function startTween() {
    new TWEEN.Tween({ value: 30 })
        .easing(TWEEN.Easing.Quadratic.In)
        .to({ value: 300 }, 1000)
        .onStart(() => {
            console.log("The tween has stated...");
        })
        .onComplete(() => {
            console.log("The tween has completed...");
        })
        .onUpdate(obj => {
            boxRef.width = obj.value;
        })
        .start();
}

That should be all you need! Now, when you tap the button Start Animation, the box's width should go from 30 to 300.

Look in the demo-svelte directory for a more advanced demo.

Usage in React

The following is a very simple example of getting tweens to run in your React project.

Create a view that you would like to animate as well as a button to trigger it.

<stackLayout>
    <button text="Start Animation" onTap={startTween} />
    <absoluteLayout ref={boxRef} width="30" height="30" backgroundColor="red" horizontalAlignment="center" verticalAlignment="middle"></absoluteLayout>
</stackLayout

Reference the view you want to animate in your component.

const boxRef = React.useRef<NSVElement<AbsoluteLayout>>(null);

Import the tween module in your component:

import { TWEEN } from '@nativescript-community/tween';

Create a function that will contain the call to run the tween.

function startTween() {
    new TWEEN.Tween({ value: 30 })
        .easing(TWEEN.Easing.Quadratic.In)
        .to({ value: 300 }, 1000)
        .onStart(() => {
            console.log("The tween has stated...");
        })
        .onComplete(() => {
            console.log("The tween has completed...");
        })
        .onUpdate(obj => {
            boxRef.current!.nativeView.width = obj.value;
        })
        .start();
}

That should be all you need! Now, when you tap the button Start Animation, the box's width should go from 30 to 300.

Look in the demo-react directory for a more advanced demo

Demos

This repository includes Angular, Vue.js, Svelte, and React demos. In order to run these execute the following in your shell:

$ git clone https://github.com/@nativescript-community/tween
$ cd tween
$ npm i
$ npm run build
$ cd demo-ng # or demo-vue or demo-svelte or demo-react
$ ns run ios|android