• This repository has been archived on 10/Nov/2020
  • Stars
    star
    299
  • Rank 134,506 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple tool to debug GSAP animations

logo

banner

about

GsapTools

npm version

A simple tool to debug GSAP animations

Managing and debugging Tween and Timeline in GSAP is a hassle, even with the official dev tools. So we created GsapTools, a tool for React1, that makes it all so much easier. Scroll down to know more and go take a look at the website.

1. GsapTools only works with React for the moment, but we plan to make it works on other popular front-end library in the future.

Installation

yarn add gsap-tools

Features

  • Play/pause
  • Loop
  • Rewind
  • In/out markers
  • Timescale
  • Draggable UI
  • Updated animations
  • Timeline details

How to use it

First, add GsapTools component globally to your application. You only need to do this once.

import GsapTools from 'gsap-tools';

<GsapTools />

Next, register your GSAP animation to be controlled with GsapTools.

Define an id on the Timeline constructor or on the Tween vars object, call the add function to register the timeline, and create a reference to the add function to remove it when the component is unmounted.

import { add } from 'gsap-tools';

componentDidMount() {
  this.t = new TimelineLite({ id: 'myTimeline' });

  this.disposer = add(this.t);
}

componentWillUnmount() {
  this.disposer();
}

That’s the simpler version. Here is an alternative setup.

import { add } from 'gsap-tools';

/*
 * With Timeline
 */

componentDidMount() {
  // You can define an id on the Timeline's constructor
  this.timeline = new TimelineLite({ id: 'myTimeline' });

  // Or you can also define an id on the add function itself
  this.disposer = add(this.timeline, 'myTimeline');

  // Or it will generate an id if you don't specify any
  this.disposer = add(this.timeline);
}

componentWillUnmount() {
  // Remove the Timeline by using the disposer reference
  this.disposer();
}

/*
 * With Tween
 */

componentDidMount() {
  // You can define an id within the vars object
  this.tween = TweenLite.to(this.el, 1, { x: 50, id: 'myTween' });

  // Or you can define an id on the add function itself
  this.disposer = add(this.tween, 'myTween');

  // Or it will generate an id if you don't specify any
  this.disposer = add(this.tween);
}

componentWillUnmount() {
  // Remove the Tween by using the disposer reference
  this.disposer();
}

Examples

  • The GsapTools’ website use the tool itself, you can see it in action here: AppLayout.js and Hero.js.
  • There is also more examples with Tween and Timeline also here.

Shortcuts

  • space Play/pause
  • L Toggle loop
  • H Toggle UI
  • E Expand Timeline
  • R Reset in/out markers
  • Rewind
  • Speed up
  • Slow down

References

<GsapTools /> component

  • isVisible (default = false) Show GsapTools by default. Or not. It’s a free country.

  • isFixed (default = true) With the draggable feature, GsapTools defaults to position: fixed on top of everything. But you can pass false to this prop to position the tool however you like.

  • onClick (default = undefined) The tool comes with a built-in button to toggle the component. But if you decide to have your own button to handle this, just pass an onClick prop to the component and it will override the built-in function. This is useful if you have a whole dev tools package and already have a way to enable specific tools.

add() function

  • Timeline/Tween (required) The first argument to pass is the animation object. It can be either Tween or Timeline instances.

  • id (optional) Instead of passing the id to the timeline method constructor you can pass it on the add() function itself.

But, why?

We ❤️ GSAP. We ❤️ it so much that we use GSAP for animations on almost all of our projects.

But one thing were struggling with for a long time was debugging big timelines. Most of the time we reload, reload, reload, reload, reload, reload, reload, reload. You get where this is going.

Recently GSAP introduced their dev tools. We tried them but found they didn’t really fit our needs: Setting the tools up with webpack, a real mess; when unmounting a component, removing its timeline after being registered is not possible; and finally, animations are only registered if they are played 2 seconds after the page is loaded, which is a problem if we have an animation playing based on user interaction, or when a waypoint is triggered.

That’s why we decided to make our own tool to address these issues.

You to the rescue

If you noticed any issues, have any ideas, or want to open pull requests, just do it. And if you want to know more about who we are and what we do, here’s a link for that.

Development

In source folder:

npm run watch
npm link

In project:

npm link gsap-tools

More Repositories

1

react-native-starter

Professional react-native starter kit with everything you'll ever need to deploy rock solid apps
Ruby
577
star
2

starter-kit-universally

Ueno.'s react starter kit
JavaScript
185
star
3

create-ueno-app

The easiest and fastest way to create new web projects with next, gatsby, create-react-app and mobile projects with react-native.
JavaScript
111
star
4

newsletter

Newsletter email templates
HTML
43
star
5

styleguide

Ueno's code style guide and linter configs
JavaScript
30
star
6

mobx-server-wait

Render universally with server wait mobx actions
JavaScript
27
star
7

starter-kit-historical

ueno. Starter kit
JavaScript
24
star
8

ueno-next-starter

Opinionated Next starter template by Ueno.
TypeScript
22
star
9

ueno-ui

Ueno. UI Components
JavaScript
17
star
10

ueno-gatsby-prismic

Ueno gatsby demo with prismic connection
TypeScript
11
star
11

next-prismic-demo

Prismic with create-ueno-app NextJS setup
TypeScript
9
star
12

ueno-code-menu

Ueno's menu in VSCode
TypeScript
8
star
13

async-dom

Asynchronously call a method after the DOM has changed
JavaScript
8
star
14

demo-prismic

JavaScript
7
star
15

ueno-3d-starter

3D Starter with react-three-fiber and suspense
TypeScript
6
star
16

react-waypoint-decorator

Decorator to apply waypoints to React components
JavaScript
6
star
17

vue-starterkit

JavaScript
5
star
18

template-www

./src folder in all the different starters
TypeScript
5
star
19

prismic-kit

Helpful tools for building Prismic apps in React
JavaScript
5
star
20

ueno-app

Pet project and a public sample of ueno's react native setup
Objective-C
5
star
21

ueno-five-www

Source for the five year's anniversary website
TypeScript
3
star
22

react-native-ueno-css-modules

React Native CSS Modules with variables and theme support
JavaScript
3
star
23

ueno-design-osx-screensaver

Objective-C
2
star
24

markdown-to-prismic-richtext

Converts markdown to prismic richtext objects.
TypeScript
2
star
25

gatsby-plugin-ueno

Plugin void for all ueno things in gatsby
JavaScript
2
star
26

contentful-extension-link-field

Link Field extension for Contentful
HTML
2
star
27

ueno-atom-menu

JavaScript
1
star
28

code-react-native-styles

Visual Studio Code plugin to convert CSS to React Native compatible styles
TypeScript
1
star
29

ueno-cli

Ueno Command-Line Utility
TypeScript
1
star
30

demo-contentful

Demo based on starter kit and contentful
JavaScript
1
star
31

demo-app-django-nginx

Quick demo of a possible scenario where a django setup is running on the same domain as a React frontend based on create-ueno-app with an nginx proxy inside docker.
TypeScript
1
star
32

demo-next-prime

Next.JS demo with Prime
CSS
1
star
33

react-native-tv-starter

React Native App and TV starter kit. tvOS and Android TV
Objective-C
1
star