Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tab-navigator: make TabOptions interface #463

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/navigation/tab-navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ Voyager provides a specialized navigator for tabs : the `TabNavigator`.

The `Tab` interface, like the `Screen`, has a `Content()` composable function, but also requires a `TabOptions`. 

!!! warning
You need to create a `data class` implementing the `TabOptions` interface.

```kotlin
data class TabOptionsModel(
override val index: UShort,
override val title: String,
override val icon: Painter?
) : TabOptions
```

```kotlin
object HomeTab : Tab {

Expand All @@ -17,7 +28,7 @@ object HomeTab : Tab {
val icon = rememberVectorPainter(Icons.Default.Home)

return remember {
TabOptions(
TabOptionsModel(
index = 0u,
title = title,
icon = icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object FavoritesTab : Tab {
val icon = rememberVectorPainter(Icons.Default.Favorite)

return remember {
TabOptions(
TabOptionsModel(
index = 1u,
title = "Favorites",
icon = icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object HomeTab : Tab {
val icon = rememberVectorPainter(Icons.Default.Home)

return remember {
TabOptions(
TabOptionsModel(
index = 0u,
title = "Home",
icon = icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object ProfileTab : Tab {
val icon = rememberVectorPainter(Icons.Default.Person)

return remember {
TabOptions(
TabOptionsModel(
index = 2u,
title = "Profile",
icon = icon
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cafe.adriel.voyager.sample.tabNavigation.tabs

import androidx.compose.ui.graphics.painter.Painter
import cafe.adriel.voyager.navigator.tab.TabOptions

data class TabOptionsModel(
override val index: UShort,
override val title: String,
override val icon: Painter?
): TabOptions
19 changes: 4 additions & 15 deletions voyager-tab-navigator/api/android/voyager-tab-navigator.api
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,9 @@ public final class cafe/adriel/voyager/navigator/tab/TabNavigatorKt {
public static final fun getLocalTabNavigator ()Landroidx/compose/runtime/ProvidableCompositionLocal;
}

public final class cafe/adriel/voyager/navigator/tab/TabOptions {
public static final field $stable I
public synthetic fun <init> (SLjava/lang/String;Landroidx/compose/ui/graphics/painter/Painter;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (SLjava/lang/String;Landroidx/compose/ui/graphics/painter/Painter;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1-Mh2AYeg ()S
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Landroidx/compose/ui/graphics/painter/Painter;
public final fun copy-_TFR7lA (SLjava/lang/String;Landroidx/compose/ui/graphics/painter/Painter;)Lcafe/adriel/voyager/navigator/tab/TabOptions;
public static synthetic fun copy-_TFR7lA$default (Lcafe/adriel/voyager/navigator/tab/TabOptions;SLjava/lang/String;Landroidx/compose/ui/graphics/painter/Painter;ILjava/lang/Object;)Lcafe/adriel/voyager/navigator/tab/TabOptions;
public fun equals (Ljava/lang/Object;)Z
public final fun getIcon ()Landroidx/compose/ui/graphics/painter/Painter;
public final fun getIndex-Mh2AYeg ()S
public final fun getTitle ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public abstract interface class cafe/adriel/voyager/navigator/tab/TabOptions {
public abstract fun getIcon ()Landroidx/compose/ui/graphics/painter/Painter;
public abstract fun getIndex-Mh2AYeg ()S
public abstract fun getTitle ()Ljava/lang/String;
}

19 changes: 4 additions & 15 deletions voyager-tab-navigator/api/desktop/voyager-tab-navigator.api
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,9 @@ public final class cafe/adriel/voyager/navigator/tab/TabNavigatorKt {
public static final fun getLocalTabNavigator ()Landroidx/compose/runtime/ProvidableCompositionLocal;
}

public final class cafe/adriel/voyager/navigator/tab/TabOptions {
public static final field $stable I
public synthetic fun <init> (SLjava/lang/String;Landroidx/compose/ui/graphics/painter/Painter;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (SLjava/lang/String;Landroidx/compose/ui/graphics/painter/Painter;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1-Mh2AYeg ()S
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Landroidx/compose/ui/graphics/painter/Painter;
public final fun copy-_TFR7lA (SLjava/lang/String;Landroidx/compose/ui/graphics/painter/Painter;)Lcafe/adriel/voyager/navigator/tab/TabOptions;
public static synthetic fun copy-_TFR7lA$default (Lcafe/adriel/voyager/navigator/tab/TabOptions;SLjava/lang/String;Landroidx/compose/ui/graphics/painter/Painter;ILjava/lang/Object;)Lcafe/adriel/voyager/navigator/tab/TabOptions;
public fun equals (Ljava/lang/Object;)Z
public final fun getIcon ()Landroidx/compose/ui/graphics/painter/Painter;
public final fun getIndex-Mh2AYeg ()S
public final fun getTitle ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public abstract interface class cafe/adriel/voyager/navigator/tab/TabOptions {
public abstract fun getIcon ()Landroidx/compose/ui/graphics/painter/Painter;
public abstract fun getIndex-Mh2AYeg ()S
public abstract fun getTitle ()Ljava/lang/String;
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public fun CurrentTab() {
}
}

public data class TabOptions(
val index: UShort,
val title: String,
val icon: Painter? = null
)
public interface TabOptions {
public val index: UShort
public val title: String
public val icon: Painter?
}

public interface Tab : Screen {

Expand Down
Loading