Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FB7367637: SwiftUI .popover() in a List cannot be dismissed from inside the popover view on macOS #50

Closed
sindresorhus opened this issue Oct 11, 2019 · 2 comments

Comments

@sindresorhus
Copy link
Member

sindresorhus commented Oct 11, 2019

  • Date: 2019-10-11
  • Resolution: Fixed
  • Area: SwiftUI Framework
  • OS: macOS 10.15
  • Type: Incorrect/Unexpected Behavior

Description

I have a List of buttons. When a button is clicked, a popover is shown from that list item. Inside the popover, there's a "Dismiss" button that is supposed to dismiss the popover, but that doesn't work.

I have included a test project that reproduces the issue. I'm also including the code inline as it's not much:

import SwiftUI

// Reproduce: Click one of the "Click me" button and then click "Dismiss" in the popover. Notice how the popover is not dismissed.

struct PopoverView: View {
	@Environment(\.presentationMode) var presentationMode

	var body: some View {
		Button(action: {
			self.presentationMode.wrappedValue.dismiss()
		}) {
			Text("Dismiss")
				.padding()
		}
	}
}

struct ListItemView: View {
	let index: Int
	@State var showPopover = false

	var body: some View {
		Group {
			Button(action: {
				self.showPopover = true
			}) {
				Text("Click me \(index)")
			}
			Text("\(index)")
				.popover(isPresented: self.$showPopover) {
					PopoverView()
				}
		}
	}
}

struct ContentView: View {
    var body: some View {
		VStack {
			List {
				ForEach(0...5, id: \.self) { index in
					ListItemView(index: index)
				}
			}
		}
			.frame(width: 400, height: 400)
    }
}

Files

swiftui-dismiss-popover-in-list-testcase.zip

@sindresorhus
Copy link
Member Author

Confirmed fixed in macOS 10.15.1.

@abara-kedavra
Copy link

The same if you have "self.presentationMode.wrappedValue.dismiss()" inside button that appears in a modal view later, after some event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants