Skip to content

A Jetpack compose library that auto-syncs a TabRow with a LazyColumn.

License

Notifications You must be signed in to change notification settings

St4B/smart-tabs

Repository files navigation

SmartTabs

Badge

A simple library that helps us to sync a TabRow with a LazyColumn. The motives behind creating it can be found in this post.

Installation

In the project's build.gradle file you need to add the maven central repository:

repositories {
    mavenCentral()
}

In the module's build.gradle file you need to add the following dependency:

implementation("com.quadible:smart-tabs:1.0.0")

Usage

Apart from our dataset (that needs to contain simple and header items), we need to define:

  • a function that makes it easier for SmartTabsList to distinguish header items in the dataset.
  • a composable that defines how the simple and header items will be rendered in the LazyColumn.
  • a composable that defines how the header items will be rendered in the TabRow.
// We assume that we have the following composables.
// Item: Specifies how every item (header or not) will be rendered in LazyColumn
// Tab: Specifies how every header will be rendered in TabRow
val content = // list of items (they contains also the headers)
SmartTabsList(
    smartTabsContent = content,
    isTab = { itemFromContent -> /* check if this is a header or not */ },
    smartTab = { headerItem, isSelected -> Tab(headerItem, isSelected) },
    smartItem = { itemFromContent -> Item(itemFromContent) }
)

Preview

About

A Jetpack compose library that auto-syncs a TabRow with a LazyColumn.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages