All Projects → bkazi → react-layout-transition

bkazi / react-layout-transition

Licence: MIT license
Trying to make layout transitions simple

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to react-layout-transition

react-animations-from-scratch
medium.com/@alex_holachek/building-animations-in-react-from-scratch-c66a582c9b65
Stars: ✭ 19 (-66.67%)
Mutual labels:  transition
ux-lab
No description or website provided.
Stars: ✭ 49 (-14.04%)
Mutual labels:  transition
animated
🌊 Implicit animations for JavaFX.
Stars: ✭ 79 (+38.6%)
Mutual labels:  transition
floating-layout-android
Floating Layout library for Android
Stars: ✭ 55 (-3.51%)
Mutual labels:  layouts
FiniteStateMachine
This project is a finite state machine designed to be used in games.
Stars: ✭ 45 (-21.05%)
Mutual labels:  transition
utransition
A tiny (~2KB) library providing you an easy way to manage time-based transitions
Stars: ✭ 22 (-61.4%)
Mutual labels:  transition
STCubeTransition
A custom view transition that provides transition between 2 different views with 3D cube rotate effect.
Stars: ✭ 16 (-71.93%)
Mutual labels:  transition
layouts
Wraps templates with layouts. Layouts can use other layouts and be nested to any depth. This can be used 100% standalone to wrap any kind of file with banners, headers or footer content. Use for markdown, HTML, handlebars views, lo-dash templates, etc. Layouts can also be vinyl files.
Stars: ✭ 28 (-50.88%)
Mutual labels:  layouts
Layouts-To-Clone
Este repositório tem como objetivo reunir templates de sites para ajudar a pessoas que estão aprendendo e estão querendo praticar o desenvolvimento de sites.
Stars: ✭ 28 (-50.88%)
Mutual labels:  layouts
flutter scale aware
🎗 Scale-based layouts with a bit more ease, powered by extensions.
Stars: ✭ 26 (-54.39%)
Mutual labels:  layouts
react-scrolling-color-background
background with color transitioning as you scroll, declarative and easy to setup
Stars: ✭ 53 (-7.02%)
Mutual labels:  transition
anim8js
The ultimate animation library for javascript - animate everything!
Stars: ✭ 33 (-42.11%)
Mutual labels:  transition
vue-router-view-transition
Properly time out-in transitions with scrollBehavior
Stars: ✭ 38 (-33.33%)
Mutual labels:  transition
NiceDemo
iOS project, built on improved MVP architecture using Coordinator pattern for routing 😎
Stars: ✭ 54 (-5.26%)
Mutual labels:  transition
SHTransition
SHTransition is a simple library for viewcontroller transition animation in swift.
Stars: ✭ 35 (-38.6%)
Mutual labels:  transition
react-page-swapper
An orchestrator that eases out the implementation of page transitions
Stars: ✭ 16 (-71.93%)
Mutual labels:  transition
dpar
Neural network transition-based dependency parser (in Rust)
Stars: ✭ 41 (-28.07%)
Mutual labels:  transition
django-logic
Django Logic - easy way to implement state-based business logic with pure functions
Stars: ✭ 44 (-22.81%)
Mutual labels:  transition
drain-js
Makes smooth transitions between two numbers.
Stars: ✭ 45 (-21.05%)
Mutual labels:  transition
postcsslayouts
This is the repository for my course, Building a Responsive Single-Page Design with PostCSS on LinkedIn Learning and Lynda.com.
Stars: ✭ 22 (-61.4%)
Mutual labels:  layouts

react-layout-transition

Logo Trying to make layout transitions simple

Build Status Coverage Status

Check it out at https://react-layout-transition.surge.sh/

This project aims to provide React components that can automagically animate between changes in your layout. Inspired by existing solutions on native platforms, it hopes to bring similar functionality and ease to the web.

These are some great pieces with example code on how to use the native platform feature

Note: This is a very early implementation so do expect loads of bugs and missing features (but also be sure to report them)

Usage

react-layout-transition is available on the npm registry and can be installed via npm/yarn

npm install --save react-layout-transition

You should have npm installed if you have Node.js
Or you can download Node.js from https://nodejs.org/en/ which comes with npm

You can also include it directly using script tags via the unpkg CDN

<script src='https://unpkg.com/react-layout-transition/dist/react-layout-transition.min.js'></script>

LayoutTransitionGroup

A component that animates state based changes in layout in certain parts of your view.
Can handle the addition and removal of DOM nodes (as shown below)

LayoutTransitionDemo

Find the code for above example here here

Usage

An abstract class that must be extended by your component Must also implement the getInterpolator function that returns an Interpolator. (see section below)

class MyComponent extends LayoutTransitionGroup {
    this.interpolator = new CssInterpolator();

    getInterpolator() {
        return this.interpolator;
    }

	// must call superclass method if you implement componentDidUpdate
    componentDidUpdate(prevProps, prevState) {
        super.componentDidUpdate(prevProps, prevState);
        // your code here
    }

    // other methods and React lifecycle methods
}

this.beginTransition

this is where the magic happens

parameters

  • stateUpdateFn: (currState) => newState
    A function that takes in the the current state and returns the new state. Identical to the first parameter of React's setState
  • refs: Ref[] | Ref
    The React ref to the HTML element whose top level children will be animated

SharedElementTransitionGroup

A container around the views to transition between that animates shared elements, between their initial and final position. It classifies elements as shared if you mark them with the same id in both the intial and final layout component and does the rest for you.

SharedElementDemo

Find the code for above example here here

Usage

class Demo extends React.Component {
    interpolator = new CssInterpolator();

    state = {
        toggle: true,
    };

    render() {
        return (
            <div>
                // animates when toggle is changed to false
                <SharedElementTransitionGroup interpolator={this.interpolator}>
                    {this.state.toggle && <Page1 />}
                    {!this.state.toggle && <Page2 />}
                </SharedElementTransitionGroup>
            </div>
        );
    }
}

props

  • interpolator: Interpolator
    Pass an instance of the interpolator you would like to use for the animation. (see section below)

Make sure you mark the shared elements with the same ids

class Page1 extends React.Component {
    render() {
        return (
            <div style={this.props.style} ref={this.props.innerRef}>
                <p>...</p>
                <div className='vertical-flex'>
                    // this is where the magic happens ✨
                    <img id="hero" className='img-style' src='image1.jpg' />
                    <img id="another-one" className='img-style' src='image2.jpg' />
                </div>
                <p>...</p>
            </div>
        );
    }
}

class Page2 extends React.Component {
    render() {
        return (
            <div style={this.props.style} ref={this.props.innerRef}>
                // this is where the magic happens ✨
                <img id="hero" className='img-style' src='image1.jpg' />
                <p>...</p>
                <img id="another-one" className='img-style' src='image2.jpg' />
            </div>
        );
    }
}

Interpolators

Interpolators are classes that implement certain methods that are called to perform the animation. This allows seperation of animation logic from the rest of the code and also enables different kinds of animations and techniques.

There are 2 kinds of interpolators in the interpolators directory.

CssInterpolator

import CssInterpolator from 'react-layout-transition/interpolators/CssInterpolator';

const interpolator = new CssInterpolator(timing, easing);

Uses CSS transforms to animate elements.

The constructor takes two optional parameters

  • timing: number
    the number milliseconds the transition takes
    default: 300
  • easing: string
    the easing function for the transition
    default: 'ease-in-out'

SpringInterpolator

import SpringInterpolator from 'react-layout-transition/interpolators/SpringInterpolator';

const interpolator = new SpringInterpolator(stiffness, damping, precision);

Uses CSS transforms to animate elements.

The constructor takes three optional parameters

  • stiffness: number
    the number milliseconds the transition takes
    default: 170
  • damping: number
    the easing function for the transition
    default: 26
  • precision: number
    the easing function for the transition
    default: 0.01

Custom Interpolators

You can write your own interpolators as long as you implement the correct functions

import Interpolator from 'react-layout-transition/interpolators/Interpolator';

class MyInterpolator extends Interpolator {
    play(
        element: HTMLElement,
        invertObject: {sx: number; sy: number; x: number; y: number},
        reverse: boolean,
        callback?: () => void,
    ): void;

    playMultiple(
        element: HTMLElement[],
        invertObject: Array<{sx: number; sy: number; x: number; y: number}>,
        reverse: boolean,
        callback?: () => void,
    ): void;
}

The invertObject is an object that contains the delta of initial and final values of

  • scale in X-axis (sx)
  • scale in Y-axis (sy)
  • translation in X-axis (x)
  • translation in Y-axis (y)

Please do report any bugs you encounter and point to me any examples and use cases that could be used to improve this

If you like the direction the project is headed in and want to help please do reach out!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].