david-swift / SettingsKit-macOS

Add a settings window to a SwiftUI macOS app
https://david-swift.github.io/SettingsKit-macOS/
MIT License
87 stars 2 forks source link

Using TabView within the Setting #7

Closed longseespace closed 1 year ago

longseespace commented 1 year ago

Overview

I wanted to render a TabView within the SettingContent but it doesn't seem to work. Any idea why?

Here is my code:

// App.swift
...
.settings {
  SettingsTab(.init("Inline" as String, systemSymbol: .textBelowPhoto), id: "shortcut") {
        SettingsSubtab(.noSelection, id: "no-selection") {
            InlineSettingsView()
        }
    }
  }
//  InlineSettingsView.swift

struct InlineSettingsView: View {
    var body: some View {
        TabView {
            Text("A")
                .tabItem {
                    Label("A", systemSymbol: .person2)
                }

            Text("B")
                .tabItem {
                    Label("B", systemSymbol: .person2)
                }
        }
    }
}

I wanted to achieve something like this:

CleanShot 2023-08-28 at 17 35 19@2x

david-swift commented 1 year ago

You should be able to fix that by explicitly setting the automatic tab view style:

TabView {
    // ...
}
.tabViewStyle(.automatic)

Does that work in your case? I will add that modifier to the tab content in the SettingsKit package so that one does not have to add it manually.

longseespace commented 1 year ago

Ah right. I'm so dumb. Thank you!

david-swift commented 1 year ago

I actually needed some time to figure that out, I don't think it's that obvious...

In SettingsKit 0.1.13, the tab view style of every tab's content is set to automatic by default, because the buggy behavior you've encountered does not make sense. You can now remove the explicit .tabViewStyle(.automatic) in your case, @longseespace. Thanks for opening the issue!