Search code examples
swiftswiftuiaccessibilityswiftui-navigationlink

Eliminate NavigationLink button shape in accessibility mode


I have a small SwiftUI project that supports "Button Shapes" in accessibility mode.
Button Shapes in accessibility mode
But I found that when I enable this mode, there is a small white rectangle in the center of the screen, which I guess is the NavigationLink I put for SecondView.
Here is my code:

struct FirstView: View {
    @State private var activeSecondView = false
    var body: some View {
        NavigationView {
            VStack {
                Text("FirstView")
                Button("Tap to show second view") {
                    self.activeSecondView = true
                }
            }
            .overlay(NavigationLink(destination: Text("SecondView"), isActive: $activeSecondView) {EmptyView()})
        }
    }
}

And it runs like this(The redundant rectangle is circled in red): Extra tappable area in the center

Is there any way to eliminate or hide this small white rectangle while "Button Shapes" is enable?


Solution

  • Try next (not tested just idea)

    .background(
       NavigationLink(destination: Text("SecondView"), isActive: $activeSecondView) 
           {EmptyView()}.opacity(0)          // << this !!
    )