Skip to content

Commit 9005165

Browse files
added example
1 parent 64cbe41 commit 9005165

File tree

6 files changed

+5780
-0
lines changed

6 files changed

+5780
-0
lines changed

example/App.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// eslint-disable-next-line import/default
2+
import React, { useState } from 'react';
3+
import { Dimensions, Image, StyleSheet, TouchableOpacity, View } from 'react-native';
4+
import { Blurhash } from 'gl-react-blurhash';
5+
import { Surface } from 'gl-react-expo';
6+
7+
const screenWidth = Math.round(Dimensions.get('window').width);
8+
9+
const styles = StyleSheet.create({
10+
container: {
11+
flex: 1,
12+
backgroundColor: '#fff',
13+
alignItems: 'center',
14+
justifyContent: 'center'
15+
},
16+
image: {
17+
width: screenWidth * 0.8,
18+
height: (screenWidth * 0.8) / 1.5
19+
}
20+
});
21+
22+
const data = {
23+
hash: 'LPKA$w{H_c05b{Nqwbx^grotMnNf',
24+
uri:
25+
'https://images.pexels.com/photos/1209843/pexels-photo-1209843.jpeg?crop=entropy&cs=srgb&dl=person-with-body-painting-1209843.jpg&fit=crop&fm=jpg&h=853&w=1280'
26+
};
27+
28+
function ImageWithBlurhash({ blurhashVisible }: { blurhashVisible: boolean }) {
29+
if (blurhashVisible) {
30+
return (
31+
<Surface style={styles.image}>
32+
<Blurhash hash={data.hash} />
33+
</Surface>
34+
);
35+
}
36+
return <Image source={{ uri: data.uri }} style={styles.image}></Image>;
37+
}
38+
39+
export default function App() {
40+
const [blurhashVisible, setBlurhashVisible] = useState(true);
41+
const onPress = () => setBlurhashVisible(!blurhashVisible);
42+
return (
43+
<View style={styles.container}>
44+
<TouchableOpacity onPress={onPress}>
45+
<ImageWithBlurhash blurhashVisible={blurhashVisible} />
46+
</TouchableOpacity>
47+
</View>
48+
);
49+
}

example/app.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"expo": {
3+
"name": "gl-blurhash-example",
4+
"slug": "gl-blurhash-example",
5+
"platforms": ["ios", "android", "web"],
6+
"version": "1.0.0",
7+
"orientation": "portrait",
8+
"updates": {
9+
"fallbackToCacheTimeout": 0
10+
},
11+
"assetBundlePatterns": ["**/*"],
12+
"ios": {
13+
"supportsTablet": true
14+
}
15+
}
16+
}

example/babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function (api) {
2+
api.cache(true);
3+
return {
4+
presets: ['babel-preset-expo']
5+
};
6+
};

example/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"main": "node_modules/expo/AppEntry.js",
3+
"scripts": {
4+
"start": "expo start",
5+
"android": "expo start --android",
6+
"ios": "expo start --ios",
7+
"web": "expo start --web",
8+
"eject": "expo eject"
9+
},
10+
"dependencies": {
11+
"@types/gl-react-expo": "^3.16.2",
12+
"buffer": "^5.6.0",
13+
"expo": "~37.0.3",
14+
"expo-gl": "^8.2.0",
15+
"gl-react": "^4.0.1",
16+
"gl-react-blurhash": "latest",
17+
"gl-react-expo": "^4.0.1",
18+
"react": "~16.9.0",
19+
"react-dom": "~16.9.0",
20+
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
21+
"react-native-screens": "~2.2.0",
22+
"react-native-web": "~0.11.7"
23+
},
24+
"devDependencies": {
25+
"@babel/core": "^7.8.6",
26+
"@types/react": "~16.9.23",
27+
"@types/react-native": "~0.61.17",
28+
"babel-preset-expo": "~8.1.0",
29+
"typescript": "~3.8.3"
30+
},
31+
"private": true
32+
}

example/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true,
4+
"jsx": "react-native",
5+
"lib": ["dom", "esnext"],
6+
"moduleResolution": "node",
7+
"noEmit": true,
8+
"skipLibCheck": true,
9+
"resolveJsonModule": true,
10+
"strict": true
11+
}
12+
}

0 commit comments

Comments
 (0)