From 2dbdb0353f081b3f31184ddcb366faf3c744ff21 Mon Sep 17 00:00:00 2001 From: Nier4ever <20170127nwl@gmail.com> Date: Fri, 20 Sep 2024 22:16:32 +0800 Subject: [PATCH 1/5] fix swipe gesture area --- .../src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt b/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt index 3f79602c57..e18fb454df 100644 --- a/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt +++ b/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt @@ -20,6 +20,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.systemGesturesPadding import androidx.compose.foundation.layout.width import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.rounded.VolumeUp @@ -74,6 +75,7 @@ import me.him188.ani.app.ui.foundation.effects.ComposeKey import me.him188.ani.app.ui.foundation.effects.onKey import me.him188.ani.app.ui.foundation.effects.onPointerEventMultiplatform import me.him188.ani.app.ui.foundation.ifThen +import me.him188.ani.app.ui.foundation.layout.isSystemInFullscreen import me.him188.ani.app.ui.foundation.theme.aniDarkColorTheme import me.him188.ani.app.utils.fixToString import me.him188.ani.app.videoplayer.ui.VideoControllerState @@ -451,7 +453,6 @@ fun VideoGestureHost( Box( modifier .focusRequester(keyboardFocus) - .padding(top = 60.dp) .ifThen(family.swipeToSeek) { swipeToSeek(seekerState, Orientation.Horizontal) } @@ -674,7 +675,6 @@ fun VideoGestureHost( } } } - .padding(top = 60.dp) .combinedClickable( remember { MutableInteractionSource() }, indication = null, @@ -756,6 +756,9 @@ fun VideoGestureHost( ) { Row( Modifier.matchParentSize() + .ifThen(isSystemInFullscreen()) { + systemGesturesPadding() + } .ifThen(family.longPressForFastSkip) { longPressFastSkip(fastSkipState, SkipDirection.FORWARD) }, From a9e718eca9b81a202d100db0b63ae2395c011cec Mon Sep 17 00:00:00 2001 From: Nier4ever <20170127nwl@gmail.com> Date: Mon, 7 Oct 2024 10:36:41 +0800 Subject: [PATCH 2/5] use combineClickableWithFamilyGesture --- .../kotlin/ui/guesture/VideoGestureHost.kt | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt b/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt index db961ce36c..277ec51a80 100644 --- a/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt +++ b/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt @@ -24,11 +24,15 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.asPaddingValues import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.systemGestures import androidx.compose.foundation.layout.systemGesturesPadding import androidx.compose.foundation.layout.width import androidx.compose.material.icons.Icons @@ -675,17 +679,9 @@ fun VideoGestureHost( } } - Box( - modifier - .testTag("VideoGestureHost") - .ifThen(needWorkaroundForFocusManager) { - onFocusEvent { - if (it.hasFocus) { - focusManager.clearFocus() - } - } - } - .combinedClickable( + @Composable + fun Modifier.combineClickableWithFamilyGesture() = this then + combinedClickable( remember { MutableInteractionSource() }, indication = null, onClick = remember(family) { @@ -710,6 +706,17 @@ fun VideoGestureHost( } }, ) + Box( + modifier + .testTag("VideoGestureHost") + .ifThen(needWorkaroundForFocusManager) { + onFocusEvent { + if (it.hasFocus) { + focusManager.clearFocus() + } + } + } + .combineClickableWithFamilyGesture() .ifThen(family.swipeToSeek && enableSwipeToSeek) { val swipeToSeekRequester = rememberAlwaysOnRequester(controllerState, "swipeToSeek") swipeToSeek( @@ -818,6 +825,15 @@ fun VideoGestureHost( ) } } + + // 状态栏区域响应点击手势 + Box( + Modifier.fillMaxWidth() + .ifThen(isSystemInFullscreen()) { + height(WindowInsets.systemGestures.asPaddingValues().calculateTopPadding()) + } + .combineClickableWithFamilyGesture(), + ) } } } From 99b9dc71e2941e04d6d4d51e78d191d524694003 Mon Sep 17 00:00:00 2001 From: Nier4ever <20170127nwl@gmail.com> Date: Mon, 7 Oct 2024 18:16:55 +0800 Subject: [PATCH 3/5] optimize something --- .../commonMain/kotlin/ui/guesture/VideoGestureHost.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt b/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt index 277ec51a80..dfc003f5bc 100644 --- a/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt +++ b/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt @@ -25,11 +25,13 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.WindowInsetsSides import androidx.compose.foundation.layout.asPaddingValues import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.only import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.systemGestures @@ -773,9 +775,7 @@ fun VideoGestureHost( ) { Row( Modifier.matchParentSize() - .ifThen(isSystemInFullscreen()) { - systemGesturesPadding() - } + .systemGesturesPadding() .ifThen(family.longPressForFastSkip) { longPressFastSkip(fastSkipState, SkipDirection.FORWARD) }, @@ -830,7 +830,10 @@ fun VideoGestureHost( Box( Modifier.fillMaxWidth() .ifThen(isSystemInFullscreen()) { - height(WindowInsets.systemGestures.asPaddingValues().calculateTopPadding()) + height( + WindowInsets.systemGestures.only(WindowInsetsSides.Top).asPaddingValues() + .calculateTopPadding(), + ) } .combineClickableWithFamilyGesture(), ) From ced4940783d2e6a7dd3d511e0364bd615dba12d2 Mon Sep 17 00:00:00 2001 From: Nier4ever <20170127nwl@gmail.com> Date: Mon, 7 Oct 2024 20:17:46 +0800 Subject: [PATCH 4/5] optimize something --- .../commonMain/kotlin/ui/guesture/VideoGestureHost.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt b/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt index dfc003f5bc..5d047e41c1 100644 --- a/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt +++ b/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt @@ -25,13 +25,10 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.WindowInsetsSides -import androidx.compose.foundation.layout.asPaddingValues import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.only import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.systemGestures @@ -78,6 +75,7 @@ import androidx.compose.ui.input.key.key import androidx.compose.ui.input.key.onKeyEvent import androidx.compose.ui.input.key.type import androidx.compose.ui.input.pointer.PointerEventType +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.font.FontWeight @@ -831,8 +829,9 @@ fun VideoGestureHost( Modifier.fillMaxWidth() .ifThen(isSystemInFullscreen()) { height( - WindowInsets.systemGestures.only(WindowInsetsSides.Top).asPaddingValues() - .calculateTopPadding(), + with(LocalDensity.current) { + WindowInsets.systemGestures.getTop(this).toDp() + }, ) } .combineClickableWithFamilyGesture(), From 7ab5258c40f0a1b4219f69f8016ad2d1c0a72a4d Mon Sep 17 00:00:00 2001 From: Nier4ever <20170127nwl@gmail.com> Date: Mon, 7 Oct 2024 22:02:51 +0800 Subject: [PATCH 5/5] optimize something --- .../src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt b/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt index 5d047e41c1..02d9b433f8 100644 --- a/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt +++ b/app/shared/video-player/src/commonMain/kotlin/ui/guesture/VideoGestureHost.kt @@ -34,6 +34,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.systemGestures import androidx.compose.foundation.layout.systemGesturesPadding import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.windowInsetsTopHeight import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.rounded.VolumeUp import androidx.compose.material.icons.rounded.BrightnessHigh @@ -75,7 +76,6 @@ import androidx.compose.ui.input.key.key import androidx.compose.ui.input.key.onKeyEvent import androidx.compose.ui.input.key.type import androidx.compose.ui.input.pointer.PointerEventType -import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.font.FontWeight @@ -828,11 +828,7 @@ fun VideoGestureHost( Box( Modifier.fillMaxWidth() .ifThen(isSystemInFullscreen()) { - height( - with(LocalDensity.current) { - WindowInsets.systemGestures.getTop(this).toDp() - }, - ) + windowInsetsTopHeight(WindowInsets.systemGestures) } .combineClickableWithFamilyGesture(), )