Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply layout corrections only to consecutive cells #788

Merged
merged 3 commits into from
Mar 17, 2023
Merged

Conversation

naqvitalha
Copy link
Collaborator

@naqvitalha naqvitalha commented Mar 15, 2023

Description

resolves #600

Issue summary: FlashList sometimes overlaps items when getItemType is used.

This issue was reported long ago but we couldn’t identify the root cause. We recently figured out that the issue happens when you have two items of different types next to each other but not in consecutive order from the data perspective.

For example, assume View1, View2, View3, View4, View7, View8 are present in the view hierarchy. From the parent view’s perspective View4 and View7 are next to each other but they’re actually not because we should have View5 and View6 in between. The reason for the two views being missing could be many, one of them being slow rendering due to expensive components and View7 / View8 are already in the view tree because they’re of different type so they might not be getting recycled at the same time.
In the aforementioned case AutoLayout will also think View4 and 7 are neighbours with a gap and it’ll pull 7 up pushing it out of sync with the react layout. This may or may not get fixed based on future onLayout operations. This is why we can see overlaps or gaps.

This PR should resolve the issue by making sure AutoLayout understands whether or not views are consecutive.

Reviewers’ hat-rack 🎩

Try the list sample on a slow device. Scroll down so that you see item 98 and 99 once. Scroll to the top and quickly scroll down. You will notice red items popping in and out of places where they should never be.

Checklist

@naqvitalha naqvitalha requested a review from fortmarek March 15, 2023 19:44
Comment on lines 28 to 29
// Only apply correction if the next cell is consecutive.
val isNeighbourConsecutive = cell.index == neighbour.index + 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we apply this logic on iOS, too, or does the problem not manifest there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS changes are also present in this PR. Check below

Comment on lines 8 to 9
@objc(onBlankAreaEvent)
var onBlankAreaEvent: RCTDirectEventBlock?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naqvitalha it seems the indentation for the whole file has changed and it's now hard to figure out what has actually changed. Can we keep here only the actual changes to make the review easier?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah apologies for this. I reformatted because indentations were looking off in github. I'll revert ASAP

Copy link
Contributor

@fortmarek fortmarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go!

ios/Sources/AutoLayoutView.swift Outdated Show resolved Hide resolved
ios/Sources/AutoLayoutView.swift Outdated Show resolved Hide resolved
@naqvitalha
Copy link
Collaborator Author

Did extensive tophatting. Looks good!

@naqvitalha naqvitalha merged commit 9180872 into main Mar 17, 2023
@naqvitalha naqvitalha deleted the blank-item-issue branch March 17, 2023 02:10
@hukpo
Copy link

hukpo commented Mar 21, 2023

Hey @naqvitalha 👋 I saw this issue on the web platform too, are there any plans to fix it not only for iOS and Android?

@AlexanderEggers
Copy link

@naqvitalha This change broke the flash list usage in my project.

Issue which includes some details: #812

Do you have an idea?

cc @fortmarek

@naqvitalha
Copy link
Collaborator Author

@AlexanderEggers Replied on the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug][ios]: using getItemType causes blanks and overlapping items
4 participants