diff --git a/docs/navigation/tab-navigation.md b/docs/navigation/tab-navigation.md index 7295434b..5ed54a5e 100644 --- a/docs/navigation/tab-navigation.md +++ b/docs/navigation/tab-navigation.md @@ -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 { @@ -17,7 +28,7 @@ object HomeTab : Tab { val icon = rememberVectorPainter(Icons.Default.Home) return remember { - TabOptions( + TabOptionsModel( index = 0u, title = title, icon = icon diff --git a/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/FavoritesTab.kt b/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/FavoritesTab.kt index c8498751..d0729507 100644 --- a/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/FavoritesTab.kt +++ b/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/FavoritesTab.kt @@ -16,7 +16,7 @@ object FavoritesTab : Tab { val icon = rememberVectorPainter(Icons.Default.Favorite) return remember { - TabOptions( + TabOptionsModel( index = 1u, title = "Favorites", icon = icon diff --git a/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/HomeTab.kt b/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/HomeTab.kt index 783c4de1..df8265e5 100644 --- a/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/HomeTab.kt +++ b/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/HomeTab.kt @@ -16,7 +16,7 @@ object HomeTab : Tab { val icon = rememberVectorPainter(Icons.Default.Home) return remember { - TabOptions( + TabOptionsModel( index = 0u, title = "Home", icon = icon diff --git a/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/ProfileTab.kt b/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/ProfileTab.kt index 19d25c4f..236b759c 100644 --- a/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/ProfileTab.kt +++ b/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/ProfileTab.kt @@ -16,7 +16,7 @@ object ProfileTab : Tab { val icon = rememberVectorPainter(Icons.Default.Person) return remember { - TabOptions( + TabOptionsModel( index = 2u, title = "Profile", icon = icon diff --git a/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/TabOptionsModel.kt b/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/TabOptionsModel.kt new file mode 100644 index 00000000..6375d44b --- /dev/null +++ b/samples/android/src/main/java/cafe/adriel/voyager/sample/tabNavigation/tabs/TabOptionsModel.kt @@ -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 diff --git a/voyager-tab-navigator/api/android/voyager-tab-navigator.api b/voyager-tab-navigator/api/android/voyager-tab-navigator.api index b9f3a91c..25478fef 100644 --- a/voyager-tab-navigator/api/android/voyager-tab-navigator.api +++ b/voyager-tab-navigator/api/android/voyager-tab-navigator.api @@ -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 (SLjava/lang/String;Landroidx/compose/ui/graphics/painter/Painter;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun (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; } diff --git a/voyager-tab-navigator/api/desktop/voyager-tab-navigator.api b/voyager-tab-navigator/api/desktop/voyager-tab-navigator.api index 83a0f180..0a760cab 100644 --- a/voyager-tab-navigator/api/desktop/voyager-tab-navigator.api +++ b/voyager-tab-navigator/api/desktop/voyager-tab-navigator.api @@ -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 (SLjava/lang/String;Landroidx/compose/ui/graphics/painter/Painter;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun (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; } diff --git a/voyager-tab-navigator/src/commonMain/kotlin/cafe/adriel/voyager/navigator/tab/Tab.kt b/voyager-tab-navigator/src/commonMain/kotlin/cafe/adriel/voyager/navigator/tab/Tab.kt index 945471d9..06000575 100644 --- a/voyager-tab-navigator/src/commonMain/kotlin/cafe/adriel/voyager/navigator/tab/Tab.kt +++ b/voyager-tab-navigator/src/commonMain/kotlin/cafe/adriel/voyager/navigator/tab/Tab.kt @@ -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 {