Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. import React from 'react';
  2. import { Font, AppLoading, Permissions, MapView, BlurView } from "expo";
  3. import { StyleSheet, Text, TouchableOpacity, TouchableHighlight, View } from 'react-native';
  4. import data from './data';
  5. // NOTE: import { StyleSheet } from 'react-native'; is required in this file,
  6. // too, even though it is not used directly here.
  7. import styles from './styles';
  8.  
  9. export default class App extends React.Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. loading: true,
  14. region: null,
  15. };
  16. }
  17.  
  18. async componentDidMount() {
  19. await Font.loadAsync({
  20. 'Raleway': require('./assets/Raleway-Light.ttf')
  21. });
  22. await Permissions.askAsync(Permissions.LOCATION);
  23. this.setState({ loading: false });
  24. }
  25.  
  26. closeMapView = () => this.setState({ region: null });
  27.  
  28. renderMapView = () => (
  29. <View style={styles.topWrapper}>
  30. <BlurView
  31. tint="dark"
  32. intensity={60}
  33. style={[StyleSheet.absoluteFill, styles.blurWrapper]}
  34. >
  35. <View style={styles.mapWrapper}>
  36. <View style={styles.roundedWrapper}>
  37. <MapView style={styles.map} region={this.state.region}>
  38. <MapView.Marker
  39. title="You're here"
  40. coordinate={this.state.region}
  41. pinColor="red"
  42. />
  43. </MapView>
  44. <TouchableOpacity
  45. style={styles.button}
  46. onPress={this.closeMapView}
  47. activeOpacity={1}
  48. >
  49. <Text style={styles.buttonText}>close the map</Text>
  50. </TouchableOpacity>
  51. </View>
  52. </View>
  53. </BlurView>
  54. </View>
  55. );
  56.  
  57. renderCard = (word, country, { latitude, longitude }) => (
  58. <TouchableOpacity
  59. style={styles.card}
  60. onPress={() => this.setState({
  61. region: { latitude, longitude, latitudeDelta: 0.1, longitudeDelta: 0.05 }
  62. })}
  63. >
  64. <Text style={styles.header}>{word}</Text>
  65. <Text style={styles.sub}>{country}</Text>
  66. </TouchableOpacity>
  67. );
  68.  
  69. renderCards = () => (
  70. <View style={styles.container}>
  71. {data.map(({ name, country, region }) => (
  72. <View key={name}>
  73. {this.renderCard(name, country, region)}
  74. </View>
  75. ))}
  76. </View>
  77. );
  78.  
  79. render() {
  80. const { loading, region } = this.state;
  81. if (loading) return <AppLoading />;
  82. return (
  83. <View style={styles.center}>
  84. {region !== null && this.renderMapView()}
  85. <View style={styles.container}>{this.renderCards()}</View>
  86. </View>
  87. );
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement