index.ios.js 2.43 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
} = React;
Gaëtan Renaudeau's avatar
wip  
Gaëtan Renaudeau committed
8
const Camera = require("react-native-camera");
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
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 41
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,
42 43
      hue: 0,
      mode: 0
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
44 45 46
    };
  }
  render () {
47
    const { blur, hue, blurPasses, mode } = this.state;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
48 49
    return (
      <View style={styles.container}>
50
        <Surface pixelRatio={1} width={640} height={480} autoRedraw eventsThrough width={width} height={height}>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
51 52
          <Blur passes={blurPasses} factor={blur}>
            <HueRotate hue={hue}>
Gaëtan Renaudeau's avatar
wip  
Gaëtan Renaudeau committed
53 54 55
              {   mode === 0 ?
                <Video source={{ uri: "video" }} repeat style={styles.video} />
                : mode === 1 ?
56 57 58
                <View style={{ flex: 1, backgroundColor: "#fff", padding: 10 }}>
                  <Text style={{ fontSize: 80, color: "#F00" }}>Hello</Text>
                  <Text style={{ fontSize: 60, color: "#00F" }}>World</Text>
Gaëtan Renaudeau's avatar
wip  
Gaëtan Renaudeau committed
59 60
                </View>
                : mode === 2 ?
61
                "http://i.imgur.com/2Go2D7i.jpg"
Gaëtan Renaudeau's avatar
wip  
Gaëtan Renaudeau committed
62 63
                : mode === 3 ?
                <Camera style={styles.preview} aspect={Camera.constants.Aspect.Fill} />
64 65
                : null
              }
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
66 67 68
            </HueRotate>
          </Blur>
        </Surface>
Gaëtan Renaudeau's avatar
wip  
Gaëtan Renaudeau committed
69
        <Field min={0} max={4} step={1} value={mode} onChange={mode => this.setState({ mode })} name="Content" width={width} />
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
70 71 72 73 74 75 76 77 78
        <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);