Code Monkey home page Code Monkey logo

react-flight's Introduction

https://jondot.github.io/react-flight/

The best way to build animation compositions for React. Design and compose a component to start with, a component to end with, and Flight will take it from there.

Flight tries to be for React what Principle is for Sketch compositions - the fastest, most friction free way to compose and an effortless way to animate an idea, an interaction, or a short movie-like composition in a self-contained widget (a React component after all).

Check out the new video:

React Flight in Three Minutes

Quick Start (From Scratch)

Just clone and use the example, built around create-react-app:

$ git clone https://github.com/jondot/react-flight
$ cd react-flight/examples/compos
$ yarn && yarn start

Quick Start (Existing Project)

With yarn (or npm):

$ yarn add react-flight
$ curl https://raw.githubusercontent.com/jondot/react-flight/master/examples/compos/src/index.js -o src/anim.js

And now you can frame your compositions in anim.js, require and place it in any other React component.

Next:

  1. Add jQuery (or Zepto, or any jQuery drop-in) if you don't have it already in the project.
  2. Or if you use create-react-app you can add it to your public/index.html, like here, or eject and configure webpack for jQuery.

NOTE: jQuery is currently a requirement of one of react-flight's dependencies. We plan to rebuild that dependency any way, obsoleting this requirement in the process (also: PRs accepted!).

Workflow

When you're designing compositions, focus on designing frames. The first frame is marked source because that's the starting point, and interactive because you want to play with it while you go.

  <Flight interactive ref={flight => (this.flight = flight)}>
    <Flight.Frame duration={300} source interactive showFrames>

Showing Frames

While designing, you want to have showFrames on. It will unpack all of the frames in front of you, so you could edit them while watching them. With Webpack hot-reload this becomes a fantastic experience.

When done, remove showFrames.

Controlling Flight Directly

This is where the ref addition comes in:

  <Flight interactive ref={flight => (this.flight = flight)}>
    <Flight.Frame duration={300} source interactive showFrames>

Once you can grab an instance of flight you can flight.play() and flight.reset() on demand from your own components and actions.

Here's a full layout:

  <Flight interactive ref={flight => (this.flight = flight)}>
    <Flight.Frame duration={300} source interactive showFrames>

      -- your own DOM / React Components ---
      -- starting position and styles    ---

    </Flight.Frame>

    <Flight.Frame>

      -- your own DOM / React Components ---
      -- ending position and styles    ---

    </Flight.Frame>
  </Flight>

Redux

If you're using Redux, there's basic support for it. Basic in the sense that react-flight is not going to handle deep renders of a stateful app with all its gotchas, so YMMV.

You can check out this Redux example for a fully working solution.

For your app, you can enable Redux support by indicating inclusion of store before using the Flight component:

Flight.contextTypes = {
  store: PropTypes.object,
}

Flight.childContextTypes = {
  ...Flight.childContextTypes,
  store: PropTypes.object,
}

Under the Hood

If you want to hack on react-flight, here are some context to keep in mind.

react-flight does some cool stuff and some DOM-heavy stuff (perhaps less cool?). For the cool stuff, it walks the component tree, makes decisions about what should move where, and builds a clean and nice declarative data structure that represents the way compositions should behave.

Currently it will then hand over this data to a DOM-based adapter, that also uses Velocity.js, so that it would actually orchestrate the animations. This is where you're welcome to plug in your own adapter - another animation engine, React Native, and what not.

Happy hacking!

Contributing

Fork, implement, add tests, pull request, get my everlasting thanks and a respectable place here :).

Thanks:

To all Contributors - you make this happen, thanks!

Copyright

Copyright (c) 2017 Dotan Nahum @jondot. See LICENSE for further details.

react-flight's People

Contributors

dschau avatar jondot avatar treeless avatar ummahusla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-flight's Issues

Build error: [email protected] build:umd: `NODE_ENV=development webpack`

Wanted to play around react-flight but wasn't been able to run yarn. Tested it with both yarn / yarn start and npm install / npm start


๐Ÿ“ Log

