index.ios.js 6.81 KB
Newer Older
1 2 3 4 5 6
const React = require("react-native");
const {
  AppRegistry,
  StyleSheet,
  Text,
  View,
7 8
  Image,
  TextInput,
9
  ScrollView,
10
  SliderIOS,
11 12 13
  SwitchIOS,
  ProgressViewIOS,
  ActivityIndicatorIOS,
14 15 16
} = React;

const HelloGL = require("./HelloGL");
17 18
const Saturation = require("./Saturation");
const HueRotate = require("./HueRotate");
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
19 20 21
const PieProgress = require("./PieProgress");
const OneFingerResponse = require("./OneFingerResponse");
const AnimatedHelloGL = require("./AnimatedHelloGL");
22
const Blur = require("./Blur");
23
const Button = require("./Button");
24 25 26 27 28 29 30

class Simple extends React.Component {
  constructor (props) {
    super(props);
    this.state = {
      saturationFactor: 1,
      hue: 0,
31 32
      progress: 0,
      factor: 0,
33 34 35 36
      text: "and I will return leading the pack",
      switch1: false,
      switch2: false,
      switch3: false,
37
      captured: null
38
    };
39 40 41 42 43 44 45
    this.onCapture1 = this.onCapture1.bind(this);
  }

  onCapture1 () {
    this.refs.helloGL.captureFrame(data64 => {
      this.setState({ captured: data64 });
    });
46 47 48 49 50 51
  }

  render () {
    const {
      saturationFactor,
      hue,
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
52
      text,
53
      progress,
54 55 56 57
      factor,
      switch1,
      switch2,
      switch3,
58
      captured
59
    } = this.state;
60 61 62 63 64 65

    return <ScrollView style={styles.container}>
      <Text style={styles.title}>
        Welcome to GL React Native!
      </Text>
      <View style={styles.demos}>
66

67 68
        <Text style={styles.demoTitle}>1. Hello GL</Text>
        <View style={styles.demo}>
69 70 71 72 73
          <HelloGL width={256} height={171} ref="helloGL" />
          <View style={{ paddingTop: 20, alignItems: "center", flexDirection: "row" }}>
            <Button onPress={this.onCapture1}>captureFrame()</Button>
            {captured && <Image source={{ uri:captured }} style={{ marginLeft: 20, width: 51, height: 34 }} />}
          </View>
74 75
        </View>

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
76
        <Text style={styles.demoTitle}>2. Saturate an Image</Text>
77
        <View style={styles.demo}>
78
          <Saturation
79
            width={256}
80 81 82 83 84 85 86 87
            height={171}
            factor={saturationFactor}
            image={{ uri: "http://i.imgur.com/iPKTONG.jpg" }}
          />
        <SliderIOS
          maximumValue={8}
          onValueChange={saturationFactor => this.setState({ saturationFactor })}
        />
88
        </View>
89

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
90
        <Text style={styles.demoTitle}>3. Hue Rotate on Text+Image</Text>
91 92
        <View style={styles.demo}>
          <HueRotate
93
            autoRedraw
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
            width={256}
            height={180}
            hue={hue}>
            <Image style={{ width: 256, height: 244 }} source={{ uri: "http://i.imgur.com/qVxHrkY.jpg" }}/>
            <Text style={styles.demoText1}>Throw me to the wolves</Text>
            <Text style={styles.demoText2}>{text}</Text>
          </HueRotate>
          <SliderIOS
            maximumValue={2 * Math.PI}
            onValueChange={hue => this.setState({ hue })}
          />
          <TextInput
            style={{ height: 30, borderColor: "#aaa", borderWidth: 1 }}
            onChangeText={text => this.setState({ text })}
            value={text}
          />
        </View>

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
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
        <Text style={styles.demoTitle}>4. Progress Indicator</Text>
        <View style={styles.demo}>
          <PieProgress
            width={256}
            height={180}
            progress={progress}
          />
          <SliderIOS
            onValueChange={progress => this.setState({ progress })}
          />
        </View>

        <Text style={styles.demoTitle}>5. Touch Responsive</Text>
        <View style={styles.demo}>
          <OneFingerResponse
            width={256}
            height={180}
          />
        </View>

        <Text style={styles.demoTitle}>6. Animation</Text>
        <View style={styles.demo}>
          <AnimatedHelloGL
            width={256}
            height={180}
          />
        </View>

140 141 142 143 144 145 146 147 148 149
        <Text style={styles.demoTitle}>7. Blur (2-pass)</Text>
        <View style={styles.demo}>
          <Blur width={256} height={180} factor={factor}>
            http://i.imgur.com/3On9QEu.jpg
          </Blur>
          <SliderIOS
            maximumValue={2}
            onValueChange={factor => this.setState({ factor })} />
        </View>

150

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
151
        <Text style={styles.demoTitle}>8. Blur+Hue over UI</Text>
152
        <View style={styles.demo}>
153 154
          <HueRotate
            hue={-switch1 + 2 * switch2 + 4 * switch3}
155 156
            width={256}
            height={160}
157 158 159
            autoRedraw
            eventsThrough
            visibleContent>
160 161 162
            <Blur
              width={256}
              height={160}
163 164 165 166 167
              factor={factor}>
              <Blur
                width={256}
                height={160}
                factor={factor/2}>
168 169 170 171 172 173 174 175 176 177 178 179 180 181
                <View style={{ width: 256, height: 160, padding: 10 }}>
                  <SliderIOS
                    style={{ height: 80 }}
                    maximumValue={2}
                    onValueChange={factor => this.setState({ factor })}
                  />
                <View style={{ height: 60, flexDirection: "row", alignItems: "center" }}>
                  <SwitchIOS style={{flex:1}} value={switch1} onValueChange={switch1 => this.setState({ switch1 })} />
                  <SwitchIOS style={{flex:1}} value={switch2} onValueChange={switch2 => this.setState({ switch2 })} />
                  <SwitchIOS style={{flex:1}} value={switch3} onValueChange={switch3 => this.setState({ switch3 })} />
                </View>
                <ProgressViewIOS progress={factor} style={{height: 10, marginTop: 8, flex:1}} />

                </View>
182
              </Blur>
183
            </Blur>
184
          </HueRotate>
185 186
        </View>

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
187 188 189 190 191
        <Text style={styles.demoTitle}>9. Texture from array</Text>
        <View style={styles.demo}>
          <Text>Not Supported Yet</Text>
        </View>

192 193 194
      </View>
    </ScrollView>;
  }
195
}
196 197 198 199

