basshelal / BoardView

🚧Work In Progress🚧 Android library for easy to use Kanban Boards
3 stars 0 forks source link

0th child swap bug #3

Closed basshelal closed 4 years ago

basshelal commented 4 years ago

Weird behavior happens when a swap is made with the 0th child of a BoardList. This includes swaps in the same list and swaps across the list.

This is likely related to LinearLayoutManager's strange behavior and relation with the 0th child of the RecyclerView, read this for more.

I still don't fully know what's causing these and will have to investigate further

basshelal commented 4 years ago

Minor update: This is unrelated to ItemAnimator as a null ItemAnimator will still cause weird swap issues.

This likely has to do with the forced scrolling we do to compensate for the LinearLayoutManager bug because without it we lose the weird swapping behavior and get a weird scrolling behavior.

basshelal commented 4 years ago

Swapping within the same list is fixed, using a hacky(?) method by ignoring the animation requests that layoutManager.prepareForDrop seems to call when it calls LayoutManager.scrollToPositionWithOffset. Our new custom ItemAnimator handles this.

Now, swapping across lists from or into the 0th child of a BoardList that can be scrollable (the same conditions that trigger a problem with swaps within the same list) still cause bugs. This is entirely due to LinearLayoutManager's weirdnesses with its anchor of the 0th child and is unrelated to Item Animators (just as before). This may be different for both, insertions into the 0th child and removals from the 0th child.

basshelal commented 4 years ago

This is all but done at this point, just need to make sure everything will work correctly when the custom Item Animator is finished.

basshelal commented 4 years ago

The hacky solution we used to fix this which was just onRunPendingAnimations.add { pendingRemovals.clear() } (basically ignore these next removals because trust me they're incorrect) is prone to bugs.

They are difficult to replicate but it does happen such that there will be a removal that should have happened but never did and thus a lingering View will remain as a child of BoardList. Perhaps its animation started but never ended or something.

I'll see if I can get something more elegant to counter this but so far I am annoyed by how much LinearLayoutManager has been a hassle for us, it's like it's working against me trying as hard as possible to break something that should be quite simple!

basshelal commented 4 years ago

Instead of ignoring any pending removals we just animate them with "useless" animations. Essentially, animations that change nothing and terminate instantly but do everything else correctly. ItemAnimator is happy with this and things seem fine with this approach. The animations are thus still run except some of them are invisible.