edvins.antonovs@NEMO MINGW64 /d/repos
$ git clone https://github.com/jondot/react-flight
Cloning into 'react-flight'...
remote: Counting objects: 106, done.
remote: Compressing objects: 100% (73/73), done.
remote: Total 106 (delta 22), reused 106 (delta 22), pack-reused 0
Receiving objects: 100% (106/106), 1.54 MiB | 886.00 KiB/s, done.
Resolving deltas: 100% (22/22), done.

edvins.antonovs@NEMO MINGW64 /d/repos
$ cd react-flight/

edvins.antonovs@NEMO MINGW64 /d/repos/react-flight (master)
$ ls
core/  dom/       media/        README.md  webpack.config.js
dist/  examples/  package.json  src/       yarn.lock

edvins.antonovs@NEMO MINGW64 /d/repos/react-flight (master)
$ yarn
yarn install v0.23.2
[1/4] Resolving packages...
[2/4] Fetching packages...
warning [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it
 from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
warning Your current version of Yarn is out of date. The latest version is "0.24.6" while you
're on "0.23.2".
info To upgrade, download the latest installer at "https://yarnpkg.com/latest.msi".
$ npm run build

> [email protected] build D:\repos\react-flight
> npm run build:lib && npm run build:umd && npm run build:umd:min


> [email protected] build:lib D:\repos\react-flight
> babel src --out-dir . && rm -rf __tests__

src\core\director.js -> core\director.js
src\core\flight.js -> core\flight.js
src\core\velocity-composer.js -> core\velocity-composer.js
src\dom\controls.js -> dom\controls.js
src\dom\index.js -> dom\index.js
src\dom\ui.js -> dom\ui.js
src\__tests__\index.spec.js -> __tests__\index.spec.js

> [email protected] build:umd D:\repos\react-flight
> NODE_ENV=development webpack

'NODE_ENV' is not recognized as an internal or external command,
operable program or batch file.

npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\
\npm\\bin\\npm-cli.js" "run" "build:umd"
npm ERR! node v6.10.2
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] build:umd: `NODE_ENV=development webpack`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build:umd script 'NODE_ENV=development webpack'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the react-flight package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     NODE_ENV=development webpack
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs react-flight
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls react-flight
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     D:\repos\react-flight\npm-debug.log

npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\
\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v6.10.2
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] build: `npm run build:lib && npm run build:umd && npm run build:u
md:min`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script 'npm run build:lib && npm run build:um
d && npm run build:umd:min'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the react-flight package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run build:lib && npm run build:umd && npm run build:umd:min
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs react-flight
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls react-flight
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     D:\repos\react-flight\npm-debug.log
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

jQuery is not defined

Hey ! Wanted to mention that the project seems really cool. However, I ran into this error while trying to use Flight and therefore I cannot test it myself.

Steps to reproduce:

On an existing project, run:

npm i react-flight --save

Install jQuery/Zepto (one of them):

npm i zepto --save

npm i jquery --save

Import it in js file:

import Flight, {Frame} from 'react-flight/dom';

Use the doc's example, and got :

capture d ecran 2017-06-22 a 15 02 20 2

x

Sorry, wrong window. wrong project. ๐Ÿ˜‡

Attempt jQuery removal

Goal is to provide a more lightweight bundle size, one less dependency, and to use Velocity's built-in capability instead of jQuery's.

Challenge is to find and separate dependencies from tweene and tweene-velocity which treat jQuery as a global dependency and relies on jQuery plugin system.

This is motivated by #17, #16, #11

Error Command "start" not found

Thanks for fixing in #2 but it still seems to be broken as I cannot compile it. Same issue exists both for yarn && yarn start and npm i && npm start.

Should be the line in readme replaced to yarn && yarn build?


๐Ÿ“ Log when yarn && yarn start

edvins.antonovs@NEMO MINGW64 /d/repos
$ git clone https://github.com/jondot/react-flight
Cloning into 'react-flight'...
remote: Counting objects: 171, done.
remote: Compressing objects: 100% (109/109), done.
remote: Total 171 (delta 62), reused 158 (delta 49), pack-reused 0
Receiving objects: 100% (171/171), 1.60 MiB | 1.25 MiB/s, done.
Resolving deltas: 100% (62/62), done.

edvins.antonovs@NEMO MINGW64 /d/repos
$ cd react-flight

edvins.antonovs@NEMO MINGW64 /d/repos/react-flight (master)
$ yarn && yarn start
yarn install v0.23.2
[1/4] Resolving packages...
[2/4] Fetching packages...
warning [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it
 from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 20.88s.
yarn start v0.23.2
error Command "start" not found.

$.fn.velocity is undefined

Hi there,

Thanks for this project it is very cool.

I included jQuery, however when try to go to next frame with either play or interactive, I get

$.fn.velocity is undefined.

$ and jQuery are definitely available in the global of the bundle (not global window scope though)

The only way for me to fix this was by not relying on webpack and instead adding in:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.slim.min.js"></script>

Can't yarn && yarn start in the examples folder

So I wanted to run the example which is based on CRA and I just entered the directory and hit yarn && yarn start and got next bit.


๐Ÿ“ Log

edvins.antonovs@NEMO MINGW64 /d/repos/react-flight/examples/compos (master)
$ yarn && yarn start
yarn install v0.23.2
[1/4] Resolving packages...
error Command failed.
Exit code: 128
Command: git
Arguments: clone ssh://[email protected]/jondot/react-flight.git C:\Users\edvins.antonovs\AppDat
a\Local\Yarn\cache\v1\.tmp\19629a569d02bfdf167197eb7f6761e6
Directory: D:\repos\react-flight\examples\compos
Output:
Cloning into 'C:\Users\edvins.antonovs\AppData\Local\Yarn\cache\v1\.tmp\19629a569d02bfdf16719
7eb7f6761e6'...
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Intergration with a Router (example)

Could you show an example of how to use react-flight with react-router-dom for example? It would be awesome if you added it to the examples folder, for everyone else to see.

Cannot read property 'store' of undefined

Hey ! Now that I managed to properly import jQuery into the project, I've been trying to implement it.

Everything works fine with the imported component Rect. But am I not supposed to be able to use my own components as well ?

Steps to reproduce :

<Flight interactive ref={flight => (this.flight = flight)}>
  <Flight.Frame duration={300} source interactive>
    <div className="keyframe">
      <MyCustomComponent style={...} />
    </div>
  </Flight.Frame>
  <Flight.Frame duration={300}>
    <div className="keyframe">
      <MyCustomComponent style={...} />
    </div>
  </Flight.Frame>
</Flight>

Error:

connectAdvanced.js:113: Uncaught TypeError: Cannot read property 'store' of undefined
    at new Connect (http://localhost:3001/static/js/bundle.js:62754:49)
    at http://localhost:3001/static/js/bundle.js:266516:26
    at Array.map (native)
    at walk (http://localhost:3001/static/js/bundle.js:266500:52)
    at http://localhost:3001/static/js/bundle.js:266535:14
    at Array.map (native)
    at walk (http://localhost:3001/static/js/bundle.js:266500:52)
    at extract (http://localhost:3001/static/js/bundle.js:266541:105)
    at Array.map (native)
    at styles (http://localhost:3001/static/js/bundle.js:266544:60)
    at new Director (http://localhost:3001/static/js/bundle.js:266559:20)
    at http://localhost:3001/static/js/bundle.js:266718:26

Tried:

  • To nest my component inside a Rect,
  • To assign name, id, className to the component.

Am I doing something wrong here ? Has the registerServiceWorker anything to do with it ?

Need better docs/examples

I really like the idea of this project -- I think there's a lot of room for making animation in react simpler. However, I think you need better documentation / examples. I tried using this in a project I'm working on today and for the life of me I couldn't get it working. The cloned repo and example worked fine -- but when I tried to apply it to my own code... well, nothing worked.

It'd be nice if you had some examples showing animation of components that weren't the included Rect, and also if you specified what css is required on custom components to make everything play nicely.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.