Skip to content

Commit

Permalink
Merge pull request #1245 from kif-framework/dostrander/fix-cell-reuse
Browse files Browse the repository at this point in the history
Check that we have the same view after scrolling
  • Loading branch information
dostrander authored Nov 5, 2021
2 parents aa8d173 + 65a7667 commit 861417d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/KIF/Additions/UIAccessibilityElement-KIFAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ + (UIView *)viewContainingAccessibilityElement:(UIAccessibilityElement *)element
// Give the scroll view a small amount of time to perform the scroll.
CFTimeInterval delay = animationEnabled ? 0.3 : 0.05;
KIFRunLoopRunInModeRelativeToAnimationSpeed(kCFRunLoopDefaultMode, delay, false);

// Because of cell reuse the first found view could be different after we scroll.
// Find the same element's view to ensure that after we have scrolled we get the same view back.
UIView *checkedView = [UIAccessibilityElement viewContainingAccessibilityElement:element];
// intentionally doing a memory address check vs a isEqual check because
// we want to ensure that the memory address hasn't changed after scroll.
if(view != checkedView) {
view = checkedView;
}
}
}

Expand Down

0 comments on commit 861417d

Please sign in to comment.