-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathApp.tsx
128 lines (119 loc) · 3.37 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
* Copyright (c) JOB TODAY S.A. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import React, { useState } from "react";
import {
Alert,
Platform,
SafeAreaView,
StatusBar,
StyleSheet,
Text,
View,
} from "react-native";
import get from "lodash/get";
import memoize from "lodash/memoize";
import ImageViewing from "../src/ImageViewing";
import ImageList from "./components/ImageList";
import ImageHeader from "./components/ImageHeader";
import ImageFooter from "./components/ImageFooter";
import { architecture } from "./data/architecture";
import { travel } from "./data/travel";
import { city } from "./data/city";
import { food } from "./data/food";
import { ImageSource } from "../src/@types";
export default function App() {
const [currentImageIndex, setImageIndex] = useState(0);
const [images, setImages] = useState(architecture);
const [isVisible, setIsVisible] = useState(false);
const onSelect = (images, index) => {
setImageIndex(index);
setImages(images);
setIsVisible(true);
};
const onRequestClose = () => setIsVisible(false);
const getImageSource = memoize((images): ImageSource[] =>
images.map((image) =>
typeof image.original === "number"
? image.original
: { uri: image.original as string }
)
);
const onLongPress = (image) => {
Alert.alert("Long Pressed", image.uri);
};
return (
<SafeAreaView style={styles.root}>
<ImageList
images={travel.map((image) => image.thumbnail)}
onPress={(index) => onSelect(travel, index)}
shift={0.25}
/>
<ImageList
images={architecture.map((image) => image.thumbnail)}
onPress={(index) => onSelect(architecture, index)}
shift={0.75}
/>
<View style={styles.about}>
<Text style={styles.name}>[ react-native-image-viewing ]</Text>
</View>
<ImageViewing
images={getImageSource(images)}
imageIndex={currentImageIndex}
presentationStyle="overFullScreen"
visible={isVisible}
onRequestClose={onRequestClose}
onLongPress={onLongPress}
HeaderComponent={
images === travel
? ({ imageIndex }) => {
const title = get(images, `${imageIndex}.title`);
return (
<ImageHeader title={title} onRequestClose={onRequestClose} />
);
}
: undefined
}
FooterComponent={({ imageIndex }) => (
<ImageFooter imageIndex={imageIndex} imagesCount={images.length} />
)}
/>
<ImageList
images={food.map((image) => image.thumbnail)}
onPress={(index) => onSelect(food, index)}
shift={0.5}
/>
<ImageList
images={city.map((image) => image.thumbnail)}
onPress={(index) => onSelect(city, index)}
shift={0.75}
/>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
root: {
flex: 1,
backgroundColor: "#000",
...Platform.select({
android: { paddingTop: StatusBar.currentHeight },
default: null,
}),
},
about: {
flex: 1,
marginTop: -12,
alignItems: "center",
justifyContent: "center",
},
name: {
textAlign: "center",
fontSize: 24,
fontWeight: "200",
color: "#FFFFFFEE",
},
});