import React, { Component } from 'react';
import { View, Picker, ActivityIndicator, Button } from 'react-native';
export default class MoviesScreen extends Component {
componentDidMount() {
return fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
// this.handleMoviesResponse(responseJson.movies, 57000); TODO FIXME handle timeout
this.handleMoviesResponse(responseJson.movies);
})
.catch((error) => {
// TODO FIXME replace the red screen with something informative.
console.error(error);
});
}
setMovieState(movies) {
this.setState({
isLoading: false,
dataSource: movies,
});
}
setNearbyTheatersState(theaters) {
this.setState({
isLoading: false,
nearbyTheaters: theaters,
});
}
handleMoviesResponse(movies, delay) {
if (delay && delay > 0) {
const timer = setTimeout(function () {
this.setMovieState(movies);
}.bind(this), delay);
} else {
this.setMovieState(movies);
}
}
handleNearbyTheatersResponse(theaters, delay) {
if (delay && delay > 0) {
const timer = setTimeout(function () {
this.setNearbyTheatersState(theaters);
}.bind(this), delay);
} else {
this.setNearbyTheatersState(theaters);
}
}
handleClick() {
return fetch('https://www.fullstackoasis.com/rnb/theaters.php')
.then((response) => response.json())
.then((responseJson) => {
// TODO FIXME handle timeout / delay
this.handleNearbyTheatersResponse(responseJson);
})
.catch((error) => {
// TODO FIXME replace the red screen with something informative.
console.error(error);
});
}
handleShowTheaterClick() {
const { navigate } = this.props.navigation;
navigate('Maps', {});
}
render() {
if (this.state && !this.state.isLoading) {
let items = [];
var length = this.state.dataSource.length;
for (var i = 0; i < length; i++) {
var item = this.state.dataSource[i];
// Really, really important to not put quotes around these braces:
items.push();
}
var theatersPicker = null;
var goButton = null;
if (this.state.nearbyTheaters) {
let theaters = this.state.nearbyTheaters.map(function (t, i) {
return ;
});
theatersPicker =
this.setState({ theater: itemValue })
}>{theaters}
goButton = ;
}
return
this.setState({ movie: itemValue })
}>
{items}
{theatersPicker}
{goButton}
;
} else {
return (
);
}
}
}