Skip to content

Commit

Permalink
Tabs - Avoid passing a list of Composable tag content
Browse files Browse the repository at this point in the history
  • Loading branch information
Tweener committed Jul 21, 2024
1 parent 4204b6d commit 443df9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 0 additions & 2 deletions czan/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ kotlin {
androidTarget {
publishLibraryVariants("release")


@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
jvmTarget.set(JvmTarget.fromTarget(ProjectConfiguration.Compiler.jvmTarget))
Expand All @@ -72,7 +71,6 @@ kotlin {
}

sourceSets {

commonMain.dependencies {
implementation(project.dependencies.platform(libs.tweener.bom))
implementation(libs.tweener.common)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.jetbrains.compose.resources.DrawableResource
import org.jetbrains.compose.resources.StringResource

class TabItem(
val id: String,
val title: StringResource,
val icon: DrawableResource? = null,
)
Expand All @@ -54,13 +55,13 @@ class TabItem(
@Composable
fun PrimaryTabs(
tabItems: List<TabItem>,
tabsContents: List<@Composable () -> Unit>,
modifier: Modifier = Modifier,
colors: TabsColors = TabsDefaults.colors(),
textStyle: TextStyle = MaterialTheme.typography.bodyMedium,
shape: Shape = RoundedCornerShape(Size.Padding.Small),
contentPadding: PaddingValues = TabsDefaults.ContentPadding,
showDivider: Boolean = false,
onTabChanged: (@Composable (String) -> Unit)? = null,
) {
var selectedTabIndex by remember { mutableIntStateOf(0) }

Expand Down Expand Up @@ -92,21 +93,21 @@ fun PrimaryTabs(
}
}

tabsContents.getOrNull(selectedTabIndex)?.invoke()
onTabChanged?.invoke(tabItems[selectedTabIndex].id)
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SecondaryTabs(
tabItems: List<TabItem>,
tabsContents: List<@Composable () -> Unit>,
modifier: Modifier = Modifier,
colors: TabsColors = TabsDefaults.colors(),
textStyle: TextStyle = MaterialTheme.typography.bodyMedium,
shape: Shape = RoundedCornerShape(Size.Padding.Small),
contentPadding: PaddingValues = TabsDefaults.ContentPadding,
showDivider: Boolean = false,
onTabChanged: (@Composable (String) -> Unit)? = null,
) {
var selectedTabIndex by remember { mutableIntStateOf(0) }

Expand Down Expand Up @@ -138,7 +139,7 @@ fun SecondaryTabs(
}
}

tabsContents.getOrNull(selectedTabIndex)?.invoke()
onTabChanged?.invoke(tabItems[selectedTabIndex].id)
}
}

Expand Down

0 comments on commit 443df9d

Please sign in to comment.