Skip to content

Commit

Permalink
Fix app crashing when sharing post/feed on an iPad
Browse files Browse the repository at this point in the history
I tried placing the popover anchor to be based on the share icon root offset. But for some reason the offset from onGloballyPositioned is different from the bounds of the viewcontroller view. I am lazy to debug it and resolve it fully, so showing it in bottom center for the screen instead similar to how the sheet is shown on mobile.

fixes #96
  • Loading branch information
msasikanth committed Sep 15, 2023
1 parent 6c25745 commit 75f52d9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ private fun FeedLabelInput(
@Composable internal expect fun ShareIconButton(content: () -> String)

@Composable
internal fun ShareIconButtonInternal(onClick: () -> Unit) {
IconButton(onClick = onClick) {
internal fun ShareIconButtonInternal(modifier: Modifier = Modifier, onClick: () -> Unit) {
IconButton(modifier = modifier, onClick = onClick) {
Icon(
imageVector = TwineIcons.Share,
contentDescription = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,33 @@
package dev.sasikanth.rss.reader.feeds.ui

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.interop.LocalUIViewController
import kotlinx.cinterop.ExperimentalForeignApi
import platform.CoreGraphics.CGRectGetMaxY
import platform.CoreGraphics.CGRectGetMidX
import platform.CoreGraphics.CGRectMake
import platform.UIKit.UIActivityViewController
import platform.UIKit.popoverPresentationController

@OptIn(ExperimentalForeignApi::class)
@Composable
internal actual fun ShareIconButton(content: () -> String) {
val viewController = LocalUIViewController.current

ShareIconButtonInternal {
val items = listOf(content())
val activityController = UIActivityViewController(items, null)
activityController.popoverPresentationController?.setSourceView(viewController.view)
activityController.popoverPresentationController?.setSourceRect(
CGRectMake(
x = CGRectGetMidX(viewController.view.bounds),
y = CGRectGetMaxY(viewController.view.bounds),
width = 0.0,
height = 0.0
)
)
viewController.presentViewController(activityController, true, null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,39 @@
package dev.sasikanth.rss.reader.home.ui

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.interop.LocalUIViewController
import dev.sasikanth.rss.reader.resources.icons.Share
import dev.sasikanth.rss.reader.resources.icons.TwineIcons
import dev.sasikanth.rss.reader.resources.strings.LocalStrings
import kotlinx.cinterop.ExperimentalForeignApi
import platform.CoreGraphics.CGRectGetMaxY
import platform.CoreGraphics.CGRectGetMidX
import platform.CoreGraphics.CGRectMake
import platform.UIKit.UIActivityViewController
import platform.UIKit.popoverPresentationController

@OptIn(ExperimentalForeignApi::class)
@Composable
internal actual fun PostOptionShareIconButton(postLink: String) {
val viewController = LocalUIViewController.current

PostOptionIconButton(
icon = TwineIcons.Share,
contentDescription = LocalStrings.current.share,
onClick = {
val items = listOf(postLink)
val activityController = UIActivityViewController(items, null)
activityController.popoverPresentationController?.setSourceView(viewController.view)
activityController.popoverPresentationController?.setSourceRect(
CGRectMake(
x = CGRectGetMidX(viewController.view.bounds),
y = CGRectGetMaxY(viewController.view.bounds),
width = 0.0,
height = 0.0
)
)
viewController.presentViewController(activityController, true, null)
}
)
Expand Down

0 comments on commit 75f52d9

Please sign in to comment.