Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加窗口可拖拽区域 #989

Merged
merged 5 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions app/desktop/src/main/kotlin/AniDesktop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ object AniDesktop {
LocalPlatformWindow provides remember(window.windowHandle) {
PlatformWindow(
windowHandle = window.windowHandle,
windowScope = this,
NieR4ever marked this conversation as resolved.
Show resolved Hide resolved
)
},
LocalOnBackPressedDispatcherOwner provides backPressedDispatcherOwner,
Expand Down
23 changes: 13 additions & 10 deletions app/shared/src/commonMain/kotlin/ui/cache/CacheManagementPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import me.him188.ani.app.ui.cache.components.CacheGroupState
import me.him188.ani.app.ui.cache.components.CacheManagementOverallStats
import me.him188.ani.app.ui.foundation.AbstractViewModel
import me.him188.ani.app.ui.foundation.ifThen
import me.him188.ani.app.ui.foundation.interaction.WindowDragArea
import me.him188.ani.app.ui.foundation.produceState
import me.him188.ani.app.ui.foundation.stateOf
import me.him188.ani.app.ui.foundation.theme.AniThemeDefaults
Expand Down Expand Up @@ -264,16 +265,18 @@ fun CacheManagementPage(
Scaffold(
modifier,
topBar = {
TopAppBar(
title = { Text("缓存管理") },
navigationIcon = {
if (showBack) {
TopAppBarGoBackButton()
}
},
colors = appBarColors,
windowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
)
WindowDragArea {
TopAppBar(
title = { Text("缓存管理") },
navigationIcon = {
if (showBack) {
TopAppBarGoBackButton()
}
},
colors = appBarColors,
windowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
)
}
},
contentWindowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom),
) { paddingValues ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.BottomSheetDefaults
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.Scaffold
Expand All @@ -36,6 +34,7 @@ import kotlinx.coroutines.flow.map
import me.him188.ani.app.data.source.media.cache.MediaCacheManager
import me.him188.ani.app.data.source.media.fetch.MediaSourceManager
import me.him188.ani.app.ui.foundation.AbstractViewModel
import me.him188.ani.app.ui.foundation.interaction.WindowDragArea
import me.him188.ani.app.ui.foundation.theme.AniThemeDefaults
import me.him188.ani.app.ui.foundation.widgets.TopAppBarGoBackButton
import me.him188.ani.datasources.api.Media
Expand Down Expand Up @@ -97,16 +96,18 @@ fun MediaCacheDetailsPage(
Scaffold(
modifier = modifier,
topBar = {
TopAppBar(
title = { Text("详情") },
navigationIcon = {
if (allowBack) {
TopAppBarGoBackButton()
}
},
colors = AniThemeDefaults.topAppBarColors(),
windowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
)
WindowDragArea {
TopAppBar(
title = { Text("详情") },
navigationIcon = {
if (allowBack) {
TopAppBarGoBackButton()
}
},
colors = AniThemeDefaults.topAppBarColors(),
windowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
)
}
},
contentWindowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom),
) { paddingValues ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import me.him188.ani.app.data.source.media.selector.eventHandling
import me.him188.ani.app.navigation.LocalNavigator
import me.him188.ani.app.ui.external.placeholder.placeholder
import me.him188.ani.app.ui.foundation.AbstractViewModel
import me.him188.ani.app.ui.foundation.interaction.WindowDragArea
import me.him188.ani.app.ui.foundation.launchInBackground
import me.him188.ani.app.ui.foundation.produceState
import me.him188.ani.app.ui.foundation.stateOf
Expand Down Expand Up @@ -277,16 +278,18 @@ fun SubjectCachePageScaffold(
Scaffold(
modifier,
topBar = {
TopAppBar(
title = {
title()
},
navigationIcon = {
TopAppBarGoBackButton()
},
colors = appBarColors,
windowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
)
WindowDragArea {
TopAppBar(
title = {
title()
},
navigationIcon = {
TopAppBarGoBackButton()
},
colors = appBarColors,
windowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
)
}
},
contentWindowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom),
) { paddingValues ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import me.him188.ani.app.data.source.session.AuthState
import me.him188.ani.app.navigation.LocalNavigator
import me.him188.ani.app.tools.rememberUiMonoTasker
import me.him188.ani.app.ui.foundation.LocalPlatform
import me.him188.ani.app.ui.foundation.interaction.WindowDragArea
import me.him188.ani.app.ui.foundation.pagerTabIndicatorOffset
import me.him188.ani.app.ui.foundation.theme.AniThemeDefaults
import me.him188.ani.app.ui.foundation.widgets.PullToRefreshBox
Expand Down Expand Up @@ -121,43 +122,45 @@ fun CollectionPane(
topBar = {
val topAppBarColors = AniThemeDefaults.topAppBarColors()
Column(modifier = Modifier.fillMaxWidth()) {
TopAppBar(
title = { Text("我的追番") },
modifier = Modifier,
actions = {
if (!showSessionErrorInList) {
SessionTipsIcon(vm.authState)
}
WindowDragArea {
TopAppBar(
title = { Text("我的追番") },
modifier = Modifier,
actions = {
if (!showSessionErrorInList) {
SessionTipsIcon(vm.authState)
}

if (showCacheButton) {
TextButtonUpdateLogo()
if (showCacheButton) {
TextButtonUpdateLogo()

IconButton(onClickCaches) {
Icon(Icons.Rounded.Download, "缓存管理")
IconButton(onClickCaches) {
Icon(Icons.Rounded.Download, "缓存管理")
}
}
}

if (LocalPlatform.current.isDesktop()) {
// PC 无法下拉刷新
val refreshTasker = rememberUiMonoTasker()
IconButton(
{
val type = COLLECTION_TABS_SORTED[pagerState.currentPage]
val collection = vm.collectionsByType(type)
if (!refreshTasker.isRunning) {
refreshTasker.launch {
collection.subjectCollectionColumnState.manualRefresh()
if (LocalPlatform.current.isDesktop()) {
// PC 无法下拉刷新
val refreshTasker = rememberUiMonoTasker()
IconButton(
{
val type = COLLECTION_TABS_SORTED[pagerState.currentPage]
val collection = vm.collectionsByType(type)
if (!refreshTasker.isRunning) {
refreshTasker.launch {
collection.subjectCollectionColumnState.manualRefresh()
}
}
}
},
) {
Icon(Icons.Rounded.Refresh, null)
},
) {
Icon(Icons.Rounded.Refresh, null)
}
}
}
},
colors = topAppBarColors,
windowInsets = windowInsets.only(WindowInsetsSides.Top),
)
},
colors = topAppBarColors,
windowInsets = windowInsets.only(WindowInsetsSides.Top),
)
}

ScrollableTabRow(
selectedTabIndex = pagerState.currentPage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import me.him188.ani.app.platform.LocalContext
import me.him188.ani.app.ui.foundation.ImageViewer
import me.him188.ani.app.ui.foundation.LocalPlatform
import me.him188.ani.app.ui.foundation.ifThen
import me.him188.ani.app.ui.foundation.interaction.WindowDragArea
import me.him188.ani.app.ui.foundation.interaction.nestedScrollWorkaround
import me.him188.ani.app.ui.foundation.layout.ConnectedScrollState
import me.him188.ani.app.ui.foundation.layout.PaddingValuesSides
Expand Down Expand Up @@ -245,33 +246,41 @@ fun SubjectDetailsPage(
Scaffold(
topBar = {
if (showTopBar) {
Box {
// 透明背景的, 总是显示
TopAppBar(
title = {},
navigationIcon = { TopAppBarGoBackButton() },
actions = {
IconButton(onClickOpenExternal) {
Icon(Icons.AutoMirrored.Outlined.OpenInNew, null)
}
},
colors = AniThemeDefaults.topAppBarColors().copy(containerColor = Color.Transparent),
windowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
)

// 有背景, 仅在滚动一段距离后使用
AnimatedVisibility(connectedScrollState.isScrolledTop, enter = fadeIn(), exit = fadeOut()) {
WindowDragArea {
Box {
// 透明背景的, 总是显示
TopAppBar(
title = { Text(state.info.displayName, maxLines = 1, overflow = TextOverflow.Ellipsis) },
title = {},
navigationIcon = { TopAppBarGoBackButton() },
actions = {
IconButton(onClickOpenExternal) {
Icon(Icons.AutoMirrored.Outlined.OpenInNew, null)
}
},
colors = AniThemeDefaults.topAppBarColors(),
colors = AniThemeDefaults.topAppBarColors().copy(containerColor = Color.Transparent),
windowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
)

// 有背景, 仅在滚动一段距离后使用
AnimatedVisibility(connectedScrollState.isScrolledTop, enter = fadeIn(), exit = fadeOut()) {
TopAppBar(
title = {
Text(
state.info.displayName,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
},
navigationIcon = { TopAppBarGoBackButton() },
actions = {
IconButton(onClickOpenExternal) {
Icon(Icons.AutoMirrored.Outlined.OpenInNew, null)
}
},
colors = AniThemeDefaults.topAppBarColors(),
windowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.app.ui.foundation.interaction

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
actual inline fun WindowDragArea(
modifier: Modifier,
crossinline content: @Composable () -> Unit
) {
content()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.app.ui.foundation.interaction

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
expect inline fun WindowDragArea(
modifier: Modifier = Modifier,
crossinline content: @Composable () -> Unit = {}
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.window.WindowScope

actual open class PlatformWindow(
val windowHandle: Long,
val windowScope: WindowScope? = null
) {
internal var savedWindowState: SavedWindowState? = null

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.app.ui.foundation.interaction

import androidx.compose.foundation.window.WindowDraggableArea
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import me.him188.ani.app.ui.foundation.layout.LocalPlatformWindow

@Composable
actual inline fun WindowDragArea(
modifier: Modifier,
crossinline content: @Composable () -> Unit
) {
val windowScope = LocalPlatformWindow.current.windowScope
windowScope?.run {
WindowDraggableArea(modifier) {
content()
}
} ?: content()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.app.ui.foundation.interaction

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
actual inline fun WindowDragArea(
modifier: Modifier,
crossinline content: @Composable () -> Unit
) {
content()
}
Loading
Loading