-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFullPageView.js
More file actions
106 lines (95 loc) · 2.61 KB
/
FullPageView.js
File metadata and controls
106 lines (95 loc) · 2.61 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
'use strict';
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
ListView,
TouchableHighlight,
} from 'react-native'
import Dimensions from 'Dimensions';
////////////// CONSTANTS and PARAMETERS //////////////
var _height = Dimensions.get('window').height;
var _width = Dimensions.get('window').width;
////////////// HELPERS FUNCTIONS ///////////////////
var URL = function(id) {
return 'https://api.500px.com/v1/photos/' + id + '?consumer_key=wB4ozJxTijCwNuggJvPGtBGCRqaZVcF6jsrzUadF&size3'
}
////////////// MAIN COMPONENT //////////////
class FullPageView extends Component {
constructor(props) {
super(props);
this.state = {
loaded: false, // for tracking initial load
url: '', // add state var for keeping url of an image
};
}
componentDidMount(){
this.fetchPhoto(this.props.image_id);
}
fetchPhoto(id) {
fetch(URL(id))
.then((response) => response.json())
.then((responseData) => {
this.setState({
loaded: true,
url: responseData.photo.image_url, // get url
});
})
.catch(error =>
this.setState({
message: 'Something went wrong ' + error
}))
.done();
}
render() {
if (!this.state.loaded) {
// display nice message while image is loading
return this.renderLoadingView();
}
return (
// click on image and go back to Gallery (well allmost back)
<TouchableHighlight onPress ={() => this.goToGallery()}>
<View style = {styles.container}>
<Image
style = {styles.image}
source = {{uri:this.state.url}} />
</View>
</TouchableHighlight>
);
}
renderLoadingView() {
return (
<View>
<Text style = {styles.loadingText}>
Big picture is being loaded...
</Text>
</View>
);
}
goToGallery() {
this.props.navigator.push({
name:'Gallery',
id: 'gallery'
})
}
}
////////////// STYLES //////////
const styles = StyleSheet.create({
container: {
flex: 1,
},
image: {
width: _height,
height: _height
},
loadingText: {
marginTop: 100,
fontSize: 20,
textAlign: 'center',
},
})
//export module
module.exports = FullPageView;