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

fix: ipad share #336

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.ooni.probe.shared.PlatformInfo
import platform.BackgroundTasks.BGProcessingTask
import platform.BackgroundTasks.BGProcessingTaskRequest
import platform.BackgroundTasks.BGTaskScheduler
import platform.CoreGraphics.CGRectMake
import platform.Foundation.NSBundle
import platform.Foundation.NSDate
import platform.Foundation.NSDocumentDirectory
Expand All @@ -53,8 +54,12 @@ import platform.UIKit.UIActivityViewController
import platform.UIKit.UIApplication
import platform.UIKit.UIDevice
import platform.UIKit.UIDeviceBatteryState
import platform.UIKit.UIModalPresentationOverCurrentContext
import platform.UIKit.UIPasteboard
import platform.UIKit.UIUserInterfaceIdiomPad
import platform.UIKit.UIViewController
import platform.UIKit.UI_USER_INTERFACE_IDIOM
import platform.UIKit.popoverPresentationController
import platform.darwin.NSObject
import platform.darwin.NSObjectMeta

Expand Down Expand Up @@ -178,12 +183,23 @@ class SetupDependencies(
setToRecipients(listOf(action.to))
setSubject(action.subject)
setMessageBody(action.body, isHTML = false)
}.let {
findCurrentViewController()?.presentViewController(
it,
true,
null,
)
}.let { mailComposer ->

findCurrentViewController()?.let { viewController ->

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
mailComposer.popoverPresentationController?.sourceView = viewController.view

mailComposer.modalPresentationStyle = UIModalPresentationOverCurrentContext
mailComposer.popoverPresentationController?.sourceRect = CGRectMake(0.0, 0.0, 200.0, 200.0)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this code is repeated 3 times, maybe we can create a function for it?


viewController.presentViewController(
mailComposer,
true,
null,
)
}
}
return true
} else {
Expand Down Expand Up @@ -277,11 +293,16 @@ class SetupDependencies(
activityItems = listOf(share.text),
applicationActivities = null,
)
activityViewController.excludedActivityTypes =
listOf(UIActivityTypeAirDrop, UIActivityTypePostToFacebook)

findCurrentViewController()?.let {
it.presentViewController(
findCurrentViewController()?.let { viewController ->
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
activityViewController.popoverPresentationController?.sourceView = viewController.view

activityViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext
activityViewController.popoverPresentationController?.sourceRect = CGRectMake(0.0, 0.0, 200.0, 200.0)
}

viewController.presentViewController(
activityViewController,
true,
null,
Expand All @@ -304,8 +325,15 @@ class SetupDependencies(
activityViewController.excludedActivityTypes =
listOf(UIActivityTypeAirDrop, UIActivityTypePostToFacebook)

findCurrentViewController()?.let {
it.presentViewController(
findCurrentViewController()?.let { viewController ->
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
activityViewController.popoverPresentationController?.sourceView = viewController.view

activityViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext
activityViewController.popoverPresentationController?.sourceRect = CGRectMake(0.0, 0.0, 200.0, 200.0)
}

viewController.presentViewController(
activityViewController,
true,
null,
Expand Down
Loading