All Projects → steadicat → React Rebound

steadicat / React Rebound

High-performance spring animations in React

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Rebound

Jstarcraft Example
基于JStarCraft RNS引擎,Spring Boot框架和公共数据集搭建的千人千面演示项目. 系统会根据用户的行为记录,自动调整用户的推荐内容和搜索内容.使用者可以通过该项目了解*推荐系统*与*搜索系统*的运作流程. 涵盖了个性化推荐与个性化搜索2个部分.
Stars: ✭ 119 (-7.03%)
Mutual labels:  spring
Downlords Faf Client
Official client for Forged Alliance Forever
Stars: ✭ 121 (-5.47%)
Mutual labels:  spring
Angular bootstrap spring
AngularJS, Restful, Spring, Spring Security, Hibernate,Bootstrap, Gulp in ES6, Maven
Stars: ✭ 125 (-2.34%)
Mutual labels:  spring
Extdirectspring
Implementation of the Ext Direct protocol with Java and Spring
Stars: ✭ 119 (-7.03%)
Mutual labels:  spring
Securing Rest Api Spring Security
Spring Boot 2.2.x + Spring 5.2.x Rest Api Security Example
Stars: ✭ 117 (-8.59%)
Mutual labels:  spring
Houserentalsystem
🏠 房屋租赁系统,基于主流框架 SSM 的实战项目。
Stars: ✭ 122 (-4.69%)
Mutual labels:  spring
Ibase4j
Spring,SpringBoot 2.0,SpringMVC,Mybatis,mybatis-plus,motan/dubbo分布式,Redis缓存,Shiro权限管理,Spring-Session单点登录,Quartz分布式集群调度,Restful服务,QQ/微信登录,App token登录,微信/支付宝支付;日期转换、数据类型转换、序列化、汉字转拼音、身份证号码验证、数字转人民币、发送短信、发送邮件、加密解密、图片处理、excel导入导出、FTP/SFTP/fastDFS上传下载、二维码、XML读写、高精度计算、系统配置工具类等等。
Stars: ✭ 1,548 (+1109.38%)
Mutual labels:  spring
Permission
一款带ui基于RBAC模型的可自由配置的原生的权限框架
Stars: ✭ 127 (-0.78%)
Mutual labels:  spring
Spring Boot Blog
Simple blog web app made using Spring Boot + Thymeleaf
Stars: ✭ 121 (-5.47%)
Mutual labels:  spring
Nimrod
Nimrod - 基于 Spring Boot 构建 的 Java Web 平台企业级单体应用快速开发框架,适合中小型项目的应用和开发。所采用的技术栈包括 Spring Boot、Spring、Spring Web MVC、MyBatis、Thymeleaf 等,遵守阿里巴巴 Java 开发规约,帮助养成良好的编码习惯。整体采用 RBAC ( Role-Based Access Control ,基于角色的访问控制),具有严格的权限控制模块,支持系统与模块分离开发。最后希望这个项目能够对你有所帮助。Nimrod 开发交流群:547252502(QQ 群)
Stars: ✭ 125 (-2.34%)
Mutual labels:  spring
Springactionmenu
This is a spring ActionMenu - 一个弹性的功能菜单
Stars: ✭ 120 (-6.25%)
Mutual labels:  spring
Spring Mvc Tutorial
Spring MVC 5 Tutorial - Guide to spring mvc framework
Stars: ✭ 121 (-5.47%)
Mutual labels:  spring
Mlds2018spring
Machine Learning and having it Deep and Structured (MLDS) in 2018 spring
Stars: ✭ 124 (-3.12%)
Mutual labels:  spring
Springboot
📚 springboot学习记录
Stars: ✭ 119 (-7.03%)
Mutual labels:  spring
Android Notes
Articles, notes, interview questions and resources management for Android.
Stars: ✭ 126 (-1.56%)
Mutual labels:  spring
Wicket Spring Boot
Spring Boot starter for Apache Wicket
Stars: ✭ 117 (-8.59%)
Mutual labels:  spring
Ssm Demo
🍌Spring+SpringMVC+Mybatis+easyUI实现简单的后台管理系统
Stars: ✭ 1,639 (+1180.47%)
Mutual labels:  spring
Bucket4j Spring Boot Starter
Spring Boot Starter for Bucket4j
Stars: ✭ 127 (-0.78%)
Mutual labels:  spring
Sfg Blog Posts
Source code examples for blog posts
Stars: ✭ 125 (-2.34%)
Mutual labels:  spring
Spring Javafx Examples
Example apps for springboot-javafx-support. See
Stars: ✭ 124 (-3.12%)
Mutual labels:  spring

