Skip to content

Commit adf7ebf

Browse files
committed
Refactor Weather component and add UVIndex component
1 parent 99fcd06 commit adf7ebf

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/screens/Weather/Main/Weather.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import { useDerivedValue, useSharedValue, withTiming } from 'react-native-reanim
1212
import { useSafeAreaInsets } from 'react-native-safe-area-context'
1313
import { getWeather } from '../api'
1414
import type { Weather } from '../types'
15+
import { calculatePressurePercentage, getVisibilityStatusString } from '../utils'
1516
import DailyForecast from './components/DailyForecast'
1617
import FeelsLike, { getFeelsLikeStatusString } from './components/FeelsLike'
1718
import Header from './components/Header'
1819
import HourlyForecast from './components/HourlyForecast'
1920
import Humidity from './components/Humidity'
2021
import Pressure from './components/Pressure'
21-
import { calculatePressurePercentage } from '../utils'
2222
import Visibility from './components/Visibility'
23-
import { getVisibilityStatusString } from '../utils'
2423
import WeatherTopInfo from './components/WeatherTopInfo'
24+
import UVIndex from './components/UVIndex'
2525

2626
export default function WeatherScreen({ navigation }: NavProp) {
2727
const { currentCity, lastUpdated, currentWeather, setCurrentWeather, setLastUpdated, weatherCacheTime } =
@@ -115,6 +115,7 @@ function Boxes({ w, theme }: { w: Weather; theme: Theme }) {
115115
visibility={(w?.current.visibility || 0) / 1000 + ' km'}
116116
visibilityStatus={visibilityStatus}
117117
/>
118+
<UVIndex uvIndex={w?.current.uvi || 0} theme={theme} />
118119
</View>
119120
)
120121
}

src/screens/Weather/Main/components/Pressure.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export default function Pressure({ theme, pressure, percent }: { theme: Theme; p
1717
<GradientPath theme={theme} percent={percent} />
1818
<View style={StyleSheet.absoluteFill} className='items-center justify-center'>
1919
<Medium style={[{ fontSize: 15 }, theme.color]}>{pressure}</Medium>
20-
<Regular className='text-xs'>{unit}</Regular>
20+
<Regular className='text-xs' style={theme.color}>
21+
{unit}
22+
</Regular>
2123
</View>
2224
</View>
2325
</View>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Sun03SolidIcon } from '@assets/icons/icons'
2+
import { boxSize } from '@screens/Weather/utils'
3+
import { F, Medium, Regular } from '@utils/fonts'
4+
import type { Theme } from '@utils/types'
5+
import React from 'react'
6+
import { View } from 'react-native'
7+
import WeatherLabel from './WeatherLabel'
8+
9+
export default function UVIndex({ uvIndex, theme }: { uvIndex: number; theme: Theme }) {
10+
let uviPercent = (uvIndex * 100) / 11
11+
uviPercent = uviPercent > 100 ? 100 : uviPercent
12+
13+
return (
14+
<View className='aspect-square rounded-3xl bg-black/10' style={boxSize}>
15+
<WeatherLabel Icon={Sun03SolidIcon} color={theme.color} label='UV Index' />
16+
<View className='flex-1 justify-between px-5 pb-4 pt-0'>
17+
<Medium style={[{ fontSize: 35 }, theme.color]}>{uvIndex}</Medium>
18+
<View className='w-full rounded-full bg-white/10'>
19+
<View className='h-1.5 rounded-full bg-white/70' style={{ width: `${uviPercent}%` }} />
20+
</View>
21+
<Regular style={[theme.color, F.F12]}>{getUVIndexStatus(uvIndex)}</Regular>
22+
</View>
23+
</View>
24+
)
25+
}
26+
27+
function getUVIndexStatus(uvIndex: number) {
28+
if (uvIndex < 3) return 'Current UV index is low.'
29+
if (uvIndex < 6) return 'Current UV index is moderate.'
30+
if (uvIndex < 8) return 'Current UV index is high.'
31+
if (uvIndex < 11) return 'Current UV index is very high.'
32+
return 'Current UV index is extreme.'
33+
}

0 commit comments

Comments
 (0)