5

Nested Auto Scroll For Section Based Lists With Jetpack Compose

 2 years ago
source link: https://proandroiddev.com/nested-auto-scroll-for-multiple-section-based-lists-with-jetpack-compose-c193a9814b09
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Nested Auto Scroll For Section Based Lists With Jetpack Compose

0*oXSpCRAlzKXZNkXh
Photo by Nathana Rebouças on Unsplash

Showing menu items in multiple food & drinks apps is one of the best use cases for multiple lists interaction, Let’s create a simple implementation with Jetpack Compose 🚀

We’ll cover all of the following points :

  • Show menu items list labeled by sections
  • Show sections list and highlight the selected one
  • On menu items list scroll, highlight the sections list with the displayed section
  • On click on section name, jump to the menu items list section position
1*BNJrOJhMB4ED6-cqP2kZSQ.gif

Show menu items list labeled by sections

This is a simple list for all menu items labeled & indexed by sections title

  • itemsListState is a LazyListState which will be used to handle auto scroll which will be discussed later
  • onPostScroll used to detect a scroll action on the menu items list, called from nestedScroll modifier

And this is the MenuItemView, just a simple view to show section items:

Show sections list and highlight the selected one

This is a simple list to show sections titles in a row and used SectionTextView to show and highlight the selected section:

SectionTextView will also show an underline to the selected section item, the underline width textWidth should always match the text size so it is measured on onGloballyPositioned modifier:

On menu items list scroll, highlight the sections list with the displayed section

The main parent view which will handle both lists interactions is MenuView

It will hold the current selection and handle onPostScroll event from the menu items list view

  • Update the selected section index
  • Scroll through the sections list to the selected section title position

On click on section name, jump to the section menu items list position

MenuViewwill also handle section title click event

  • Update the selected section index
  • Scroll through the items list to the selected section position
  • Scroll through the sections list to the selected section title position

Finally the MenuViewwill be like this:

That’s it! You made it! 💪

Do you see anything missing? please comment!

Thanks for reading, see you in the next article 😊


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK