-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
160 lines (139 loc) · 2.91 KB
/
index.ios.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
//CameraRoll应用
var React = require('react-native');
var{
AppRegistry,
CameraRoll,
Image,
ListView,
StyleSheet,
View,
Text,
ScrollView
} = React;
//获取图片的参数设置
var fetchParams = {
first : 4,
groupTypes: 'All',
assetType: 'Photos'
};
var imgUrl = 'http://vczreo.github.io/lvtu/img/';
var app = React.createClass({
getInitialState: function(){
return{
photos: null
};
},
render: function(){
var photos = this.state.photos || [];
var photosView = [];
for(var i = 0; i < 4; i += 2){
photosView.push(
<View style={styles.row}>
<View style={styles.flex_1}>
<Image resizeMode="stretch"
style={[styles.imgHeight,styles.m5]}
source={{uri:photos[i]}}/>
</View>
<View style={styles.flex_1}>
<Image resizeMode="stretch"
style={[styles.imgHeight,styles.m5]}
source={{uri:photos[parseInt(i) + 1]}}/>
</View>
</View>
);
}
return(
<ScrollView>
<View style={styles.row}>
<View style={styles.flex_1}>
<Image resizeMode="stretch"
style={[styles.imgHeight,styles.m5]}
source={{uri: imgUrl + 'city.jpg'}}/>
</View>
<View style={styles.flex_1}>
<Image resizeMode="stretch"
style={[styles.imgHeight,styles.m5]}
source={{uri:imgUrl + '3.jpeg'}}/>
</View>
</View>
<View>
<Text onPress={this.saveImg.bind(this,'city.jpg','3.jpeg')}
style={styles.saveImg}>保存图片到相册</Text>
</View>
<View style={[{marginTop:20}]}>
{photosView}
</View>
</ScrollView>
);
},
componentDidMount: function(){
var _that = this;
CameraRoll.getPhotos(fetchParams,function(data){
console.log(data);
var edges = data.edges;
var photos= [];
for(var i in edges){
photos.push(edges[i].node.image.uri);
}
_that.setState({
photos: photos
});
},function(){
alert('获取照片失败');
});
},
saveImg: function(img1,img2){
var _that = this;
CameraRoll.saveImageWithTag(imgUrl + img1,function(url){
if (url) {
var photos = _that.state.photos;
photos.unshift(url);
_that.setState({
photos: photos
});
CameraRoll.saveImageWithTag(imgUrl+ img2,function(url){
photos,unshift(url);
_that.setState({
photos: photos
});
alert('保存图片成功');
},function(){
alert('保存图片失败');
});
}
},function(){
alert('保存图片失败');
});
}
});
var styles = StyleSheet.create({
flex_1:{
flex: 1
},
m5: {
marginLeft: 5,
marginRight: 5,
borderWidth: 1,
borderColor: '#ddd'
},
row: {
flexDirection: 'row'
},
imgHeight: {
height: 120
},
saveImg: {
flex: 1,
height: 30,
textAlign : 'center',
marginTop: 20,
backgroundColor: '#3BC1FF',
color: '#FFF',
lineHeight: 20,
borderRadius:5,
marginLeft: 5,
marginRight: 5,
fontWeight: 'bold'
}
});
AppRegistry.registerComponent('app', () => app);