2.5.0 • Published 6 years ago

react-steersman-transition v2.5.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

React Steersman Transition

Tiny react transition library

NPM version Downloads Build Status

Usage

Browser example

JSS example

import React, { Component } from 'react';
import classNames from 'classnames';
import withStyles from 'react-jss';

const styles = theme => ({
  'animation': {
    transition: 'opacity 1s ease',
  },
  'fade-enter-start': {
    opacity: 0,
  },
  'fade-enter-active': {
    opacity: 1,
  },
  'fade-enter-done': {
    opacity: 1,
  },
});

function mapProps({ direction, status }) {
  return { 
    className: classNames(
      classes.animation, 
      classes[`fade-${direction}-${status}`],
    )
  }
}

@withStyles(styles)
export default class App extends Component {
  render() {
    const { classes } = this.props;
    return <Transition 
       timeout={1000} 
       mapProps={mapProps}
       children={({ className }) => <div className={className}>transition</div> }
       startOnMount
     />
  }
}    

Style object example

import React, { Component } from 'react';

const styles = {
  'animation': {
    transition: 'all 1s ease',
  },
  'fade-enter-start': {
    opacity: 0,
  },
  'fade-enter-active': {
    opacity: 1,
  },
  'fade-enter-done': {
    opacity: 1,
  },
};

function mapProps({ direction, status }) {
  return { 
    style: {
      ...styles.animation, 
      ...styles[`fade-${direction}-${status}`]
    },
  };
}

export default class App extends Component {
  render() {
    return <Transition  
      timeout={1000} 
      mapProps={mapProps}
      children={({ style }) => <div style={style}>transition</div>}
      startOnMount
    />
  }
}

React Native example

import React, { Component } from 'react';
import { Animated, Easing, StyleSheet } from 'react-native';

const styles = StyleSheet.create({
  'text': {
    color: '#000',
  },
});

export default class App extends Component {
  
  static timeout = 375;
  
  value = new Animated.Value(0);
  
  animate = (direction) => {
    if (this.animation) {
      this.animation.stop();
    }
    const display = direction === 'enter';
    this.value.setValue(display ? 0 : 1);
    this.animation = Animated.timing(this.value,
      {
        toValue: display ? 1 : 0,
        duration: App.timeout,
        easing: Easing.cubic,
      },
    ).start();
  };
  
  render() {
    return <Transition  
      timeout={App.timeout} 
      children={() => <Animated.Text style={[styles.text, { opacity: this.value }]}>transition</Animated.Text>}
      onEnter={this.animate}
      startOnMount
    />
  }
}

License

License The MIT License Copyright (c) 2017-2018 Ivan Zakharchanka

2.5.0

6 years ago

1.4.0

6 years ago

1.2.0

6 years ago

1.0.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.28

6 years ago

0.1.27

6 years ago

0.1.26

6 years ago

0.1.25

6 years ago

0.1.24

6 years ago

0.1.23

6 years ago

0.1.22

6 years ago

0.1.21

6 years ago

0.1.20

6 years ago

0.1.19

6 years ago

0.1.18

6 years ago

0.1.17

6 years ago

0.1.16

6 years ago

0.1.15

6 years ago

0.1.14

6 years ago

0.1.13

6 years ago

0.1.12

6 years ago

0.1.11

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago