Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix share sheet presentation crash on iPad
Browse files Browse the repository at this point in the history
mohamede1945 committed Nov 25, 2023
1 parent 2c7ab89 commit 587ff9f
Showing 2 changed files with 7 additions and 15 deletions.
7 changes: 7 additions & 0 deletions Features/SettingsFeature/SettingsRootViewModel.swift
Original file line number Diff line number Diff line change
@@ -101,12 +101,19 @@ final class SettingsRootViewModel: ObservableObject {
}

func shareApp() {
logger.info("Settings: Share the app.")
let url = URL(validURL: "https://itunes.apple.com/app/id1118663303")
let appName = "Quran - by Quran.com - قرآن"

let activityViewController = UIActivityViewController(
activityItems: [appName, url], applicationActivities: nil
)
let view = navigationController?.view
let viewBound = view.map { CGRect(x: $0.bounds.midX, y: $0.bounds.midY, width: 0, height: 0) }
activityViewController.modalPresentationStyle = .formSheet
activityViewController.popoverPresentationController?.permittedArrowDirections = []
activityViewController.popoverPresentationController?.sourceView = view
activityViewController.popoverPresentationController?.sourceRect = viewBound ?? .zero
navigationController?.present(activityViewController, animated: true)
}

15 changes: 0 additions & 15 deletions UI/UIx/UIKit/Popover/PopoverPresenter.swift
Original file line number Diff line number Diff line change
@@ -64,21 +64,6 @@ extension PopoverPresenter {
presented.popoverPresentationController?.permittedArrowDirections = permittedArrowDirections
presenting.present(presented, animated: animated, completion: completion)
}

func present(
presenting: UIViewController,
presented: UIViewController,
pointingTo barButtonItem: UIBarButtonItem,
permittedArrowDirections: UIPopoverArrowDirection = .any,
animated: Bool = true,
completion: (() -> Void)? = nil
) {
presented.modalPresentationStyle = .popover
presented.popoverPresentationController?.delegate = self
presented.popoverPresentationController?.barButtonItem = barButtonItem
presented.popoverPresentationController?.permittedArrowDirections = permittedArrowDirections
presenting.present(presented, animated: animated, completion: completion)
}
}

extension UIViewController {

0 comments on commit 587ff9f

Please sign in to comment.