Using a TabView as a pageviewer by using .tabViewStyle(PageTabViewStyle())
works fine, but trying to let it run from edge to edge by applying edgesIgnoringSafeArea
does not seem to work.
What am I missing here?
struct ContentView: View { let colors: [Color] = [.red, .green, .blue] var body: some View { TabView { ForEach(0...2, id: \.self) { index in Rectangle() .fill(colors[index]) } } .tabViewStyle(PageTabViewStyle()) .edgesIgnoringSafeArea(.all) } }
Adding another .edgesIgnoringSafeArea(.all)
to the Rectangle
or ForEach
also doen't work.
Note that all these questions are different because they do not use use PageTabViewStyle()
:
Their solution (adding edgesIgnoringSafeArea(.all)
) doesn't work in this case.
struct ContentView: View { let colors: [Color] = [.red, .green, .blue] var body: some View { ScrollView { TabView { ForEach(0...2, id: \.self) { index in Rectangle() .fill(colors[index]) } } .frame( width: UIScreen.main.bounds.width , height: UIScreen.main.bounds.height ) .tabViewStyle(PageTabViewStyle()) } .edgesIgnoringSafeArea(.all) } }
Here is a maximum what I've got... anyway I assume that originally it is a bug and worth submitting feedback to Apple.
Tested with Xcode 12b
struct TestPagingStyle: View { let colors: [Color] = [.red, .green, .blue] var body: some View { ZStack { Color.black.overlay( GeometryReader { gp in TabView { ForEach(0..<3, id: \.self) { index in Text("Hello, World \(index)") .frame(width: gp.size.width, height: gp.size.height) .background(colors[index]) } } .tabViewStyle(PageTabViewStyle(indexDisplayMode: .always)) } ) }.edgesIgnoringSafeArea(.all) } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With