@@ -66,6 +66,8 @@ const RARITY_LABELS: Record<BadgeRarity, string> = {
6666 legendary : 'Legendary' ,
6767} ;
6868
69+ import { VirtualList } from './VirtualList' ;
70+
6971const AchievementBadgesComponent : React . FC < AchievementBadgesProps > = ( {
7072 achievements,
7173 isDark = false ,
@@ -83,7 +85,7 @@ const AchievementBadgesComponent: React.FC<AchievementBadgesProps> = ({
8385 announceToScreenReader ( `Opening details for ${ achievement . name } badge.` ) ;
8486 } , [ ] ) ;
8587
86- const renderBadge = ( achievement : Achievement ) => {
88+ const renderBadge = useCallback ( ( { item : achievement } : { item : Achievement } ) => {
8789 const rarity = achievement . rarity ?? 'common' ;
8890 const gradColors = RARITY_COLORS [ rarity ] ;
8991 const isLocked = achievement . isLocked ;
@@ -171,7 +173,7 @@ const AchievementBadgesComponent: React.FC<AchievementBadgesProps> = ({
171173 ) }
172174 </ TouchableOpacity >
173175 ) ;
174- } ;
176+ } , [ isDark , handleSelectBadge ] ) ;
175177
176178 return (
177179 < View style = { [ styles . container , { backgroundColor : isDark ? '#0f172a' : '#fff' } ] } >
@@ -194,15 +196,20 @@ const AchievementBadgesComponent: React.FC<AchievementBadgesProps> = ({
194196 </ View >
195197
196198 { achievements . length > 0 ? (
197- < ScrollView
199+ < VirtualList
200+ data = { achievements }
201+ renderItem = { renderBadge }
202+ keyExtractor = { item => item . id }
198203 horizontal
199204 showsHorizontalScrollIndicator = { false }
200205 contentContainerStyle = { styles . scrollContent }
201206 accessibilityLabel = "Horizontal achievements list"
202207 removeClippedSubviews = { true }
203- >
204- { achievements . map ( renderBadge ) }
205- </ ScrollView >
208+ initialNumToRender = { 5 }
209+ maxToRenderPerBatch = { 5 }
210+ windowSize = { 3 }
211+ itemSize = { 72 }
212+ />
206213 ) : (
207214 < View
208215 style = { styles . emptyState }
@@ -536,4 +543,4 @@ const styles = StyleSheet.create({
536543 height : '100%' ,
537544 borderRadius : 3 ,
538545 } ,
539- } ) ;
546+ } ) ;
0 commit comments