-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathApp.tsx
102 lines (91 loc) · 2.75 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
import React, { useState } from 'react';
import { Button, SafeAreaView, StyleSheet, View } from 'react-native';
import { Dirs } from 'react-native-file-access';
import { CachedImage, CacheManager } from '@georstat/react-native-image-cache';
import {
ImageGallery,
ImageObject,
} from '@georstat/react-native-image-gallery';
import { images } from './helpers';
import Header from './Header';
import Footer from './Footer';
CacheManager.config = {
baseDir: `${Dirs.CacheDir}/images_cache/`,
blurRadius: 15,
sourceAnimationDuration: 1000,
thumbnailAnimationDuration: 1000,
};
const App = () => {
const [isOpen, setIsOpen] = useState(false);
const [isCustomGalleryOpen, setIsCustomGalleryOpen] = useState(false);
const openGallery = () => setIsOpen(true);
const openCustomGallery = () => setIsCustomGalleryOpen(true);
const closeGallery = () => setIsOpen(false);
const closeCustomGallery = () => setIsCustomGalleryOpen(false);
const renderHeaderComponent = (_image: ImageObject, currentIndex: number) => {
return <Header currentIndex={currentIndex} />;
};
const renderFooterComponent = (_image: ImageObject, currentIndex: number) => {
return <Footer total={images.length} currentIndex={currentIndex} />;
};
const renderCustomImage = (image: ImageObject) => {
return (
<View style={styles.customImageContainer}>
<CachedImage
resizeMode="cover"
source={image.url}
style={styles.customImage}
thumbnailSource="https://via.placeholder.com/350x150"
/>
</View>
);
};
return (
<SafeAreaView style={styles.screen}>
<View style={styles.screen}>
<Button onPress={openGallery} title="Open Gallery" />
<Button onPress={openCustomGallery} title="Open Custom Gallery" />
<ImageGallery
close={closeGallery}
images={images}
isOpen={isOpen}
resizeMode="contain"
/>
<ImageGallery
close={closeCustomGallery}
hideThumbs
images={images}
isOpen={isCustomGalleryOpen}
renderCustomImage={renderCustomImage}
renderFooterComponent={renderFooterComponent}
renderHeaderComponent={renderHeaderComponent}
resizeMode="contain"
/>
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
screen: {
alignItems: 'center',
flex: 1,
justifyContent: 'center',
},
customImageContainer: {
alignItems: 'center',
borderRadius: 11,
height: '100%',
justifyContent: 'center',
paddingHorizontal: 24,
width: '100%',
},
customImage: {
borderColor: 'green',
borderRadius: 250,
borderWidth: 3,
height: 300,
overflow: 'hidden',
width: 300,
},
});
export default App;