Skip to content

How to disable autoscrolling in UICollectionView #1328

Open

Description

@stanislavleonchik

https://github.com/user-attachments/assets/0381b319-8462-46cf-ba73-d559f5e2b4ef
I have no lines of code that call scroll.
This behaviour is provided by .tap(), .waitForTappableView(), .waitForView() e.t.c methods.
Whole collection items are displayed on the screen, there is no reason to do autoscrolling.

Activity

  1. stanislavleonchik commented on Apr 24, 2025

    @stanislavleonchik
    Author

    @justinseanmartin @danielbarela Will this issue be fixed any time soon?

  2. justinseanmartin commented on Apr 24, 2025

    @justinseanmartin
    Contributor

    I've added a potentially relevant comment in #1316 (comment).

    KIF implicitly tries to scroll table views and collection views to enumerate elements that are offscreen. This is to allow tests to be more robust and not try to reason about the scroll position of the views on the screen, because that state can often change as we interact with the app and can be hard to explicitly control. Some view elements aren't accessible in the view/accessibility hierarchy until the view has been scrolled to that position. We stopped being able to access those cells programmatically and needed to scroll the view to different positions as a workaround for assertions that Apple added and called out in issues #1007 (for UITableViews) and #1303 (for UICollectionViews). If no matching view is found for the predicate, we should scroll back to the original view position. Once a matching element has been found, if it must be tappable, then we try to scroll it into the visible region of the screen.

    If you wanted to understand why KIF is performing a scroll for your app and test, you could try setting some breakpoints on the lines of code I linked above to try and reason about why KIF is performing a scroll. If you wanted to globally turn the autoscroll behavior off, you could probably subclass KIFUIViewTestActor and set disablingAutomaticScroll to true always.

    I'd be happy to merge a PR that adds a static boolean property on KIFUITestActor that waitForAccessibilityElement:view:withElementMatchingPredicate:tappable: could use as its default value and KIFUIViewTestActor could use in its initializer for setting the initial value of disablingAutomaticScroll. In that case, we'd maybe want something that is in the inverse of usingCurrentFrame to allow scrolling on a one off basis. If you wanted to contribute, please include tests to exercise the functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions