Skip to content

Commit 9f27041

Browse files
committed
fix(collectionview): ios fix for getViewForItemAtIndex when not loaded
1 parent 88d4c9e commit 9f27041

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/collectionview/index.ios.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,18 @@ export class CollectionView extends CollectionViewBase {
222222
public getViewForItemAtIndex(index: number): View {
223223
let result: View;
224224
if (this.nativeViewProtected) {
225+
// when the collectionview is not loaded anymore, cellForItemAtIndexPath wont return
226+
// then we use our cached map to get the view
225227
const cell = this.nativeViewProtected.cellForItemAtIndexPath(NSIndexPath.indexPathForRowInSection(index, 0)) as CollectionViewCell;
226-
return cell?.view;
228+
if (cell) {
229+
return cell?.view;
230+
} else {
231+
for (const [cell, view] of this._map) {
232+
if (cell.currentIndex === index) {
233+
return view;
234+
}
235+
}
236+
}
227237
}
228238

229239
return result;

0 commit comments

Comments
 (0)