Skip to content

Instantly share code, notes, and snippets.

@sheki
Created July 20, 2015 03:51
Show Gist options
  • Select an option

  • Save sheki/afab7baef203844d1367 to your computer and use it in GitHub Desktop.

Select an option

Save sheki/afab7baef203844d1367 to your computer and use it in GitHub Desktop.
index.ios.js
'use strict';
var React = require('react-native');
var ScrollView = require('./components/ScrollView');
var {
AppRegistry,
} = React;
AppRegistry.registerComponent('AwesomeProject', () => ScrollView);
'use strict';
var React = require('react-native');
var ParseReact = require('parse-react');
Parse.initialize('O23lje4UAXbWj91T1y3qAMLAMIHx29rDkU2aB9z6', 'cFeJ1DQbXaSbtov0Fwc4TbTlJnfQiikfGwE19S0e');
var {
Image,
ListView,
StyleSheet,
Text,
TouchableHighlight,
View,
} = React;
var API_KEY = '7waqfqbprs7pajbz28mqf6vz';
var API_URL = 'http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json';
var PAGE_SIZE = 25;
var PARAMS = '?apikey=' + API_KEY + '&page_limit=' + PAGE_SIZE;
var REQUEST_URL = API_URL + PARAMS;
var ScrollView = React.createClass({
mixins: [ParseReact.Mixin],
getInitialState: function() {
return {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
}),
loaded: false,
};
},
observe: function() {
return {
comments: (new Parse.Query("Test")).descending("createdAt")
};
},
componentDidMount: function() {
this.fetchData();
},
fetchData: function() {
fetch(REQUEST_URL)
.then((response) => response.json())
.then((responseData) => {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(responseData.movies),
loaded: true,
});
})
.done();
},
render: function() {
if (!this.state.loaded) {
return this.renderLoadingView();
}
console.log(this.data.comments);
return (
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderMovie}
style={styles.listViewRight}
/>
);
},
handlePress : function() {
console.log("halla bol");
},
renderLoadingView: function() {
return (
<View style={styles.container}>
<Text>
Loading movies...
</Text>
</View>
);
},
renderMovie: function(movie) {
return (
<TouchableHighlight onPress={this.handlePress} underlayColor="#dddddd" >
<View style={styles.container}>
<Image
source={{uri: movie.posters.thumbnail}}
style={styles.thumbnail}
/>
<View style={styles.rightContainer}>
<Text style={styles.title}>{movie.title}</Text>
<Text style={styles.year}>{movie.year}</Text>
<Text style={styles.criticsReview}>{movie.ratings.critics_rating}</Text>
</View>
</View>
</TouchableHighlight>
);
},
});
var styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
rightContainer: {
flex: 1,
},
title: {
fontSize: 20,
marginBottom: 8,
textAlign: 'center',
},
year: {
textAlign: 'center',
},
criticsReview: {
textAlign: 'center',
},
thumbnail: {
width: 80,
height: 181,
},
listViewLeft: {
paddingTop: 20,
backgroundColor: '#F5FCFF',
flex:0,
},
listViewRight: {
paddingTop: 20,
backgroundColor: '#FF0000',
flex : 1,
},
});
module.export = ScrollView;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment