Derry Birkett
5 min readApr 9, 2016

--

‘use strict’;
import React, {
AppRegistry,
Component,
StyleSheet
} from ‘react-native’;
var Results = require('./Results');
class jblyrn extends Component {
render() {
return (
<React.NavigatorIOS
style={styles.container}
initialRoute={{
title: 'Github',
component: Results,
}}/>
);
}
}
var styles = React.StyleSheet.create({
container: {
flex: 1
}
});
AppRegistry.registerComponent('jblyrn', () => jblyrn);
'use strict';
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
View,
ListView,
TouchableHighlight,
LinkingIOS
} from 'react-native';
var REQUEST_URL = "https://jobs.github.com/positions.json";
class Results extends Component {
constructor(props) {
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2
}),
loaded: false,
};
}
componentDidMount() {
this.fetchData();
}
fetchData() {
fetch(REQUEST_URL)
.then((response) => response.json())
.then((responseData) => {
console.log(responseData)
this.setState({
dataSource: this.state.dataSource.cloneWithRows(responseData),
loaded: true,
});
})
.done();
}
renderLoadingView() {
return (
<View style={styles.container}>
<Text>
Loading Jobs...
</Text>
</View>
);
}
renderJobs(job) {
return (
<TouchableHighlight onPress={() => { LinkingIOS.openURL(job.url); }}>
<View style={styles.container}>
<Text style={styles.title}>
{job.title}
</Text>
<Text style={styles.location}>
{job.company} - {job.location}
</Text>
</View>
</TouchableHighlight>
);
}
render() 
if(!this.state.loaded) {
return this.renderLoadingView();
}
return (
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderJobs}
style={styles.listView}
/>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
paddingBottom: 30,
paddingTop: 30,
borderBottomWidth: 1,
borderBottomColor: '#eee',
borderStyle: 'solid'
},
title: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
location: {
textAlign: 'center',
color: '#999'
},
listView: {
paddingTop: 20,
backgroundColor: '#F5FCFF',
},
});
module.exports = Results;
I love coffee, so if you liked this article and wish to share happiness consider buying me a coffee! I will be very happy. https://www.paypal.me/derrybirkett/5

--

--

Derry Birkett

Thoughts, stories and ideas from a UX Designer.