3

I have a ShareLink inside an ActionSheet (confirmationDialog) but it's not opening. Can anyone confirm if this is possible or not? I imagine it's something to do with the action sheet being dismissed at the same time.

.confirmationDialog("", isPresented: $isShowingMoreActionSheet, titleVisibility: .hidden) {
        
        if let url = URL(string: "https://www.google.com") {
            ShareLink("Share", item: url)
        }
    }
Dan
  • 543
  • 2
  • 13
  • I guess you're right. When the confirmation sheet dismisses, the ShareSheet will also be dismissed. Also why do you want the ShareLink inside of a confirmationDialog? – Timo Jan 13 '23 at 13:36
  • Hey, I have a "more" button that opens the action sheet to give the user multiple actions, one of which is to share a link. Seems link a pretty standard feature. – Dan Jan 13 '23 at 13:47
  • I guess the sharing via confirmationDialog can be done by using the old actionSheet from UIKit. If you want to use the ShareLink I would recommend using it inside a Menu. See documentation for Menu here: https://developer.apple.com/documentation/swiftui/menu – Timo Jan 13 '23 at 13:50
  • Ooo, interesting! Good shout thanks – Dan Jan 13 '23 at 13:52
  • I was looking for another answer when I came across this post: https://stackoverflow.com/questions/73424912/swiftui-presenting-multiple-sharelinks-in-a-menu. Appearently the ShareLink doesn't really work well with being displayed in a Menu or ConfirmationDialog. Maybe Apple will fix this in a newer version, but for now it seems to be impossible. However there is a solution in the StackOverflow Question I sent you in this comment. – Timo Jan 13 '23 at 14:38
  • I'm working with iOS 16.1 so it's working now thanks! – Dan Jan 13 '23 at 14:49
  • Spoke too soon. It's very temperamental. Some times it works fine sometimes it does nothing. It's also all happening in a full screen cover which I think causes more issues – Dan Jan 14 '23 at 12:53
  • Actually it does work. What doesn't work is if I have a Menu open and then tap a ShareLink (on the view, not in the menu) it makes the ShareLink unusable – Dan Jan 16 '23 at 12:59
  • Actually what you're describing is the same for every buttons. A well known `Menu` bug not yet resolved. And the solution to fix this is really boring! – Alexnnd Jun 15 '23 at 09:29

1 Answers1

1

The Sharelink actually is a button, which is documented in the developer tools:

People tap or click on a share link to present a share interface. The link typically uses a system-standard appearance for the link; you only need to supply the content to share.

Therefore a sharelink is not going to work within an if let

Hope this helps!

Fabian H.
  • 458
  • 4
  • 11