mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 22:36:00 +00:00
feat(ui): a Launcher setting turns page swipes off, and edge swipes in landscape leave the page alone (#2924)
This commit is contained in:
1 parent
a8d03d687f
commit
1f70d43fe2
39 files changed
+105
-5
No files matched your search
@@ -53,6 +53,13 @@ object AppUiPrefs {
|
||||
context.getSharedPreferences("app-ui", Context.MODE_PRIVATE).edit().putBoolean("hide-home-from-recents", hidden).apply()
|
||||
}
|
||||
|
||||
fun pageSwipe(context: Context): Boolean =
|
||||
context.getSharedPreferences("app-ui", Context.MODE_PRIVATE).getBoolean("page-swipe", true)
|
||||
|
||||
fun setPageSwipe(context: Context, on: Boolean) {
|
||||
context.getSharedPreferences("app-ui", Context.MODE_PRIVATE).edit().putBoolean("page-swipe", on).apply()
|
||||
}
|
||||
|
||||
internal fun normalizeScale(percent: Int): Int = percent.takeIf { it in scales } ?: DEFAULT_SCALE
|
||||
|
||||
fun scale(context: Context): Int = normalizeScale(
|
||||
|
||||
@@ -762,6 +762,8 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
onRailSelect(key)
|
||||
}, a)
|
||||
CompositionLocalProvider(LocalShowSection provides { key -> selected = key }) {
|
||||
val swipeContext = androidx.compose.ui.platform.LocalContext.current
|
||||
remember { com.droiddeck.launcher.core.AppUiPrefs.pageSwipe(swipeContext).also { PageSwipe.on = it } }
|
||||
val agentKeyboardOpen = openTab == "agent" && WindowInsets.ime.getBottom(androidx.compose.ui.platform.LocalDensity.current) > 0
|
||||
LauncherLayout(
|
||||
bottomNavigation && !s.dualScreen, pal.line,
|
||||
@@ -787,7 +789,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
) {
|
||||
Pane(
|
||||
s, selected, a, page,
|
||||
Modifier.fillMaxSize().then(paneFocus).pageSwipe({ !processSettingsPageVisible && appToChooseDisplay == null }) { dir ->
|
||||
Modifier.fillMaxSize().then(paneFocus).pageSwipe({ !processSettingsPageVisible && appToChooseDisplay == null }, edgeGuard = { !bottomNavigation }) { dir ->
|
||||
val keys = navigationKeys(s)
|
||||
val at = keys.indexOf(railSelectionNow.value)
|
||||
if (at >= 0) keys.getOrNull(at + dir)?.let { key ->
|
||||
|
||||
@@ -516,6 +516,13 @@ internal fun SetupPanel(
|
||||
if (s.launcherFullscreen) stringResource(R.string.setup_fullscreen_on) else stringResource(R.string.setup_fullscreen_off),
|
||||
s.launcherFullscreen,
|
||||
) { a.onLauncherFullscreen(it) }
|
||||
ToggleRow(
|
||||
host, "page-swipe", stringResource(R.string.setup_page_swipe),
|
||||
stringResource(R.string.setup_page_swipe_hint), PageSwipe.on,
|
||||
) { on ->
|
||||
PageSwipe.on = on
|
||||
com.droiddeck.launcher.core.AppUiPrefs.setPageSwipe(ctx, on)
|
||||
}
|
||||
ToggleRow(
|
||||
host, "controller-haptics", stringResource(R.string.setup_controller_haptics),
|
||||
stringResource(R.string.setup_controller_haptics_hint),
|
||||
|
||||
@@ -6,6 +6,8 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
@@ -13,26 +15,40 @@ import androidx.compose.ui.input.pointer.PointerEventPass
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.input.pointer.util.VelocityTracker
|
||||
import androidx.compose.ui.input.pointer.util.addPointerInputChange
|
||||
import androidx.compose.ui.layout.LayoutCoordinates
|
||||
import androidx.compose.ui.layout.findRootCoordinates
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlin.math.abs
|
||||
|
||||
internal object PageSwipe {
|
||||
var locks by mutableIntStateOf(0)
|
||||
var direction by mutableIntStateOf(0)
|
||||
var on by mutableStateOf(true)
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun Modifier.pageSwipe(enabled: () -> Boolean, onSwipe: (Int) -> Unit): Modifier {
|
||||
internal fun Modifier.pageSwipe(enabled: () -> Boolean, edgeGuard: () -> Boolean = { false }, onSwipe: (Int) -> Unit): Modifier {
|
||||
val enabledNow by rememberUpdatedState(enabled)
|
||||
val edgeGuardNow by rememberUpdatedState(edgeGuard)
|
||||
val onSwipeNow by rememberUpdatedState(onSwipe)
|
||||
return pointerInput(Unit) {
|
||||
val placed = remember { arrayOfNulls<LayoutCoordinates>(1) }
|
||||
return onGloballyPositioned { placed[0] = it }.pointerInput(Unit) {
|
||||
val distance = 72.dp.toPx()
|
||||
val flingDistance = 32.dp.toPx()
|
||||
val flingVelocity = 900.dp.toPx()
|
||||
val slop = viewConfiguration.touchSlop
|
||||
val edge = 32.dp.toPx()
|
||||
awaitEachGesture {
|
||||
val down = awaitFirstDown(requireUnconsumed = false, pass = PointerEventPass.Final)
|
||||
if (!enabledNow() || PageSwipe.locks > 0) return@awaitEachGesture
|
||||
if (!PageSwipe.on || !enabledNow() || PageSwipe.locks > 0) return@awaitEachGesture
|
||||
// A swipe in from the screen's edge brings back hidden system bars; it should not also turn the page.
|
||||
if (edgeGuardNow()) {
|
||||
val at = placed[0]?.takeIf { it.isAttached }
|
||||
val x = at?.localToRoot(down.position)?.x ?: down.position.x
|
||||
val width = at?.findRootCoordinates()?.size?.width?.toFloat() ?: size.width.toFloat()
|
||||
if (x < edge || x > width - edge) return@awaitEachGesture
|
||||
}
|
||||
val tracker = VelocityTracker()
|
||||
tracker.addPointerInputChange(down)
|
||||
var total = Offset.Zero
|
||||
@@ -48,7 +64,7 @@ internal fun Modifier.pageSwipe(enabled: () -> Boolean, onSwipe: (Int) -> Unit):
|
||||
if (!mine && abs(total.x) > slop && abs(total.x) > abs(total.y) * 2f) mine = true
|
||||
if (mine) change.consume()
|
||||
}
|
||||
if (!mine || PageSwipe.locks > 0) return@awaitEachGesture
|
||||
if (!mine || !PageSwipe.on || PageSwipe.locks > 0) return@awaitEachGesture
|
||||
val vx = tracker.calculateVelocity().x
|
||||
val horizontal = abs(total.x) > abs(total.y) * 1.5f
|
||||
val far = abs(total.x) > distance
|
||||
|
||||
@@ -108,6 +108,7 @@ internal object SettingsIndex {
|
||||
s(SettingsSection.LAUNCHER, R.string.setup_launcher_orientation, "rotate", "portrait"),
|
||||
s(SettingsSection.LAUNCHER, R.string.setup_session_orientation, "rotate", "portrait"),
|
||||
s(SettingsSection.LAUNCHER, R.string.setup_fullscreen),
|
||||
s(SettingsSection.LAUNCHER, R.string.setup_page_swipe, "gesture"),
|
||||
s(SettingsSection.LAUNCHER, R.string.setup_controller_haptics, "vibration", "rumble"),
|
||||
s(SettingsSection.LAUNCHER, R.string.setup_dual_screen_launcher, "thor", "second screen", "bottom screen"),
|
||||
s(SettingsSection.LAUNCHER, R.string.setup_low_storage_warning),
|
||||
|
||||
Reference in new issue
Block a user