@@ -792,20 +792,8 @@ struct FilePreviewView: View {
792
792
. menuStyle ( . button)
793
793
794
794
Button ( action: {
795
- // share sheet call goes here
796
- // Dismiss any presented views first
797
- if let windowScene = UIApplication . shared. connectedScenes. first as? UIWindowScene ,
798
- let window = windowScene. windows. first,
799
- let rootVC = window. rootViewController {
800
- rootVC. dismiss ( animated: true ) {
801
- let activityVC = UIActivityViewController ( activityItems: [ URL ( string: file. url) ?? " " ] , applicationActivities: nil )
802
- if let popover = activityVC. popoverPresentationController {
803
- popover. sourceView = rootVC. view
804
- popover. sourceRect = CGRect ( x: rootVC. view. bounds. midX, y: rootVC. view. bounds. midY, width: 0 , height: 0 )
805
- }
806
- rootVC. present ( activityVC, animated: true )
807
- }
808
- }
795
+ ShareSheet . present ( items: [ URL ( string: file. url) ?? " " ] )
796
+
809
797
} ) {
810
798
Image ( systemName: " square.and.arrow.up " )
811
799
. font ( . system( size: 20 ) )
@@ -819,10 +807,28 @@ struct FilePreviewView: View {
819
807
. frame ( width: 155 , height: 44 )
820
808
. cornerRadius ( 20 )
821
809
}
822
-
823
810
}
824
811
}
812
+ }
813
+ }
814
+
815
+ struct ShareSheet {
816
+ static func present( items: [ Any ] ) {
817
+ guard let rootVC = UIApplication . shared. connectedScenes
818
+ . compactMap ( { ( $0 as? UIWindowScene ) ? . keyWindow } )
819
+ . first? . rootViewController else {
820
+ return
821
+ }
822
+
823
+ let activityVC = UIActivityViewController ( activityItems: items, applicationActivities: nil )
824
+
825
+ // Find the topmost presented view controller
826
+ var topVC = rootVC
827
+ while let presented = topVC. presentedViewController {
828
+ topVC = presented
829
+ }
825
830
831
+ topVC. present ( activityVC, animated: true )
826
832
}
827
833
}
828
834
0 commit comments