• Viktor De Pasquale's avatar
    Fixed modules screen crashing on load · d810e6c8
    Viktor De Pasquale authored
    This commit fixes the issue of adding single-span items in between full-span items whilst using `StaggeredGridLayoutManager` on recycler view.
    
    Adding such items results in:
    ```
    java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 13
    	at java.util.Arrays.rangeCheck(Arrays.java:123)
    	at java.util.Arrays.fill(Arrays.java:2828)
    	at androidx.recyclerview.widget.StaggeredGridLayoutManager$LazySpanLookup.invalidateAfter(StaggeredGridLayoutManager.java:2876)
    	at androidx.recyclerview.widget.StaggeredGridLayoutManager.handleUpdate(StaggeredGridLayoutManager.java:1548)
    	at androidx.recyclerview.widget.StaggeredGridLayoutManager.onItemsUpdated(StaggeredGridLayoutManager.java:1524)
    	at androidx.recyclerview.widget.RecyclerView$6.dispatchUpdate(RecyclerView.java:1021)
    	at androidx.recyclerview.widget.RecyclerView$6.onDispatchSecondPass(RecyclerView.java:1032)
    	at androidx.recyclerview.widget.AdapterHelper.consumePostponedUpdates(AdapterHelper.java:121)
    	at androidx.recyclerview.widget.AdapterHelper.consumeUpdatesInOnePass(AdapterHelper.java:557)
    	at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4128)
    	at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
    	at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
    	...and more
    ```
    
    Affects versions including and prior to androidx.recyclerview:recyclerview:1.2.0-alpha02 (at the time of this commit) and possibly more after that.
    
    This bug is caused by a single fact and that is - array inside of `LazySpanLookup` is not being invalidated and resized correctly when non-full-span item is being added in between of two full-span items. The invalidation however passes on some (high performance) devices so it doesn't necessarily cause issues for _some_ users; others keep getting the same crash over and over again.
    
    Possible fix for anyone reading this, in the hope of fixing the same error, is to copy-paste the `StaggeredGridLayoutManager` and fix the array length before calling `Arrays.fill()`. There's no fix from user's perspective if you need to keep the UI as-is.
    We however don't need the UI as-is, so we're instead opting to use LinearLayoutManager until is the issue resolved.
    
    Continues tracking at https://issuetracker.google.com/issues/37034096
    
    Close #2631
    d810e6c8
Name
Last commit
Last update
..
anim Loading commit data...
color Loading commit data...
drawable Loading commit data...
drawable-anydpi-v21 Loading commit data...
drawable-anydpi-v23 Loading commit data...
drawable-anydpi-v26 Loading commit data...
drawable-hdpi Loading commit data...
drawable-mdpi Loading commit data...
drawable-nodpi Loading commit data...
drawable-v21 Loading commit data...
drawable-v26 Loading commit data...
drawable-xhdpi Loading commit data...
drawable-xxhdpi Loading commit data...
drawable-xxxhdpi Loading commit data...
font Loading commit data...
layout Loading commit data...
menu Loading commit data...
navigation Loading commit data...
raw Loading commit data...
values Loading commit data...
values-ar Loading commit data...
values-az Loading commit data...
values-bg Loading commit data...
values-ca Loading commit data...
values-cs Loading commit data...
values-de Loading commit data...
values-el Loading commit data...
values-es Loading commit data...
values-et Loading commit data...
values-fr Loading commit data...
values-hi Loading commit data...
values-hr Loading commit data...
values-in Loading commit data...
values-it Loading commit data...
values-ja Loading commit data...
values-ka Loading commit data...
values-ko Loading commit data...
values-lt Loading commit data...
values-mk Loading commit data...
values-nb Loading commit data...
values-night Loading commit data...
values-nl Loading commit data...
values-pl Loading commit data...
values-pt-rBR Loading commit data...
values-pt-rPT Loading commit data...
values-ro Loading commit data...
values-ru Loading commit data...
values-sk Loading commit data...
values-sr Loading commit data...
values-sv Loading commit data...
values-th Loading commit data...
values-tr Loading commit data...
values-uk Loading commit data...
values-v19 Loading commit data...
values-v21 Loading commit data...
values-vi Loading commit data...
values-zh-rCN Loading commit data...
values-zh-rTW Loading commit data...