-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
126 lines (120 loc) · 2.91 KB
/
App.js
File metadata and controls
126 lines (120 loc) · 2.91 KB
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
import { Permissions } from "expo";
import React from "react";
import {
StyleSheet,
FlatList,
Dimensions,
CameraRoll,
Image,
TouchableHighlight,
View,
ViewPagerAndroid,
BackHandler
} from "react-native";
export default class App extends React.Component {
state = {
images: [],
isPhotoFullScreen: false,
selectedImage: null,
access: false
};
componentDidMount() {
Permissions.askAsync(Permissions.CAMERA_ROLL)
.then(res => {
console.log("Access: " + res.status);
return CameraRoll.getPhotos({
first: 1000,
assetType: "Photos"
})
.then(r => {
this.setState({ images: r.edges });
})
.catch(err => {
console.log(err);
});
})
.catch(res => console.log("Access: " + res.status));
BackHandler.addEventListener("hardwareBackPress", () => {
if (this.state.isPhotoFullScreen) {
this.onClose();
return true;
}
});
}
onOpen = index => {
this.setState({
isPhotoFullScreen: true,
selectedImage: index
});
};
onClose = () =>
this.setState({ isPhotoFullScreen: false, selectedImage: null });
render() {
return (
<>
{this.state.isPhotoFullScreen ? (
<ViewPagerAndroid
style={styles.background}
initialPage={this.state.selectedImage}
pageMargin={20}
>
{this.state.images.map((item, i) => (
<View key={i}>
<TouchableHighlight
style={styles.container}
onPress={this.onClose}
>
<Image
style={styles.fullSreen}
resizeMode="contain"
source={{ uri: item.node.image.uri }}
/>
</TouchableHighlight>
</View>
))}
</ViewPagerAndroid>
) : (
<FlatList
data={this.state.images}
keyExtractor={(item, i) => i}
style={styles.container}
renderItem={({ item, index }) => (
<TouchableHighlight
style={styles.item}
onPress={() => this.onOpen(index)}
>
<View>
<Image
style={styles.item}
source={{ uri: item.node.image.uri }}
/>
</View>
</TouchableHighlight>
)}
numColumns={3}
/>
)}
</>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
item: {
marginBottom: 1,
marginRight: 1,
height: Dimensions.get("window").width / 3,
width: Dimensions.get("window").width / 3
},
background: {
backgroundColor: "black",
flex: 1
},
fullSreen: {
flex: 1,
height: undefined,
width: undefined
}
});