Skip to content

Commit 1c80580

Browse files
committed
first commit
0 parents  commit 1c80580

File tree

16 files changed

+8513
-0
lines changed

16 files changed

+8513
-0
lines changed

.expo-shared/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
> Why do I have a folder named ".expo-shared" in my project?
2+
3+
The ".expo-shared" folder is created when running commands that produce state that is intended to be shared with all developers on the project. For example, "npx expo-optimize".
4+
5+
> What does the "assets.json" file contain?
6+
7+
The "assets.json" file describes the assets that have been optimized through "expo-optimize" and do not need to be processed again.
8+
9+
> Should I commit the ".expo-shared" folder?
10+
11+
Yes, you should share the ".expo-shared" folder with your collaborators.

.expo-shared/assets.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true,
3+
"40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true
4+
}

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
node_modules/
2+
.expo/
3+
npm-debug.*
4+
*.jks
5+
*.p8
6+
*.p12
7+
*.key
8+
*.mobileprovision
9+
*.orig.*
10+
web-build/
11+
12+
# macOS
13+
.DS_Store

App.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { StatusBar } from 'expo-status-bar'
2+
import React, { useEffect, useState } from 'react'
3+
import { StyleSheet, Text, View, ActivityIndicator } from 'react-native'
4+
import * as Location from 'expo-location'
5+
import WeatherInfo from './components/WeatherInfo'
6+
import UnitsPicker from './components/UnitsPicker'
7+
import ReloadIcon from './components/ReloadIcon'
8+
import WeatherDetails from './components/WeatherDetails'
9+
// import { WEATHER_API_KEY } from 'react-native-dotenv'
10+
11+
const WEATHER_API_KEY = "a68f42df5bf8a407c62860303949d442";
12+
const BASE_WEATHER_URL = "https://api.openweathermap.org/data/2.5/weather?";
13+
14+
export default function App() {
15+
const [errorMessage, setErrorMessage] = useState(null)
16+
const [currentWeather, setCurrentWeather] = useState(null)
17+
const [unitsSystem, setUnitsSystem] = useState('metric')
18+
19+
useEffect(() => {
20+
load()
21+
}, [unitsSystem])
22+
23+
async function load() {
24+
setCurrentWeather(null)
25+
setErrorMessage(null)
26+
try {
27+
let { status } = await Location.requestForegroundPermissionsAsync()
28+
29+
if (status !== 'granted') {
30+
setErrorMessage('Access to location is needed to run the app')
31+
return
32+
}
33+
const location = await Location.getCurrentPositionAsync()
34+
35+
const { latitude, longitude } = location.coords
36+
37+
const weatherUrl = `${BASE_WEATHER_URL}lat=${latitude}&lon=${longitude}&units=${unitsSystem}&appid=${WEATHER_API_KEY}`
38+
39+
const response = await fetch(weatherUrl)
40+
41+
const result = await response.json()
42+
43+
if (response.ok) {
44+
setCurrentWeather(result)
45+
} else {
46+
setErrorMessage(result.message)
47+
}
48+
} catch (error) {
49+
setErrorMessage(error.message)
50+
}
51+
}
52+
if (currentWeather) {
53+
return (
54+
<View style={styles.container}>
55+
<StatusBar style="auto" />
56+
<View style={styles.main}>
57+
<UnitsPicker unitsSystem={unitsSystem} setUnitsSystem={setUnitsSystem} />
58+
<ReloadIcon load={load} />
59+
<WeatherInfo currentWeather={currentWeather} />
60+
</View>
61+
<WeatherDetails currentWeather={currentWeather} unitsSystem={unitsSystem} />
62+
</View>
63+
)
64+
} else if (errorMessage) {
65+
return (
66+
<View style={styles.container}>
67+
<ReloadIcon load={load} />
68+
<Text style={{ textAlign: 'center' }}>{errorMessage}</Text>
69+
<StatusBar style="auto" />
70+
</View>
71+
)
72+
} else {
73+
return (
74+
<View style={styles.container}>
75+
<ActivityIndicator size="large" color="#30acff" />
76+
<StatusBar style="auto" />
77+
</View>
78+
)
79+
}
80+
}
81+
82+
const styles = StyleSheet.create({
83+
container: {
84+
flex: 1,
85+
justifyContent: 'center',
86+
},
87+
main: {
88+
justifyContent: 'center',
89+
flex: 1,
90+
},
91+
})

app.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"expo": {
3+
"name": "weather-rn",
4+
"slug": "weather-rn",
5+
"version": "1.0.0",
6+
"orientation": "portrait",
7+
"icon": "./assets/icon.png",
8+
"splash": {
9+
"image": "./assets/splash.png",
10+
"resizeMode": "contain",
11+
"backgroundColor": "#ffffff"
12+
},
13+
"updates": {
14+
"fallbackToCacheTimeout": 0
15+
},
16+
"assetBundlePatterns": ["**/*"],
17+
"ios": {
18+
"supportsTablet": true
19+
},
20+
"android": {
21+
"adaptiveIcon": {
22+
"foregroundImage": "./assets/adaptive-icon.png",
23+
"backgroundColor": "#FFFFFF"
24+
},
25+
"package": "weatherdev.ahmedsamir.weather"
26+
},
27+
"web": {
28+
"favicon": "./assets/favicon.png"
29+
},
30+
"description": ""
31+
}
32+
}

assets/adaptive-icon.png

63.3 KB
Loading

assets/favicon.ico

112 KB
Binary file not shown.

assets/icon.png

44.6 KB
Loading

assets/splash.png

42.2 KB
Loading

babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function(api) {
2+
api.cache(true);
3+
return {
4+
presets: ['babel-preset-expo'],
5+
};
6+
};

0 commit comments

Comments
 (0)