index.ios.js 2.27 KB
Newer Older
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
1 2 3 4 5
const React = require("react-native");
const {
  AppRegistry,
  StyleSheet,
  View,
6
  Text,
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
} = React;
const Video = require("react-native-video").default;
const {
  width: viewportW
} = require("Dimensions").get("window");

const {Surface} = require("gl-react-native");
const HueRotate = require("./HueRotate");
const {Blur} = require("gl-react-blur");

const Field = require("./Field");

const width = viewportW;
const height = Math.round(viewportW * 480/640);

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#eee",
  },
  video: {
    width,
    height
  }
});

class App extends React.Component {
  constructor (props) {
    super(props);
    this.state = {
      blur: 0,
      blurPasses: 2,
41 42
      hue: 0,
      mode: 0
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
43 44 45
    };
  }
  render () {
46
    const { blur, hue, blurPasses, mode } = this.state;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
47 48
    return (
      <View style={styles.container}>
49
        <Surface pixelRatio={1} width={640} height={480} autoRedraw eventsThrough width={width} height={height}>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
50 51
          <Blur passes={blurPasses} factor={blur}>
            <HueRotate hue={hue}>
52 53 54 55 56 57 58 59 60 61 62
              { mode === 0 ?
                <Video source={{ uri: "video" }} repeat style={styles.video} /> :
                mode === 1 ?
                <View style={{ flex: 1, backgroundColor: "#fff", padding: 10 }}>
                  <Text style={{ fontSize: 80, color: "#F00" }}>Hello</Text>
                  <Text style={{ fontSize: 60, color: "#00F" }}>World</Text>
                </View> :
                mode === 2 ?
                "http://i.imgur.com/2Go2D7i.jpg"
                : null
              }
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
63 64 65
            </HueRotate>
          </Blur>
        </Surface>
66
        <Field min={0} max={3} step={1} value={mode} onChange={mode => this.setState({ mode })} name="Content" width={width} />
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
67 68 69 70 71 72 73 74 75
        <Field min={0} max={2*Math.PI} value={hue} onChange={hue => this.setState({ hue })} name="Hue" width={width} />
        <Field min={0} max={16} value={blur} onChange={blur => this.setState({ blur })} name="Blur" width={width} />
        <Field min={2} max={8} step={1} value={blurPasses} onChange={blurPasses => this.setState({ blurPasses })} name="Blur Passes" width={width} />
      </View>
    );
  }
}

AppRegistry.registerComponent("Video", () => App);