Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Increase touch slop on iOS #1422

Merged
merged 2 commits into from
Jul 23, 2023
Merged
Changes from all commits
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
36 changes: 28 additions & 8 deletions ui/root/src/iosMain/kotlin/app/tivi/home/TiviUiViewController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

package app.tivi.home

import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.interop.LocalUIViewController
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalViewConfiguration
import androidx.compose.ui.platform.ViewConfiguration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.ComposeUIViewController
import app.tivi.screens.DiscoverScreen
import com.slack.circuit.backstack.rememberSaveableBackStack
Expand All @@ -26,13 +31,28 @@ fun TiviUiViewController(

val uiViewController = LocalUIViewController.current

tiviContent(
backstack = backstack,
navigator = navigator,
onOpenUrl = { url ->
val safari = SFSafariViewController(NSURL(string = url))
uiViewController.presentViewController(safari, animated = true, completion = null)
},
modifier = Modifier,
// Increase the touch slop. The default value of 3.dp is a bit low imo, so we use the
// Android default value of 8.dp
// https://github.com/JetBrains/compose-multiplatform/issues/3397
val vc = LocalViewConfiguration.current.withTouchSlop(
with(LocalDensity.current) { 8.dp.toPx() },
)

CompositionLocalProvider(LocalViewConfiguration provides vc) {
tiviContent(
backstack = backstack,
navigator = navigator,
onOpenUrl = { url ->
val safari = SFSafariViewController(NSURL(string = url))
uiViewController.presentViewController(safari, animated = true, completion = null)
},
modifier = Modifier,
)
}
}

private fun ViewConfiguration.withTouchSlop(
touchSlop: Float,
): ViewConfiguration = object : ViewConfiguration by this {
override val touchSlop: Float = touchSlop
}