-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ios.js
executable file
·173 lines (129 loc) · 4.15 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var Assets = require('./Assets.ios');
var Button = require('react-native-button');
var {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TextInput,
View,
ListView,
TouchableHighlight
} = React;
var component = React.createClass({
getInitialState: function() {
return {
dataSource: new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2
}),
imageNumber: DEFAULT_IMAGE_NUMBER,
localImage : DEFAULT_LOCAL_IMAGE
};
},
_onSucessAssetDownload: function(response) {
this.setState({localImage: response.filename});
this._listAssets();
},
_error : function(error){
console.log('error callback ',error);
alert('Error!!',error);
},
_onSucessListAssets: function(arrayFilenames){
this.setState({
dataSource: this.state.dataSource.cloneWithRows(arrayFilenames)
});
},
_onSucessDeleteAsset: function (){
this._listAssets();
},
_dowloadAssest: function(){
var imageUrl = BASE_URL + this.state.imageNumber + '.jpg'
Assets.downloadResourceFromUrl(imageUrl, CACHE_DIR, this._onSucessAssetDownload, this._error);
},
_listAssets: function(){
Assets.listResourcesInCache(CACHE_DIR, this._onSucessListAssets, this._error);
},
_extractFileName: function(filePath){
return filePath.substring(filePath.lastIndexOf("/")+1,filePath.length);
},
_deleteAsset: function (data){
console.log('delete asset',data)
Assets.deleteResourceInCache(data,CACHE_DIR,this._onSucessDeleteAsset)
},
_renderRow: function(rowData: string, sectionID: number, rowID: number) {
var fileName = this._extractFileName(rowData);
var localPath = rowData.replace('file://','');
return (
<View style={ { flexDirection: 'row', justifyContent:'space-between' }} >
<TouchableHighlight onPress={ this._deleteAsset.bind(this, fileName) }>
<Image source={{uri: MINUS_IMAGE.path}}
style={{width: 20, height: 20, resizeMode: 'stretch', alignSelf:'flex-start'}} />
</TouchableHighlight>
<Image source={{uri: localPath}}
style={{width: 80, height: 80, resizeMode: 'stretch'}} />
<Text>{fileName}</Text>
</View>
);
},
render: function() {
return (
<View style={styles.container}>
<Text style={{color: 'black', textAlign: 'left' ,margin:10}} >
BASE URL:
</Text>
<Text style={{color: 'blue', margin:10, flexWrap:'wrap' }} >
{BASE_URL}
</Text>
<View style={ { width:200, flexDirection: 'row', flexWrap:'wrap' } } >
<TextInput
style={{height: 40, width:80, margin:10, borderColor: 'gray', borderWidth: 1, textAlign:'center'}}
onChangeText={(imageNumber) => this.setState({imageNumber})}
defaultValue={DEFAULT_IMAGE_NUMBER}
value={this.state.imageNumber}
/>
<Text style={{color: 'blue', marginTop:20 }} >
.jpg
</Text>
</View>
<Button style={{color: 'black', backgroundColor:'#58ACFA', margin:10}} onPress={this._dowloadAssest}>
Download!!
</Button>
<ListView
style={{margin: 10}}
dataSource={this.state.dataSource}
renderRow={this._renderRow}
/>
</View>
);
}
});
var DEFAULT_LOCAL_IMAGE = require('image!no_image_available')
var MINUS_IMAGE = require('image!minus')
var BASE_URL = 'https://s3.amazonaws.com/99Covers-Facebook-Covers/watermark/';
var DEFAULT_IMAGE_NUMBER = 10;
var CACHE_DIR = 'images';
var styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
margin:10
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('RCTAssetsManager', () => component);