const styles = StyleSheet.create({
  container: {
    flex: 1,
200
    backgroundColor: "#F9F9F9",
201 202 203 204 205 206 207 208 209 210 211
  },
  title: {
    fontSize: 20,
    textAlign: "center",
    margin: 5,
    marginBottom: 20,
    fontWeight: "bold"
  },
  demos: {
    flex: 1,
    justifyContent: "center",
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
212 213 214
    marginLeft: 40,
    width: 276,
    marginBottom: 40,
215 216
  },
  demoTitle: {
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
217 218 219 220 221
    marginBottom: 16,
    fontStyle: "italic",
    alignSelf: "flex-start",
    color: "#999",
    fontWeight: "300",
222
    fontSize: 20,
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
223 224 225 226
  },
  demo: {
    marginBottom: 64,
    marginLeft: 20,
227
  },
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
  demoText1: {
    position: "absolute",
    top: 0,
    left: 0,
    width: 256,
    textAlign: "center",
    color: "#f16",
    backgroundColor: "transparent",
    fontWeight: "400",
    fontSize: 24,
    letterSpacing: 0
  },
  demoText2: {
    position: "absolute",
    bottom: 4,
    left: 0,
    width: 256,
    textAlign: "center",
    color: "#7bf",
    backgroundColor: "transparent",
    fontWeight: "300",
    fontSize: 32,
    letterSpacing: -1
  },
252 253 254
});

AppRegistry.registerComponent("Simple", () => Simple);