Slideshow.js 1.89 KB
Newer Older
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
1 2
const React = require("react-native");
const GL = require("gl-react-native");
3
const TransitionGenerator = require("./TransitionGenerator");
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
4 5
const Transition = require("./Transition");

6
const shaders = GL.Shaders.create(TransitionGenerator.shaders);
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
7 8

class Slideshow extends React.Component {
9 10 11 12
  constructor (props) {
    super(props);
    this._currentTransition = -1;
  }
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
13 14 15 16 17 18 19
  render () {
    const { duration, width, height, time, images } = this.props;
    const slide = time / duration;
    let transitionProgress = slide % 1;
    let transitionFrom = images[Math.floor(slide) % images.length];
    let transitionTo = images[Math.floor(slide+1) % images.length];

20 21 22 23 24 25 26 27 28 29 30 31
    const currentTransition = Math.floor(slide);
    if (currentTransition !== this._currentTransition) {
      this._currentTransition = currentTransition;
      const { name, uniforms } = TransitionGenerator.random();
      this._shader = shaders[name];
      this._uniforms = uniforms;
    }

    const transitionShader = this._shader;
    const transitionUniforms = this._uniforms;

    /*
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    switch (Math.floor(slide/4) % 3) {
    case 0:
      transitionShader = shaders.transitionRandomSquares;
      const w = 3 * (1 + Math.floor(slide % 8));
      transitionUniforms = {
        size: [w, w * 2 / 3],
        smoothness: 0.5
      };
      break;
    case 1:
      transitionShader = shaders.transitionDirectionalWipe;
      transitionUniforms = {
        direction: [Math.cos(time/2), Math.sin(time/2)],
        smoothness: 0.5
      };
      break;
    case 2:
      transitionShader = shaders.transitionWind;
      transitionUniforms = {
        size: 0.2
      };
      break;
    }
55
    */
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69

    return <Transition
      width={width}
      height={height}
      progress={transitionProgress}
      from={transitionFrom}
      to={transitionTo}
      shader={transitionShader}
      uniforms={transitionUniforms}
    />;
  }
}

module.exports = Slideshow;