• 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
..
activity_main_md2.xml Loading commit data...
activity_request.xml Loading commit data...
dialog_magisk_base.xml Loading commit data...
dialog_settings_app_name.xml Loading commit data...
dialog_settings_download_path.xml Loading commit data...
dialog_settings_update_channel.xml Loading commit data...
fragment_flash_md2.xml Loading commit data...
fragment_hide_md2.xml Loading commit data...
fragment_home_md2.xml Loading commit data...
fragment_install_md2.xml Loading commit data...
fragment_log_md2.xml Loading commit data...
fragment_module_md2.xml Loading commit data...
fragment_safetynet_md2.xml Loading commit data...
fragment_settings_md2.xml Loading commit data...
fragment_superuser_md2.xml Loading commit data...
fragment_theme_md2.xml Loading commit data...
include_hide_filter.xml Loading commit data...
include_home_magisk.xml Loading commit data...
include_home_manager.xml Loading commit data...
include_install_options.xml Loading commit data...
include_log_magisk.xml Loading commit data...
include_log_superuser.xml Loading commit data...
include_module_filter.xml Loading commit data...
item_console_md2.xml Loading commit data...
item_developer.xml Loading commit data...
item_developer_link.xml Loading commit data...
item_hide_md2.xml Loading commit data...
item_hide_process_md2.xml Loading commit data...
item_list_single_line.xml Loading commit data...
item_log_access_md2.xml Loading commit data...
item_log_track_md2.xml Loading commit data...
item_module_download.xml Loading commit data...
item_module_md2.xml Loading commit data...
item_policy_md2.xml Loading commit data...
item_repo_md2.xml Loading commit data...
item_safe_mode_notice.xml Loading commit data...
item_section_md2.xml Loading commit data...
item_settings_blank.xml Loading commit data...
item_settings_input.xml Loading commit data...
item_settings_section.xml Loading commit data...
item_settings_selector.xml Loading commit data...
item_settings_toggle.xml Loading commit data...
item_spinner.xml Loading commit data...
item_tappable_headline.xml Loading commit data...
item_text.xml Loading commit data...
item_theme.xml Loading commit data...
markdown_window_md2.xml Loading commit data...