index.js 2.42 KB
Newer Older
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
1 2
import React from "react";
import {StyleSheet, View} from "react-native";
3
import {resolveAssetSource} from "gl-react-native";
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
4 5
const { width: viewportW, height: viewportH } = require("Dimensions").get("window");

6 7 8 9
import Banner from "./Banner";
import Intro from "./Intro";
import Vignette from "./Vignette";
import Slideshow from "./Slideshow";
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
10

11

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
12 13 14 15 16 17 18
class AdvancedEffects extends React.Component {

  constructor (props) {
    super(props);
    this.state = {
      time: 0.02,
      frames: 1,
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
19
      embeddedImage: resolveAssetSource(require("./Image.jpg")),
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
20 21
      images:
       //"MQtLWbD,N8a9CkZ,adCmISK,AedZQ4N,y9qRJR3,brzKTYZ,NSyk07l,EaZiWfn,I1KZdnl,DoQBdzT,slIt2Ww,DA12puU,IYLdRFW,oqmO4Po,T6NaLyI,6XAPrAY,thYzbif,4qmqo3o,8xT2J96,ZCa2pWq,loQfDN2,oabfA68,uOXqDRY,MyyS4vK,fhNYTX4"
22
        "wxqlQkh,G2Whuq3,0bUSEBX,giP58XN,iKdXwVm,IvpoR40,zJIxPEo,CKlmtPs,fnMylHI,vGXYiYy,MnOB9Le,YqsZKgc,0BJobQo,Otbz312"
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
23
          .split(",")
24
          .map(id => `http://imgur.com/${id}.jpg`)
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
25 26 27 28 29 30
    };
  }

  componentDidMount () {
    let startTime;
    const loop = t => {
31
      this._raf = requestAnimationFrame(loop);
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
32 33 34 35
      if (!startTime) startTime = t;
      const time = (t - startTime) / 1000;
      this.setState({ time: time, frames: this.state.frames+1 });
    };
36 37 38 39 40
    this._raf = requestAnimationFrame(loop);
  }

  componentWillUnmount () {
    cancelAnimationFrame(this._raf);
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
41 42 43
  }

  render () {
44
    const {time, frames, images, embeddedImage} = this.state;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

    const nbVignettes = 1;
    const imgW = Math.floor(viewportW/nbVignettes);
    const imgH = Math.floor((2/3)*viewportW/nbVignettes);
    const introH = 100;
    const transitionH = Math.floor((2/3)*viewportW);

    return (
      <View style={styles.root}>
        <Banner
          time={time}
          width={viewportW}
          height={viewportH - introH - imgH - transitionH}
        />
        <Intro
          time={time}
          fps={frames/time}
          width={viewportW}
          height={introH}
        />
65

66 67 68 69 70 71
        <Vignette
          time={time}
          width={imgW}
          height={imgH}
          source={embeddedImage}
        />
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
72 73 74 75 76 77

        <Slideshow
          time={time}
          width={viewportW}
          height={transitionH}
          images={images.slice(2)}
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
78 79
          pauseDuration={0.5}
          transitionDuration={1.5}
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  root: {
    flex: 1,
    backgroundColor: "#111"
  }
});

module.exports = AdvancedEffects;