I had a similar issue where sometimes the action sheet would show from a button in a scroll view but after the button is scrolled or reloaded, the action sheet would stop showing.
After searching the web and coming here, I realized that there is something really buggy with actionSheet and its attachment to the binding. So just for debugging I added a .onChange(of:) after the actionSheet call to log the state of the bool binding. After adding that then magically the action sheet was showing consistently.
So maybe you can try your code again with something like this:
struct ContentView: View {
@State private var showNewControlActionSheet = false
var body: some View {
NavigationView {
Text("test")
.navigationBarTitle("Test")
.navigationBarItems(trailing: HStack() {
Button(action: {
self.showNewControlActionSheet = true
}) {
HStack {
Image(systemName: "plus")
.padding(10)
.clipShape(Circle())
}
}
.actionSheet(isPresented: $showNewControlActionSheet) {
ActionSheet(title: Text("Change background"), message: Text("Select a new color"), buttons: [
.default(Text("Red")) { },
.default(Text("Green")) { },
.default(Text("Blue")) { },
.cancel()
])
}
// 👇 HERE IS THE TRICK I USED TO GET IT TO WORK
.onChange(of: showNewControlActionSheet) { newValue in
print("Action sheet show flag is: \(newValue)")
}
})
}.navigationViewStyle(StackNavigationViewStyle())
}
}
I really hope this helps anyone. Hopefully Apple can fix this weird bug
Post
Replies
Boosts
Views
Activity
I got to meet with some Apple Engineers at WWDC22. They suggested to create a UIViewRepresentable that is a wrapper around the ASAuthorizationAppleIDButton.
Then hook it up to a ASAuthorizationController and set the presentationContextProvider.
let request = ASAuthorizationAppleIDProvider().createRequest()
request.requestedScopes = [.fullName, .email]
let controller = ASAuthorizationController(authorizationRequests: [request])
controller.delegate = self
controller.presentationContextProvider = self
controller.performRequests()
And then on the presentationContextProvider protocol implementation provide the proper key window to use for popup presentation.
public func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
let keyWindow = (UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.window
return keyWindow ?? ASPresentationAnchor()
}
That's what I tried. I used this example as my template for creating the SwiftUI wrapper button and a coordinator.
SiwaButton.swift
Hi @eskimo, I was curious about how to create an experience similar to NSSavePanel but for Mac Catalyst. I would like the user to choose the location they want to export a file before doing the export process.
I tried using UIDocumentPickerViewController but it is expecting a file URL at initialization time before it can open a export controller. So I tried creating a temporary file using File manager, but that caused problems because the document picker did not know the file type of the export. NSSavePanel is what I'm looking for but thats only available in AppKit.
Thanks