-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimageListView.js
143 lines (122 loc) · 4.41 KB
/
imageListView.js
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Implements an image viewer that assumes that the device is always in portrait
mode. Will not respond to device rotation as it only gets the device dims
at render time.
Provides zoom using scroll view.
*/
import React, { PureComponent } from 'react';
import {
StyleSheet,
Text,
View,
Dimensions,
PixelRatio,
ScrollView,
TouchableWithoutFeedback,
TouchableHighlight,
ActionSheetIOS,
CameraRoll
} from 'react-native';
import { ImageCache, CachedImage } from 'react-native-img-cache';
import Icon from 'react-native-vector-icons/FontAwesome';
const BASE_IMAGE_URL = "https://res.cloudinary.com"
const CLOUDINARY_REMOTE_FOLDER = "blink_remote";
const CLOUDINARY_USER_ID = "dkw13vlcj";
const FULL_IMAGE_ASPECT_RATIO = 1.5; // This is the aspect ratio of Canon pro camera images
export default class ImageListView extends PureComponent {
constructor(props) {
super(props);
}
componentDidMount() {
console.log("Mounted image component.");
}
componentWillUnmount(){
console.log("Image view unmounting.");
}
onLoadStart = (imgName) => {
console.log("Loading image " + imgName);
}
onLoadEnd = () => {
console.log("Image loaded." );
}
onPressMore = () => {
}
showMoreActionSheet = () => {
const options = ['Download', 'Share', 'Delete', 'Cancel'];
const destructiveButtonIndex = 2;
const cancelButtonIndex = 3;
// TODO: This only works in IOS - Android uses a different setup, need to check for that here
const that = this;
ActionSheetIOS.showActionSheetWithOptions(
{ options,
cancelButtonIndex,
destructiveButtonIndex,
},
buttonIndex => {
switch(buttonIndex) {
case 0:
that.downloadPhoto();
}
});
}
downloadPhoto = () => {
// TODO: This only works in iOS. Android requires an image download then a save
CameraRoll.saveToCameraRoll(`${BASE_IMAGE_URL}/${CLOUDINARY_USER_ID}/image/upload/${CLOUDINARY_REMOTE_FOLDER}/${this.props.cf}`);
}
getCloudinaryRequestUri(height, width) {
const pixelWidth = PixelRatio.getPixelSizeForLayoutSize(width);
const dimensionCommand = this.props.landscape ? `h_${pixelWidth}` : `w_${pixelWidth}`;
const commandString = `c_scale,${dimensionCommand}`;
return (`${BASE_IMAGE_URL}/${CLOUDINARY_USER_ID}/image/upload/${commandString}/${CLOUDINARY_REMOTE_FOLDER}/${this.props.cf}`);
}
render() {
const { height, width } = Dimensions.get('window');
const imageHeight = width * FULL_IMAGE_ASPECT_RATIO;
var imageStyle = this.props.landscape ?
{ transform: [ { rotate: "90deg" },
{ translateX: (imageHeight - width) / 2 } ],
width: imageHeight, height: width } :
{ width: width, height: width * FULL_IMAGE_ASPECT_RATIO };
return (
<View style={{flexDirection: "column" }}>
<ScrollView
contentContainerStyle={{ flexDirection: "column", alignItems: "center", width: "100%", height: width * FULL_IMAGE_ASPECT_RATIO }}
centerContent={true}
maximumZoomScale={2}
minimumZoomScale={1}
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
>
<TouchableWithoutFeedback onPress={function() {}}>
<CachedImage
style={ imageStyle }
source={ { uri: this.getCloudinaryRequestUri(height, width) } }
onLoadStart={ this.onLoadStart }
onLoadEnd={ this.onLoadEnd }
/>
</TouchableWithoutFeedback>
</ScrollView>
<View style={styles.separator} />
<View style={{ flex: 1, flexDirection: "row", margin: 5 }}>
<View style={{ flex: 1, flexDirection: "row"}}>
<Icon style={{ margin: 5 }} name="heart-o" size={25} color="#484955" />
<Icon style={{ margin: 5, marginLeft: 15 }} name="comment-o" size={25} color="#484955" />
</View>
<View style={{ flex: 2 }} />
<View style={{ flex: 1, flexDirection: "row", justifyContent: "flex-end"}}>
<TouchableHighlight onPress={this.onPressMore}>
<Icon style={{ margin: 5 }} name="ellipsis-h" size={25} color="#484955" onPress={this.showMoreActionSheet} />
</TouchableHighlight>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
separator: {
flex: 1,
height: StyleSheet.hairlineWidth,
backgroundColor: '#8E8E8E',
},
});