Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow
  7. */
  8.  
  9. import React, {Component} from 'react';
  10. import {Platform, StyleSheet, Text, View, Image, TextInput, Button, ToastAndroid} from 'react-native';
  11.  
  12. export default class App extends Component {
  13. constructor(props){
  14. super(props)
  15.  
  16. this.state = {
  17. isLoading: true,
  18. weatherConditions: 'N/A',
  19. temperature: 'N/A',
  20. windSpeed: 'N/A',
  21. currentCity: 'N/A'
  22. }
  23. }
  24.  
  25. componentWillMount() {
  26. fetch('https://api.openweathermap.org/data/2.5/weather?q=tampere&units=metric&appid=6c433438776b5be4ac86001dc88de74d')
  27. .then( response=>response.json())
  28. .then((responseJson) => {
  29. //Kaivetaan haluttu data ja talletetaan stateen
  30. console.log("Temperature" + responseJson.main.temp )
  31. this.setState( {
  32. temperature: responseJson.main.temp,
  33. isLoading: false
  34. });
  35. });
  36.  
  37.  
  38. }
  39.  
  40. render() {
  41. if( this.state.isLoading ){
  42. return(
  43. <Text style={{fontSize: 50}}>Lataa säätietoja..</Text>
  44. );
  45. }
  46. return (
  47. <View style ={{flex: 1, backgroundColor: 'lightgrey'}}>
  48. <Text style={styles.header}>Tampere</Text>
  49. <View style={styles.weather}>
  50. <Image style={styles.weatherIconStyle} source={require('./Images/draw_sunny.png')}></Image>
  51. <Text style={styles.temperatureTextStyle}>{this.state.temperature}</Text>
  52. </View>
  53. <View style={styles.getWeatherArea}>
  54. <TextInput style={styles.textInputStyle} value={"Tampere..."}></TextInput>
  55. <Button style={styles.getWeatherButtonStyle} title="Hae säätiedot"></Button>
  56. </View>
  57.  
  58. <Text>Longitude</Text>
  59. <Text>Latitude</Text>
  60. <Button title="Get by location"></Button>
  61. <Button title="5 day forecast"></Button>
  62. </View>
  63. );
  64. }
  65.  
  66. fetchWeatherDataFromServer() {
  67. // Haetaan data OpenWeatherMap APIsta
  68.  
  69. // Kaivetaan lämötila, tuulen nopeus ja säätila ja
  70. // päivitetää state kutsumalla setState...
  71.  
  72. // => Renderiä kutsutaan automaattisesti
  73.  
  74. }
  75. }
  76.  
  77. const styles = StyleSheet.create({
  78. header: {
  79. height: '15%',
  80. backgroundColor: 'lightblue',
  81. fontSize: 30,
  82. textAlign: 'center',
  83. textAlignVertical: 'center'
  84. },
  85. weather: {
  86. height: '30%',
  87. flexDirection: 'row',
  88. borderWidth: 0.5,
  89. borderColor: 'black'
  90. },
  91. getWeatherArea: {
  92. flexDirection: 'row',
  93. borderWidth: 0.5,
  94. borderColor: 'black'
  95. },
  96. weatherIconStyle: {
  97. height: '100%',
  98. flex: 1,
  99. resizeMode: 'stretch'
  100. },
  101. temperatureTextStyle: {
  102. height: '100%',
  103. flex: 1,
  104. fontSize: 50,
  105. textAlign: 'center',
  106. textAlignVertical: 'center'
  107. },
  108. textInputStyle: {
  109. flex: 6,
  110. fontSize: 30
  111. },
  112. getWeatherButtonStyle: {
  113. color: "#841584",
  114. flex: 4
  115. },
  116. container: {
  117. flex: 1,
  118. flexDirection: 'row',
  119. alignItems: 'center',
  120. justifyContent: 'center',
  121. },
  122. buttonContainer: {
  123. flex: 1
  124. }
  125.  
  126. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement