SwiftUIMaterialTabs icon indicating copy to clipboard operation
SwiftUIMaterialTabs copied to clipboard

[Suggestion] Expose TabBarModel and HeaderModel as public.

Open demon9733 opened this issue 2 months ago • 4 comments

Reasoning:

When creating a custom tab bar, I'm forced to do something like:

struct ScrollableTabBar<Tab: DisplayableTab>: View {
    @Binding var selectedTab: Tab
    var tabs: [Tab]

    init(selectedTab: Binding<Tab>, tabs: [Tab]) {
    ...

providing the tabs array that's synchronized with the actual tabs, and basing the tab labels on my DisplayableTab protocol.

And tabs are registered with:

.materialTabItem(tab: tab) { _, _, _ in
    // The tab label is not used due to custom tab bar setup
    EmptyView()
}

Different screens may require different tab labels, which can blow up the DisplayableTab eventually.

Solution:

Exposing TabBarModel and HeaderModel would allow to benefit from EnvironmentObject-s to render the tab labels provided by the materialTabItem.

demon9733 avatar Nov 05 '25 19:11 demon9733

Good callout. I hadn't run into a case for a custom tab bar implementation yet. Why did you end up needing a custom tab bar in the first place?

wtmoose avatar Nov 05 '25 20:11 wtmoose

My tab bar is left-aligned self-sizing capsules that are scrollable on demand, with an optional trailing view.

Image

demon9733 avatar Nov 05 '25 20:11 demon9733

Gotcha. I think built-in tab bar does all of that except the trailing view, which could be added. But I'm also good with making those components public.

wtmoose avatar Nov 05 '25 20:11 wtmoose

I believe the left-aligned tabs and uneven tab width is not achievable with the MaterialTabBar either right now. I may be mistaken, but I'm pretty sure of it.

demon9733 avatar Nov 05 '25 21:11 demon9733