index.js 6.1 KB
Newer Older
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
1
import React from "react";
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
2 3 4
import { Text, View, ScrollView, Image } from "react-native";
import { Surface } from "gl-react-native";
import { Blur } from "gl-react-blur";
5 6 7 8 9 10 11
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";
12 13
import ColoredDisc from "./ColoredDisc";
import DiamondCrop from "./DiamondCrop";
14 15 16
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
17 18

class Tests extends React.Component {
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
19
  constructor(props) {
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
20 21 22 23
    super(props);
    this.onLoad = this.onLoad.bind(this);
    this.onProgress = this.onProgress.bind(this);
  }
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
24
  onLoad() {
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
25 26
    console.log("LOADED");
  }
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
27
  onProgress({ nativeEvent: { progress, loaded, total } }) {
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
28 29
    console.log("PROGRESS", progress, loaded, total);
  }
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
30
  render() {
31
    const debugSize = viewportW / 4;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
32

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
33
    const helloGL = <HelloGL width={64} height={64} />;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
34

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
35 36 37 38
    const txt = (
      <View
        key="txt"
        style={{
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
39
          width: 400,
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
          height: 400,
          position: "relative",
          backgroundColor: "transparent"
        }}
      >
        {[0, 1, 2, 3].map(i =>
          <Text
            key={i}
            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>
    );
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
64

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
65
    const img = "https://i.imgur.com/zJIxPEo.jpg";
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
66

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
67
    const blurredImage = (
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
68 69
      <Blur factor={4} passes={6} width={200} height={200}>
        {img}
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
70 71
      </Blur>
    );
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
72

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
73
    const blurredImageOverText = (
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
74 75 76
      <Layer>
        {blurredImage}
        {txt}
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
      </Layer>
    );

    return (
      <ScrollView style={{ backgroundColor: "#000", flex: 1 }}>
        <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>
108
          </Display2>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
109
        </Surface>
110

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
        <View style={{ flexDirection: "row", flexWrap: "wrap" }}>
          <NativeLayer width={debugSize} height={debugSize}>
            <Image
              key={0}
              source={{ uri: "https://i.imgur.com/S22HNaU.png" }}
              width={debugSize}
              height={debugSize}
            />
            <Image
              key={1}
              source={{ uri: "https://i.imgur.com/mp79p5T.png" }}
              width={debugSize}
              height={debugSize}
            />
          </NativeLayer>

          <NativeLayer width={debugSize} height={debugSize}>
            <Image
              key={0}
              source={{ uri: "https://i.imgur.com/S22HNaU.png" }}
              width={debugSize}
              height={debugSize}
            />
            <Surface
              width={debugSize}
              height={debugSize}
              backgroundColor="transparent"
              setZOrderOnTop
            >
              <Copy last>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
141 142
                <Copy>
                  <Copy>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
143
                    <Copy>https://i.imgur.com/mp79p5T.png</Copy>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
144 145 146
                  </Copy>
                </Copy>
              </Copy>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
            </Surface>
          </NativeLayer>

          <NativeLayer width={debugSize} height={debugSize}>
            <Image
              source={{ uri: "https://i.imgur.com/S22HNaU.png" }}
              width={debugSize}
              height={debugSize}
            />
            <Surface
              width={debugSize}
              height={debugSize}
              backgroundColor="transparent"
              setZOrderOnTop
            >
              <Layer>
                https://i.imgur.com/mp79p5T.png
                <TransparentNonPremultiplied>
                  <HelloGL />
                </TransparentNonPremultiplied>
              </Layer>
            </Surface>
          </NativeLayer>

          <NativeLayer width={debugSize} height={debugSize}>
            <Image
              source={{ uri: "https://i.imgur.com/S22HNaU.png" }}
              width={debugSize}
              height={debugSize}
            />
            <Surface
              width={debugSize}
              height={debugSize}
              backgroundColor="transparent"
              setZOrderOnTop
            >
              <Layer>
                https://i.imgur.com/mp79p5T.png
                <TransparentNonPremultiplied>
                  <Copy>
                    <TransparentNonPremultiplied>
                      <Copy>https://i.imgur.com/S22HNaU.png</Copy>
                    </TransparentNonPremultiplied>
                  </Copy>
                </TransparentNonPremultiplied>
              </Layer>
            </Surface>
          </NativeLayer>
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
195

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
196 197
          <Surface width={debugSize} height={debugSize}>
            <HelloGL width={2} height={2} pixelRatio={1} />
198 199
          </Surface>

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
200 201 202 203 204 205
          <Surface
            style={{ borderRadius: 50 }}
            width={debugSize}
            height={debugSize}
          >
            <HelloGL />
206
          </Surface>
207

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
208 209 210 211 212 213 214 215
          <Surface style={{ margin: 4 }} width={300} height={300}>
            <Blur passes={6} factor={2}>
              https://i.imgur.com/rkiglmm.jpg
            </Blur>
          </Surface>
        </View>
      </ScrollView>
    );
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
216 217 218 219
  }
}

module.exports = Tests;