6.5 C
Canberra
Wednesday, July 8, 2026

ios – Popover not programatically closing in NavigationStack


Usually, you possibly can programatically shut and open a popover with popover(isPresented: Binding), like so:

struct AContent: View {
  @State personal var showFilter = false

  var physique: some View {
    VStack(spacing: 16) {
      Button("Filter") {
        showFilter = true
      }
      .popover(isPresented: $showFilter, arrowEdge: .backside) {
        VStack(spacing: 16) {
          Button("One") {
            showFilter = false      // dismiss
          }
          Button("Two") {
            showFilter = false
          }
        }
        .padding(24)
        .presentationCompactAdaptation(.popover)
      }
    }
  }
}

Urgent Button “One” or Button “Two” will shut the popover.

Nonetheless, the difficulty I am going through is that it does not work if it is inside a navigation stack. Based mostly on this reproducible code:

struct A: View {
  @State personal var path = NavigationPath()

  var physique: some View {
    NavigationStack(path: $path) {
      Button("Go to filter display") {
        path.append("display")
      }
      .navigationDestination(for: String.self) { _ in
        AContent()
      }
    }
  }
}

@predominant
struct MyApp: App {
  var physique: some Scene {
    WindowGroup {
      A()
    }
  }
}

The popover is just not closing after I choose any of the choices within the popover. I wish to know the explanation why that is taking place. I examined it being inside a TabView, and it really works simply advantageous, but it surely doesn’t work contained in the NavigationStack.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles