Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

edgesIgnoringSafeArea on TabView with PageTabViewStyle not working

Tags:

ios

swiftui

ios14

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)     } } 

TabView + PageTabViewStyle + edgesIgnoringSafeArea

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():

  • How do I use a TabView with a NavigationView in SwiftUI?
  • Adding a TabView makes the Navigation Bar not cover the safe area in SwiftUI
  • NavigationView doesn't display correctly when using TabView in SwiftUI
  • In my NavigationView '.edgesIgnoringSafeArea' does not move content past the safe area

Their solution (adding edgesIgnoringSafeArea(.all)) doesn't work in this case.

like image 436
Tieme Avatar asked Jun 26 '20 11:06

Tieme


2 Answers

  1. Remove .edgesIgnoringSafeArea(.all) from the TabView
  2. Add frame to the TabView with screen width and height
  3. Wrap a TabView with ScrollView
  4. Add .edgesIgnoringSafeArea(.all) to the ScrollView
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)     } } 
like image 57
kimigori Avatar answered Oct 22 '22 07:10

kimigori


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

demo

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)     } } 
like image 40
Asperi Avatar answered Oct 22 '22 09:10

Asperi