Skip to content

Commit

Permalink
apply WindowDragArea
Browse files Browse the repository at this point in the history
  • Loading branch information
NieR4ever committed Sep 21, 2024
1 parent af2058e commit 251880f
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 151 deletions.
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
Expand Up @@ -44,6 +44,7 @@ import kotlinx.coroutines.launch
import me.him188.ani.app.navigation.AniNavigator
import me.him188.ani.app.navigation.OverrideNavigation
import me.him188.ani.app.ui.foundation.LocalPlatform
import me.him188.ani.app.ui.foundation.interaction.WindowDragArea
import me.him188.ani.app.ui.foundation.layout.cardVerticalPadding
import me.him188.ani.app.ui.foundation.pagerTabIndicatorOffset
import me.him188.ani.app.ui.foundation.theme.AniThemeDefaults
Expand Down Expand Up @@ -82,16 +83,18 @@ fun SettingsPage(
Scaffold(
modifier,
topBar = {
TopAppBar(
title = { Text("设置") },
navigationIcon = {
if (showBack) {
TopAppBarGoBackButton()
}
},
colors = appBarColors,
windowInsets = contentWindowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
)
WindowDragArea {
TopAppBar(
title = { Text("设置") },
navigationIcon = {
if (showBack) {
TopAppBarGoBackButton()
}
},
colors = appBarColors,
windowInsets = contentWindowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
)
}
},
contentWindowInsets = contentWindowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom),
) { topBarPaddings ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.window.core.layout.WindowWidthSizeClass
import me.him188.ani.app.data.source.media.source.RssMediaSource
import me.him188.ani.app.data.source.media.source.RssMediaSourceArguments
import me.him188.ani.app.data.source.media.source.RssSearchConfig
import me.him188.ani.app.ui.foundation.interaction.WindowDragArea
import me.him188.ani.app.ui.foundation.layout.AnimatedPane1
import me.him188.ani.app.ui.foundation.layout.PaddingValuesSides
import me.him188.ani.app.ui.foundation.layout.ThreePaneScaffoldValueConverter.ExtraPaneForNestedDetails
Expand Down Expand Up @@ -137,31 +138,33 @@ fun EditRssMediaSourcePage(
modifier
.fillMaxSize(),
topBar = {
TopAppBar(
title = {
AnimatedContent(
navigator.currentDestination?.pane,
transitionSpec = AniThemeDefaults.standardAnimatedContentTransition,
) {
when (it) {
ListDetailPaneScaffoldRole.List -> Text(state.displayName)
ListDetailPaneScaffoldRole.Detail -> Text("测试数据源")
ListDetailPaneScaffoldRole.Extra -> Text("详情")
else -> Text(state.displayName)
WindowDragArea {
TopAppBar(
title = {
AnimatedContent(
navigator.currentDestination?.pane,
transitionSpec = AniThemeDefaults.standardAnimatedContentTransition,
) {
when (it) {
ListDetailPaneScaffoldRole.List -> Text(state.displayName)
ListDetailPaneScaffoldRole.Detail -> Text("测试数据源")
ListDetailPaneScaffoldRole.Extra -> Text("详情")
else -> Text(state.displayName)
}
}
}
},
navigationIcon = { TopAppBarGoBackButton() },
colors = AniThemeDefaults.topAppBarColors(),
windowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
actions = {
if (navigator.scaffoldValue[ListDetailPaneScaffoldRole.Detail] == PaneAdaptedValue.Hidden) {
TextButton({ navigator.navigateTo(ListDetailPaneScaffoldRole.Detail) }) {
Text("测试")
},
navigationIcon = { TopAppBarGoBackButton() },
colors = AniThemeDefaults.topAppBarColors(),
windowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
actions = {
if (navigator.scaffoldValue[ListDetailPaneScaffoldRole.Detail] == PaneAdaptedValue.Hidden) {
TextButton({ navigator.navigateTo(ListDetailPaneScaffoldRole.Detail) }) {
Text("测试")
}
}
}
},
)
},
)
}
},
contentWindowInsets = windowInsets.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom),
) { paddingValues ->
Expand Down
Loading

0 comments on commit 251880f

Please sign in to comment.