React Rebound

A spring-based React animation library that animates elements directly in the DOM for maximum performance. Hooks and component-based API available. Spring physics are based on rebound.

Check out some demos here.

The useAnimation hook

useAnimation takes a “ref” to the element you want to animate, and an object containing the end values for the spring animation.

import {useAnimation} from 'react-rebound';

function Example() {
  const [hovered] = React.useState(false);
  const ref = React.useRef();

  // A little “pop” on hover
  useAnimation(ref, {scaleX: hovered ? 1.1 : 1, scaleY: hovered ? 1.1 : 1});

  return (
    <button
      ref={ref}
      onMouseEnter={() => setHovered(true)}
      onMouseLeave={() => setHovered(false)}>
      Hover Me
    </button>
  );
}

The Animate component

The Animate component wraps the DOM element you want to animate. It takes the end values for the spring animation as props.

import {Animate} from 'react-rebound';

function Example() {
  const [hovered] = React.useState(false);

  return (
    <Animate scaleX={hovered ? 1.1 : 1} scaleY={hovered ? 1.1 : 1}>
      <button onMouseEnter={() => setHovered(true)} onMouseLeave={() => setHovered(false)}>
        Hover Me
      </button>
    </Animate>
  );
}

Configuring springs

You can configure the tension and friction for the spring that’s driving the animation. Use props on Animate, and a third parameter to useAnimation.

A delay parameter is also available. It defers the animation by the specified number of milliseconds. This is useful for cascading animations.

// Using useAnimation
useAnimation(ref, {translateX: clicked ? 200 : 0}, {tension: 200, friction: 400, delay: 100});
<button ref={ref}>Click Me</button>


// Using Animate
<Animate translateX={clicked ? 200 : 0} tension={200} friction={400} delay={100}>
  <button>Click Me</button>
</Animate>

Animating colors

You can animate between two colors by representing colors as RGB(A) arrays. See Supported properties for the list of color properties supported.

<Animate color={hovered ? [238, 85, 34] : [0, 0, 0]}>
  <a href="#">Hover Me</a>
</Animate>

Render function with animating parameter

Sometimes it’s useful to render children differently during animations. To do that, provide a function as the only child. The function takes one parameter, a boolean that tells you whether an animation is in progress.

This option is only avaliable with the Animate component. If you’re using the useAnimation hook, use start and end callbacks.

<Animate scaleX={expanded ? 3 : 1} scaleY={expanded ? 3 : 1}>
  {animating => <img style={{zIndex: expanded || animating ? 1 : 0}} />}
</Animate>

Start and end callbacks

In complex situations it might be useful to be notified when an animation starts or ends. useCallback and Animate provide two callbacks: onStart and onEnd.

// Using useAnimation
useAnimation(
  ref,
  {scaleX: expanded ? : 5 : 1, scaleY: expanded ? 5 : 1},
  {onStart: onExpandStart, onEnd: onExpandEnd},
);

// Using Animate
<Animate
  scaleX={expanded ? 5 : 1}
  scaleY={expanded ? 5 : 1}
  onStart={onExpandStart}
  onEnd={onExpandEnd}>
  <img />
</Animate>

Animating on first render

To animate an element in on mount, first render with the initial value, then trigger an animation using componentDidMount or useEffect:

// Using useAnimation
const ref = React.useRef();
const [visible, setVisible] = React.useState(false);

React.useEffect(() => setVisible(true), []);

useAnimation(ref, {opacity: visible ? 1 : 0});

<button ref={ref}>Hover Me</button>;

// Using Animate
const [visible, setVisible] = React.useState(false);

React.useEffect(() => setVisible(true), []);

<Animate opacity={visible ? 1 : 0}>
  <button>Hover Me</button>
</Animate>;

Setting initial values

Spring animations should always start from their previous value: this is why with react-rebound you only specify the end value of the animation.

In some special cases, it might be necessary to override the start value. You have two options:

  1. Use the setCurrentValue imperative API (see Setting current values and velocity).
  2. Render with an initial value and animate={false}, then render again with your end value and animate={true}.
// Using useAnimation
const [visible, setVisible] = React.useState(false);
const instantHide = React.useCallback(() => setVisible(false));
const fadeIn = React.useCallback(() => setVisible(true));
useAnimation(ref, {opacity: visible ? 1 : 0}, {animate: visible});

<button ref={ref}>Hover Me</button>;

// Using Animate
const [visible, setVisible] = React.useState(false);
const instantHide = React.useCallback(() => setVisible(false));
const fadeIn = React.useCallback(() => setVisible(true));

<Animate opacity={visible ? 1 : 0} animate={visible}>
  <button>Hover Me</button>
</Animate>;

Setting current values and velocity

useAnimation returns an object containing all the Rebound springs, indexed by property name. This gives you full control if you need it, including the option of calling setCurrentValue and setVelocity on the springs directly. This is useful for swipes and drags, where you want to override the spring animation while dragging, and preserve velocity when the drag ends.

const ref = React.useRef();
const springs = useAnimation(ref, {translateX: restingPosition});

const onSwipeMove = React.useCallback(() => {
  springs.translateX.setCurrentValue(currentPosition);
});

const onSwipeEnd = React.useCallback(() => {
  springs.translateX.setVelocity(200);
});

<img ref={ref} />;

When using Animate, you can override the current value and velocity of an animation using the public methods setCurrentValue and setVelocity on the component instance.

const animation = React.useRef();

const onSwipeMove = React.useCallback(() => {
  animation.current.setCurrentValue('translateX', currentPosition);
});

const onSwipeEnd = React.useCallback(() => {
  animation.current.setVelocity('translateX', 200);
});

<Animate ref={animation} translateX={restingPosition}>
  <img />
</Animate>;

Supported properties

This is the full list of properties you can animate:

Transforms

  • translateX: number in px
  • translateY: number in px
  • translateZ: number in px
  • scaleX: number representing the scale ratio (1 is the default)
  • scaleY: number representing the scale ratio (1 is the default)
  • rotateX: number in deg
  • rotateY: number in deg
  • rotateZ: number in deg
  • skewX: number in deg
  • skewY: number in deg

Position and opacity

  • top: number in px
  • left: number in px
  • right: number in px
  • bottom: number in px
  • width: number in px
  • height: number in px
  • opacity: number between 0 and 1

Colors

Warning: animating colors causes a paint on every frame. Consider animating using opacity instead.

  • color: array of numbers, either [r, g, b] or [r, g, b, a]
  • background: array of numbers, either [r, g, b] or [r, g, b, a]
  • backgroundColor: array of numbers, either [r, g, b] or [r, g, b, a]
  • borderBottomColor: array of numbers, either [r, g, b] or [r, g, b, a]
  • borderColor: array of numbers, either [r, g, b] or [r, g, b, a]
  • borderLeftColor: array of numbers, either [r, g, b] or [r, g, b, a]
  • borderRightColor: array of numbers, either [r, g, b] or [r, g, b, a]
  • borderTopColor: array of numbers, either [r, g, b] or [r, g, b, a]
  • outlineColor: array of numbers, either [r, g, b] or [r, g, b, a]
  • textDecorationColor: array of numbers, either [r, g, b] or [r, g, b, a]

Text

Warning: animating text properties can create slow and jittery animations. Consider using scale and translate transforms instead.

  • fontSize: number in px
  • lineHeight: number in px
  • letterSpacing: number in px
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].