Skip to content

Commit cb43838

Browse files
committed
Refactor HourlyForecast component to use FlatList instead of ScrollView
1 parent 7c36205 commit cb43838

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

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

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { Clock01SolidIcon } from '@assets/icons/icons'
33
import type { Current, Weather } from '@screens/Weather/types'
44
import { Icons } from '@screens/Weather/utils'
55
import { Medium, Regular, SemiBold } from '@utils/fonts'
6-
import { getAp, getHour, screenDelay, tempConverter } from '@utils/utils'
7-
import React, { useEffect, useState } from 'react'
6+
import { getAp, getHour, tempConverter } from '@utils/utils'
7+
import React from 'react'
88
import { View } from 'react-native'
9-
import { ScrollView } from 'react-native-gesture-handler'
9+
import { FlatList } from 'react-native-gesture-handler'
1010
import Animated, { FadeIn } from 'react-native-reanimated'
1111
import type { SvgProps } from 'react-native-svg'
1212
import type { ViewProps } from 'react-native-svg/lib/typescript/fabric/utils'
@@ -37,36 +37,35 @@ export default function HourlyForecast({ color, w, hourly }: HourlyWeather) {
3737
<View className='rounded-3xl bg-black/10'>
3838
<WeatherLabel Icon={Clock01SolidIcon} color={color} label='Hourly Forecast' />
3939
<Underline />
40-
<ScrollView
41-
horizontal={true}
40+
<FlatList
4241
showsHorizontalScrollIndicator={false}
42+
horizontal={true}
4343
contentContainerStyle={{ flexDirection: 'row', paddingBottom: 10, paddingHorizontal: 10 }}
44-
>
45-
<>
44+
renderItem={({ item }) => (
45+
<SmallWeather
46+
key={item.dt}
47+
Icon={Icons[item.weather[0]!.icon]}
48+
time={getHour(item.dt + 3600, timeFormat)}
49+
color={color}
50+
ap={getAp(item.dt, timeFormat)}
51+
temp={item ? tempConverter({ temp: item.temp, unit: currentUnit, degree: true }) : '__'}
52+
probability={Math.round((item.pop || 0) * 100)}
53+
/>
54+
)}
55+
ListHeaderComponent={
4656
<View style={{ opacity: data ? 1 : 0 }}>
4757
<SmallWeather
4858
color={color}
4959
time='Now'
5060
Icon={Icon}
5161
ap=''
52-
// temp={w ? tempConverter(w.current.temp, currentUnit, true) : '__'}
5362
temp={w ? tempConverter({ temp: w.current.temp, unit: currentUnit, degree: true }) : '__'}
5463
probability={Math.round((w?.current.pop || 0) * 100)}
5564
/>
5665
</View>
57-
{data?.map((h, i) => (
58-
<SmallWeather
59-
Icon={Icons[h.weather[0]!.icon]}
60-
key={i}
61-
time={getHour(h.dt + 3600, timeFormat)}
62-
color={color}
63-
ap={getAp(h.dt, timeFormat)}
64-
temp={h ? tempConverter({ temp: h.temp, unit: currentUnit, degree: true }) : '__'}
65-
probability={Math.round((h.pop || 0) * 100)}
66-
/>
67-
))}
68-
</>
69-
</ScrollView>
66+
}
67+
data={data}
68+
/>
7069
</View>
7170
</Animated.View>
7271
)

0 commit comments

Comments
 (0)