Created
May 3, 2023 12:53
-
-
Save Skeptick/d877f871a2cd15eb5091d1aa05d92c46 to your computer and use it in GitHub Desktop.
Present UIActivityViewController from KMM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun UIActivityViewController.show() { | |
val topController = TopMostController ?: return | |
if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) { | |
popoverPresentationController()!!.apply { | |
sourceView = topController.presentingViewController!!.view | |
sourceRect = CGRectMake(0.0, 0.0, 0.0, 0.0) | |
} | |
} | |
topController.presentViewController(this, true, null) | |
} | |
@Suppress("UNCHECKED_CAST") | |
private val TopMostController: UIViewController? | |
get() { | |
val window = (UIApplication.sharedApplication.windows as List<UIWindow>).firstOrNull() ?: return null | |
var topController = window.rootViewController ?: return null | |
while (topController.presentedViewController != null) topController = topController.presentedViewController!! | |
return topController | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment