index.js 8.26 KB
Newer Older
1
require("gl-react-core/react-native");
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
2 3 4 5 6 7 8
const React = require("react-native");
const {
  Text,
  View,
  ScrollView,
  Image,
} = React;
9
const { Surface } = require("gl-react-native");
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
const Blur = require("./Blur");
const Add = require("./Add");
const Multiply = require("./Multiply");
const Layer = require("./Layer");
const NativeLayer = require("./NativeLayer");
const HelloGL = require("./HelloGL");
const Display2 = require("./Display2");
const Copy = require("./Copy");
const TransparentNonPremultiplied = require("./TransparentNonPremultiplied");
const { width: viewportW, height: viewportH } = require("Dimensions").get("window");

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 () {

    const debugSize = viewportW / 2;

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

    const txt =
      <View style={{ width: 400, height: 400, position: "relative", backgroundColor: "transparent" }}>
        {[0,1,2,3].map(i => <Text style={{
          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>;

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

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

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

    return <ScrollView style={{ backgroundColor: "#000" }}>
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
      <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
86
        </Display2>
87
      </Surface>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
88 89 90 91 92 93 94 95 96 97

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

        <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>

        <NativeLayer width={debugSize} height={debugSize}>
          <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
98 99
          <Surface width={debugSize} height={debugSize} opaque={false}>
            <Copy last>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
100 101
              http://i.imgur.com/mp79p5T.png
            </Copy>
102
          </Surface>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
103 104 105 106
        </NativeLayer>

        <NativeLayer width={debugSize} height={debugSize}>
          <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
107 108
          <Surface width={debugSize} height={debugSize} opaque={false}>
            <Copy last>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
109 110 111 112
              <Copy>
                http://i.imgur.com/mp79p5T.png
              </Copy>
            </Copy>
113
          </Surface>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
114 115 116 117
        </NativeLayer>

        <NativeLayer width={debugSize} height={debugSize}>
          <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
118 119
          <Surface width={debugSize} height={debugSize} opaque={false}>
            <Copy last>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
120 121 122 123 124 125
              <Copy>
                <Copy>
                  http://i.imgur.com/mp79p5T.png
                </Copy>
              </Copy>
            </Copy>
126
          </Surface>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
127 128 129 130
        </NativeLayer>

        <NativeLayer width={debugSize} height={debugSize}>
          <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
131
          <Surface width={debugSize} height={debugSize} opaque={false}>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
132 133 134 135 136 137 138 139 140
            <Copy last>
              <Copy>
                <Copy>
                  <Copy>
                    http://i.imgur.com/mp79p5T.png
                  </Copy>
                </Copy>
              </Copy>
            </Copy>
141
          </Surface>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
142 143 144 145
        </NativeLayer>

        <NativeLayer width={debugSize} height={debugSize}>
          <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
146 147 148 149 150 151 152 153 154 155 156 157 158
          <Surface width={debugSize} height={debugSize} opaque={false}>
            <Copy last>
              <Copy>
                <Copy>
                  <Copy>
                    <Copy>
                      http://i.imgur.com/mp79p5T.png
                    </Copy>
                  </Copy>
                </Copy>
              </Copy>
            </Copy>
          </Surface>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
159 160 161 162 163 164
        </NativeLayer>

        <NativeLayer width={debugSize} height={debugSize}>
          <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
          <NativeLayer>
            <Image source={{ uri: "http://i.imgur.com/mp79p5T.png" }} width={debugSize} height={debugSize} />
165
            <Surface width={debugSize} height={debugSize}>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
166 167 168
              <TransparentNonPremultiplied>
                <HelloGL />
              </TransparentNonPremultiplied>
169
            </Surface>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
170 171 172 173 174 175 176
          </NativeLayer>
        </NativeLayer>

        <NativeLayer width={debugSize} height={debugSize}>
          <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
          <NativeLayer>
            <Image source={{ uri: "http://i.imgur.com/mp79p5T.png" }} width={debugSize} height={debugSize} />
177 178
            <Surface width={debugSize} height={debugSize}>
              <TransparentNonPremultiplied>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
179
                <TransparentNonPremultiplied>
180
                  <HelloGL />
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
181
                </TransparentNonPremultiplied>
182 183
              </TransparentNonPremultiplied>
            </Surface>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
184 185 186 187 188
          </NativeLayer>
        </NativeLayer>

        <NativeLayer width={debugSize} height={debugSize}>
          <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
189 190 191 192 193 194 195 196 197 198 199 200 201 202
          <NativeLayer>
            <Image source={{ uri: "http://i.imgur.com/mp79p5T.png" }} width={debugSize} height={debugSize} />
            <Surface width={debugSize} height={debugSize}>
              <TransparentNonPremultiplied>
                <Copy>
                  <TransparentNonPremultiplied>
                    <Copy>
                      http://i.imgur.com/S22HNaU.png
                    </Copy>
                  </TransparentNonPremultiplied>
                </Copy>
              </TransparentNonPremultiplied>
            </Surface>
          </NativeLayer>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
203 204 205 206
        </NativeLayer>

        <NativeLayer width={debugSize} height={debugSize}>
          <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
          <Surface width={debugSize} height={debugSize} opaque={false}>
            <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} />
          <Surface width={debugSize} height={debugSize} opaque={false}>
            <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
233 234 235 236 237 238 239 240 241
        </NativeLayer>

      </View>

    </ScrollView>;
  }
}

module.exports = Tests;