0

In my app using SwiftUI, when I want to implement split view into my app, everything works well on iPhone and even on iPad unless I go to split screen mode when using multiple apps. Here is the code : of ContentView(), if you need more don't hesitate to ask.

import SwiftUI
import GoogleMobileAds

struct ContentView: View {

    @State var isAboutViewPresented = false

    var body: some View {
        NavigationView {
            DefaultView()
            NewView()
        }//.navigationViewStyle(StackNavigationViewStyle())
        // To get "full screen" on iPad -> not in a split view style
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
            .environment(\.locale, .init(identifier: "fr"))
    }
}


struct DefaultView: View {

    @State var isAboutViewPresented = false

    var body: some View {
        VStack {
            List {
                Section(header: Text("main"), footer: Text("showChartOfDesiredParameter")) {
                    NavigationLink(destination: ApertureStopChartView()) {
                        Text("apertureStopChart")
                    }
                    NavigationLink(destination: ShutterSpeedStopChartView()) {
                        Text("shutterSpeedStopChart")
                    }
                    NavigationLink(destination: ISOStopChartView()) {
                        Text("isoStopChart")
                    }
                }

                Section(header: Text("moreInfo")) {
                    NavigationLink(destination: WhatIsStopView()) {
                        Text("whatIsAStopInPhotography")
                    }
                }
            }.listStyle(GroupedListStyle())

            VStack {
                AdView().frame(width: 320, height: 50)
            }.edgesIgnoringSafeArea([.top, .leading, .trailing])

        }



            .navigationBarTitle(Text("Stop Chart"))
            .navigationBarItems(trailing:
                Button(action: {
                    self.isAboutViewPresented = true
                }) {Image(systemName: "info.circle")
                    .font(.title)
                    .foregroundColor(.blue)
                }.sheet(isPresented: $isAboutViewPresented, content: { AboutView(onDismiss: {
                    self.isAboutViewPresented = false
                })

                })
        )
    }
}


struct NewView: View {
    var body: some View {
        VStack {
            Image("StopChart-icon@1024px")
            .resizable()
                .frame(width: 400, height: 400, alignment: .center)
                .cornerRadius(23)
            HStack {
                Text("swipeToTheRight").font(.largeTitle)
                Image(systemName: "arrow.right").font(.largeTitle)
            }
        }
    }
}


struct AdView: UIViewRepresentable {

    func makeUIView(context: UIViewRepresentableContext<AdView>) -> GADBannerView {

        let banner = GADBannerView(adSize: kGADAdSizeBanner)

        banner.adUnitID = "ca-app-pub-3940256099942544/2934735716"
        banner.rootViewController = UIApplication.shared.windows.first?.rootViewController
        banner.load(GADRequest())
        return banner
    }

    func updateUIView(_ uiView: GADBannerView, context: UIViewRepresentableContext<AdView>) {

    }
}

GIF to show you the bug

Thanks a lot in advance for your help.

1 Answers1

1

I got your code sample down to this to reproduce the bug, and it seems it's the "listStyle(GroupedListStyle())" that is causing it. Removing that and the bug goes away.

import SwiftUI

struct ContentView: View {

    var body: some View {
        NavigationView {
            DefaultView()
        }
    }
}

struct DefaultView: View {

    @State var isAboutViewPresented = false

    var body: some View {
        VStack {
            List {
                NavigationLink(destination: Text("TEST1")) {
                    Text("TEST1")
                }
            }
            .listStyle(GroupedListStyle()) // <-- causing bug
        }
    }
}
Paul Colton
  • 246
  • 2
  • 5
  • I've encountered the same bug at the moment and narrowed it down to the same thing, `GroupedListStyle()`. I filed a Radar for it and am attaching a link to this question as an additional reference – sahandnayebaziz Aug 31 '20 at 00:45
  • From my testing, this appears to be fixed in the latest iOS 14 Developer Beta + Xcode 12 Beta! – sahandnayebaziz Aug 31 '20 at 00:53