forked from expo/react-native-image-gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
156 lines (134 loc) · 3.85 KB
/
main.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
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* Sample image gallery app
*/
import React, { Component } from 'react';
import {
AppRegistry,
Image,
Platform,
ScrollView,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
import Immutable from 'immutable';
import Actions from 'Actions';
import Layout from 'Layout';
import ImageGallery from 'ImageGallery';
import ExampleStore from 'ExampleStore';
class ListItem extends Component {
_openInImageGallery = () => {
let { list, item } = this.props;
this._view.measure((rx, ry, w, h, x, y) => {
ExampleStore.dispatch(Actions.openImageGallery({
animationMeasurements: {w, h, x, y},
list,
item,
}));
});
};
render() {
let { list, item } = this.props;
let width = item.getIn(['asset', 'width']);
let height = item.getIn(['asset', 'height']);
let targetWidth = 200.0;
let multiplier = targetWidth/width;
let targetHeight = multiplier * height;
return (
<TouchableOpacity
style={{marginBottom: 20}}
onPress={this._openInImageGallery}>
<Image
ref={view => { this._view = view }}
source={{uri: item.get('image_url')}}
style={{width: targetWidth, height: targetHeight}} />
</TouchableOpacity>
);
}
}
class FakeContent extends Component {
render() {
return (
<View style={{flex: 1, paddingTop: Platform.OS === 'android' ? 20 : 40, paddingBottom: Platform.OS === 'android' ? 10 : 0}}>
<View style={{paddingBottom: 10, borderBottomColor: '#eee', borderBottomWidth: 1, alignItems: 'center'}}>
<Text style={{fontSize: 20, marginLeft: 10}}>My favourite cats</Text>
</View>
<ScrollView style={{flex: 1}} contentContainerStyle={{alignItems: 'center', paddingTop: 20}}>
{list.get('items').map(item => <ListItem key={item.get('id')} list={list} item={item} />)}
</ScrollView>
</View>
);
}
}
class ImageGalleryExample extends Component {
render() {
return (
<View style={{flex: 1}}>
<View style={styles.container}>
<FakeContent />
</View>
<ImageGallery store={ExampleStore} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
const list = Immutable.fromJS({
items: [
{
id: 'a',
description: 'This cat is orange! An orange cat! Its eyes are olive though.',
image_url: 'https://s3-us-west-2.amazonaws.com/examples-exp/image-gallery/cat1.jpg',
asset: {
width: 632,
height: 475,
type: 'static',
cover: {
uri: 'https://s3-us-west-2.amazonaws.com/examples-exp/image-gallery/cat1.jpg',
}
}
},
{
id: 'b',
image_url: 'https://s3-us-west-2.amazonaws.com/examples-exp/image-gallery/cat2.jpg',
description: 'Look at this cat catching a mouse. Notice that "catch" includes the word "cat". Coincidence?',
asset: {
width: 1000,
height: 764,
type: 'static',
cover: {
uri: 'https://s3-us-west-2.amazonaws.com/examples-exp/image-gallery/cat2.jpg',
}
}
},
{
id: 'c',
image_url: 'https://s3-us-west-2.amazonaws.com/examples-exp/image-gallery/cat3.png',
description: 'This cat is eating a banana, while dressed as a monkey. Silly cat, you are a cat not a monkey! Congrats on going vegetarian though, be sure to take your b12',
asset: {
width: 785,
height: 785,
type: 'static',
cover: {
uri: 'https://s3-us-west-2.amazonaws.com/examples-exp/image-gallery/cat3.png',
}
}
}
],
});
AppRegistry.registerComponent('ImageGalleryExample', () => ImageGalleryExample);