index.js 4.78 KB
Newer Older
1
import React, {
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
2 3 4 5
  Text,
  View,
  ScrollView,
  Image,
6 7 8 9 10 11 12 13 14 15 16 17 18
} from "react-native";
import {Surface} from "gl-react-native";
import {Blur} from "gl-react-blur";
import Add from "./Add";
import Multiply from "./Multiply";
import Layer from "./Layer";
import NativeLayer from "./NativeLayer";
import HelloGL from "./HelloGL";
import Display2 from "./Display2";
import Copy from "./Copy";
import TransparentNonPremultiplied from "./TransparentNonPremultiplied";
import Dimensions from "Dimensions";
const { width: viewportW, height: viewportH } = Dimensions.get("window");
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

class Tests extends React.Component {

  constructor (props) {
    super(props);
    this.onLoad = this.onLoad.bind(this);
    this.onProgress = this.onProgress.bind(this);
  }
  onLoad () {
    console.log("LOADED");
  }
  onProgress ({nativeEvent: { progress, loaded, total }}) {
    console.log("PROGRESS", progress, loaded, total);
  }
  render () {
34
    const debugSize = viewportW / 4;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
35 36 37 38 39 40

    const helloGL =
      <HelloGL width={64} height={64} />;

    const txt =
      <View style={{ width: 400, height: 400, position: "relative", backgroundColor: "transparent" }}>
41
        {[0,1,2,3].map(i => <Text key={i} style={{
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
42 43 44 45 46 47 48 49 50 51 52 53 54
          position: "absolute",
          top: 20+100*i,
          left: 0,
          width: 400,
          height: 100,
          textAlign: "center",
          color: ["#f00", "#0f0", "#00f", "#fff"][i],
          fontSize: 40
        }}>
          Hello World {i}
        </Text>)}
      </View>;

55
    const img = "http://i.imgur.com/zJIxPEo.jpg";
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
56 57 58 59 60 61 62 63 64 65 66 67

    const blurredImage =
      <Blur factor={4} passes={6} width={200} height={200}>
        {img}
      </Blur>;

    const blurredImageOverText =
      <Layer>
        {blurredImage}
        {txt}
      </Layer>;

68 69
    return <ScrollView style={{ backgroundColor: "#000", flex: 1 }}>

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
      <Surface width={viewportW} height={viewportW} preload onLoad={this.onLoad} onProgress={this.onProgress}>
        <Display2>
          <Add width={viewportW/2} height={viewportH/2}>
            {txt}
            {helloGL}
          </Add>
          <Display2 width={viewportW/2} height={viewportH/2} vertical>
            <Blur factor={1} passes={4} width={viewportW/2} height={viewportH/4}>
              <Multiply>
                {blurredImageOverText}
                {helloGL}
              </Multiply>
            </Blur>
            {blurredImage}
          </Display2>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
85
        </Display2>
86
      </Surface>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
87 88 89

      <View style={{ flexDirection: "row", flexWrap: "wrap" }}>

90 91 92 93 94
        <NativeLayer width={debugSize} height={debugSize}>
          <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
          <Image source={{ uri: "http://i.imgur.com/mp79p5T.png" }} width={debugSize} height={debugSize} />
        </NativeLayer>

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
95 96
        <NativeLayer width={debugSize} height={debugSize}>
          <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
97
          <Surface width={debugSize} height={debugSize} backgroundColor="transparent">
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
98 99 100 101 102 103 104 105 106
            <Copy last>
              <Copy>
                <Copy>
                  <Copy>
                    http://i.imgur.com/mp79p5T.png
                  </Copy>
                </Copy>
              </Copy>
            </Copy>
107
          </Surface>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
108 109 110 111
        </NativeLayer>

        <NativeLayer width={debugSize} height={debugSize}>
          <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
112
          <Surface width={debugSize} height={debugSize} backgroundColor="transparent">
113 114 115 116 117 118 119 120 121 122 123
            <Layer>
              http://i.imgur.com/mp79p5T.png
              <TransparentNonPremultiplied>
                <HelloGL />
              </TransparentNonPremultiplied>
            </Layer>
          </Surface>
        </NativeLayer>

        <NativeLayer width={debugSize} height={debugSize}>
          <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
124
          <Surface width={debugSize} height={debugSize} backgroundColor="transparent">
125 126 127 128 129 130 131 132 133 134 135 136 137
            <Layer>
              http://i.imgur.com/mp79p5T.png
              <TransparentNonPremultiplied>
                <Copy>
                  <TransparentNonPremultiplied>
                    <Copy>
                      http://i.imgur.com/S22HNaU.png
                    </Copy>
                  </TransparentNonPremultiplied>
                </Copy>
              </TransparentNonPremultiplied>
            </Layer>
          </Surface>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
138 139
        </NativeLayer>

140 141 142 143
        <Surface width={debugSize} height={debugSize}>
          <HelloGL width={2} height={2} pixelRatio={1} />
        </Surface>

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
144 145 146 147
        <Surface style={{ borderRadius: 50 }} width={debugSize} height={debugSize}>
          <HelloGL />
        </Surface>

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
148 149 150 151 152 153 154
      </View>

    </ScrollView>;
  }
}

module.exports = Tests;