@@ -139,14 +139,22 @@ export function VirtualizedRoomListView({ vm, renderAvatar, onKeyDown }: Virtual
139139 /**
140140 * Get the item component for a specific index
141141 * Gets the room's view model and passes it to RoomListItemView
142+ *
143+ * @param index - The index of the item in the list
144+ * @param roomId - The ID of the room for this item
145+ * @param context - The virtualization context containing list state
146+ * @param onFocus - Callback to call when the item is focused
147+ * @param isInLastSection - Whether this item is in the last section
148+ * @param roomIndexInSection - The index of this room within its section
142149 */
143150 const getItemComponent = useCallback (
144151 (
145152 index : number ,
146153 roomId : string ,
147154 context : VirtualizedListContext < Context > ,
148155 onFocus : ( item : string , e : React . FocusEvent ) => void ,
149- roomIndexInSection : number ,
156+ isInLastSection ?: boolean ,
157+ roomIndexInSection ?: number ,
150158 ) : JSX . Element => {
151159 const { activeRoomIndex, roomCount, vm, isFlatList } = context . context ;
152160 const isSelected = activeRoomIndex === index ;
@@ -156,8 +164,8 @@ export function VirtualizedRoomListView({ vm, renderAvatar, onKeyDown }: Virtual
156164 // This matches the old RoomList implementation's roving tabindex pattern
157165 const isFocused = context . focused && context . tabIndexKey === roomId ;
158166
159- const isFirstItem = index === 0 ;
160- const isLastItem = index === roomCount - 1 ;
167+ const isFirstItem = isFlatList && index === 0 ;
168+ const isLastItem = Boolean ( ( isFlatList || isInLastSection ) && index === roomCount - 1 ) ;
161169
162170 return (
163171 < RoomListItemAccessibilityWrapper
@@ -168,7 +176,7 @@ export function VirtualizedRoomListView({ vm, renderAvatar, onKeyDown }: Virtual
168176 isFocused = { isFocused }
169177 onFocus = { onFocus }
170178 roomIndex = { index }
171- roomIndexInSection = { roomIndexInSection }
179+ roomIndexInSection = { roomIndexInSection || 0 }
172180 roomCount = { roomCount }
173181 isFirstItem = { isFirstItem }
174182 isLastItem = { isLastItem }
@@ -181,7 +189,6 @@ export function VirtualizedRoomListView({ vm, renderAvatar, onKeyDown }: Virtual
181189
182190 /**
183191 * Get the item component for a specific index in a grouped list
184- * Since we have sections, we can calculate the room's index within its section and pass it to getItemComponent
185192 * Gets the room's view model and passes it to RoomListItemView
186193 */
187194 const getItemComponentForGroupedList = useCallback (
@@ -194,14 +201,14 @@ export function VirtualizedRoomListView({ vm, renderAvatar, onKeyDown }: Virtual
194201 ) : JSX . Element => {
195202 const { sections } = context . context ;
196203 const roomIndexInSection = sections [ groupIndex ] . roomIds . findIndex ( ( id ) => id === roomId ) ;
197- return getItemComponent ( index , roomId , context , onFocus , roomIndexInSection ) ;
204+ const isInLastSection = groupIndex === sections . length - 1 ;
205+ return getItemComponent ( index , roomId , context , onFocus , isInLastSection , roomIndexInSection ) ;
198206 } ,
199207 [ getItemComponent ] ,
200208 ) ;
201209
202210 /**
203211 * Get the item component for a specific index in a flat list
204- * Since we don't have sections, we can pass 0 for the room's index within its section to getItemComponent
205212 * Gets the room's view model and passes it to RoomListItemView
206213 */
207214 const getItemComponentForFlatList = useCallback (
@@ -211,8 +218,7 @@ export function VirtualizedRoomListView({ vm, renderAvatar, onKeyDown }: Virtual
211218 context : VirtualizedListContext < Context > ,
212219 onFocus : ( item : string , e : React . FocusEvent ) => void ,
213220 ) : JSX . Element => {
214- // For a flat list, we don't have sections, so roomIndexInSection is unused and can be set to 0
215- return getItemComponent ( index , roomId , context , onFocus , 0 ) ;
221+ return getItemComponent ( index , roomId , context , onFocus ) ;
216222 } ,
217223 [ getItemComponent ] ,
218224 ) ;
0 commit comments