3

Context

I am having a SwiftUI ScrollView and would like to use Paged TabViews inside to display data. However, this concludes in strange behaviour of the View collapsing to zero height.


Code

struct SomeView: View {
    var body: some View {
        NavigationView {
            ScrollView {
                TabView {
                    Text("View A")

                    Text("View B")

                    Text("View C")
                }
                .tabViewStyle(.page)
            }
        }
    }
}

Questions

  • How can I achieve my goal of using a Paged TabView inside a larger ScrollView without it collapsing to zero height?
  • I read in the documentation, that .tabViewStyle(.page) is not available on macOS. Is there any workaround to still use Paged TabViews on macOS?
christophriepe
  • 1,157
  • 12
  • 47
  • I don't think this interface would work -- what about having ScrollViews within each tab instead? – jnpdx Oct 09 '22 at 18:32
  • @jnpdx this would probably work technically, however, this would be a completely different use case with multiple ScrollView that are pageabe instead of one main ScrollView that contains Paged TavViews, which results in a totally different UI. – christophriepe Oct 09 '22 at 19:00
  • Right, but I'm struggling to see how this interface would work -- normally, with a tab view, a user has constant access to the tabs to switch pages. With what you're suggesting, they'd have to scroll to get them. Also, if the tabs are at the bottom (like on iOS), they would be at different Y positions based on the length of the pages. These reasons (and more) are why I'm suggesting this interface may not be ideal (and it already sounds like SwiftUI isn't built to do this given the problem you're having) – jnpdx Oct 09 '22 at 19:03
  • @jnpdx please note, that I am not talking about the default iOS TabBar, instead I am talking about the Paged TabView, which is more like a scrolling Card component. – christophriepe Oct 10 '22 at 06:34
  • All of the problems I listed still apply (except no buttons) -- the page indicators would be at different Y positions, user wouldn't be able to see them depending on where they are scrolled to, etc. – jnpdx Oct 10 '22 at 06:39
  • 1
    Is what you want : display views that can be moved left or right in a page navigation ? – Ptit Xav Oct 10 '22 at 09:01
  • @PtitXav yes that's the goal, however being in a scrollable context. – christophriepe Oct 10 '22 at 09:13

0 Answers0