feat: 全局双击顶栏回到顶部

This commit is contained in:
HuanCheng65 2023-09-27 09:01:22 +08:00
parent 6442ad8e40
commit 27486515bd
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
19 changed files with 340 additions and 227 deletions

View File

@ -16,9 +16,9 @@ import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.launch
sealed interface GlobalEvent : UiEvent {
object AccountSwitched : GlobalEvent
data object AccountSwitched : GlobalEvent
object NavigateUp : GlobalEvent
data object ScrollToTop : GlobalEvent
data class Refresh(val key: String) : GlobalEvent

View File

@ -14,7 +14,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
@ -61,6 +60,7 @@ import com.huanchengfly.tieba.post.ui.widgets.compose.FeedCard
import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.LoadMoreLayout
import com.huanchengfly.tieba.post.ui.widgets.compose.LocalSnackbarHostState
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.VerticalDivider
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
@ -152,7 +152,7 @@ private fun ThreadList(
WindowWidthSizeClass.Expanded -> 0.5f
else -> 1f
}
LazyColumn(
MyLazyColumn(
state = state,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxWidth(),

View File

@ -7,6 +7,7 @@ import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Tab
import androidx.compose.material.TabRow
import androidx.compose.material.Text
@ -20,6 +21,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.huanchengfly.tieba.post.R
@ -59,7 +61,12 @@ fun HistoryPage(
scaffoldState = scaffoldState,
topBar = {
TitleCentredToolbar(
title = stringResource(id = R.string.title_history),
title = {
Text(
text = stringResource(id = R.string.title_history),
fontWeight = FontWeight.Bold, style = MaterialTheme.typography.h6
)
},
navigationIcon = {
BackNavigationIcon(onBackPressed = { navigator.navigateUp() })
},
@ -83,8 +90,8 @@ fun HistoryPage(
tint = ExtendedTheme.colors.onTopBar
)
}
}
) {
},
content = {
TabRow(
selectedTabIndex = pagerState.currentPage,
indicator = { tabPositions ->
@ -134,6 +141,7 @@ fun HistoryPage(
)
}
}
)
}
) {
ProvideNavigator(navigator = navigator) {

View File

@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.DropdownMenuItem
@ -41,6 +40,7 @@ import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.LoadMoreLayout
import com.huanchengfly.tieba.post.ui.widgets.compose.LocalSnackbarHostState
import com.huanchengfly.tieba.post.ui.widgets.compose.LongClickMenu
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.Sizes
import com.huanchengfly.tieba.post.ui.widgets.compose.UserHeader
import com.huanchengfly.tieba.post.ui.widgets.compose.rememberMenuState
@ -107,7 +107,7 @@ fun HistoryListPage(
lazyListState = lazyListState,
isEmpty = todayHistoryData.isEmpty() && beforeHistoryData.isEmpty()
) {
LazyColumn(
MyLazyColumn(
modifier = Modifier
.fillMaxSize(),
state = lazyListState

View File

@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ContentAlpha
@ -49,6 +48,7 @@ import com.huanchengfly.tieba.post.ui.common.theme.compose.White
import com.huanchengfly.tieba.post.ui.common.theme.compose.Yellow
import com.huanchengfly.tieba.post.ui.common.theme.compose.pullRefreshIndicator
import com.huanchengfly.tieba.post.ui.widgets.compose.BackNavigationIcon
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.NetworkImage
import com.huanchengfly.tieba.post.ui.widgets.compose.Sizes
import com.huanchengfly.tieba.post.ui.widgets.compose.TitleCentredToolbar
@ -175,7 +175,12 @@ fun HotTopicListPage(
backgroundColor = Color.Transparent,
topBar = {
TitleCentredToolbar(
title = stringResource(id = R.string.title_hot_message_list),
title = {
Text(
text = stringResource(id = R.string.title_hot_message_list),
fontWeight = FontWeight.Bold, style = MaterialTheme.typography.h6
)
},
navigationIcon = {
BackNavigationIcon(onBackPressed = { navigator.navigateUp() })
}
@ -192,7 +197,7 @@ fun HotTopicListPage(
.padding(contentPaddings)
.pullRefresh(pullRefreshState)
) {
LazyColumn(
MyLazyColumn(
verticalArrangement = Arrangement.spacedBy(16.dp),
contentPadding = PaddingValues(16.dp)
) {

View File

@ -4,7 +4,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.ExperimentalMaterialApi
@ -32,6 +31,7 @@ import com.huanchengfly.tieba.post.ui.page.destinations.ThreadPageDestination
import com.huanchengfly.tieba.post.ui.widgets.compose.FeedCard
import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.LoadMoreLayout
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.VerticalDivider
@OptIn(ExperimentalMaterialApi::class)
@ -86,7 +86,7 @@ fun ConcernPage(
WindowWidthSizeClass.Expanded -> 0.5f
else -> 1f
}
LazyColumn(
MyLazyColumn(
state = lazyListState,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxWidth(),

View File

@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ContentAlpha
@ -56,6 +55,7 @@ import com.huanchengfly.tieba.post.ui.page.destinations.HotTopicListPageDestinat
import com.huanchengfly.tieba.post.ui.page.destinations.ThreadPageDestination
import com.huanchengfly.tieba.post.ui.widgets.compose.FeedCard
import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.ProvideContentColor
import com.huanchengfly.tieba.post.ui.widgets.compose.VerticalDivider
import com.huanchengfly.tieba.post.ui.widgets.compose.VerticalGrid
@ -108,7 +108,7 @@ fun HotPage(
refreshing = isLoading,
onRefresh = { viewModel.send(HotUiIntent.Load) })
Box(modifier = Modifier.pullRefresh(pullRefreshState)) {
LazyColumn(
MyLazyColumn(
modifier = Modifier
.fillMaxWidth(),
) {

View File

@ -18,7 +18,6 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
@ -69,6 +68,7 @@ import com.huanchengfly.tieba.post.ui.widgets.compose.BlockableContent
import com.huanchengfly.tieba.post.ui.widgets.compose.FeedCard
import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.LoadMoreLayout
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.VerticalDivider
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
@ -270,7 +270,7 @@ private fun FeedList(
}
}
}
LazyColumn(
MyLazyColumn(
state = state,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxWidth(),

View File

@ -19,7 +19,6 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
@ -84,6 +83,7 @@ import com.huanchengfly.tieba.post.ui.widgets.compose.ConfirmDialog
import com.huanchengfly.tieba.post.ui.widgets.compose.ErrorScreen
import com.huanchengfly.tieba.post.ui.widgets.compose.LongClickMenu
import com.huanchengfly.tieba.post.ui.widgets.compose.MenuState
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyVerticalGrid
import com.huanchengfly.tieba.post.ui.widgets.compose.TextButton
import com.huanchengfly.tieba.post.ui.widgets.compose.TipScreen
import com.huanchengfly.tieba.post.ui.widgets.compose.Toolbar
@ -486,7 +486,7 @@ fun HomePage(
error?.let { ErrorScreen(error = it) }
}
) {
LazyVerticalGrid(
MyLazyVerticalGrid(
columns = gridCells,
contentPadding = PaddingValues(bottom = 12.dp),
modifier = Modifier.fillMaxSize(),
@ -576,8 +576,7 @@ private fun HomePageSkeletonScreen(
listSingle: Boolean,
gridCells: GridCells
) {
val context = LocalContext.current
LazyVerticalGrid(
MyLazyVerticalGrid(
columns = gridCells,
contentPadding = PaddingValues(bottom = 12.dp),
modifier = Modifier

View File

@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
@ -41,6 +40,7 @@ import com.huanchengfly.tieba.post.ui.widgets.compose.BlockableContent
import com.huanchengfly.tieba.post.ui.widgets.compose.EmoticonText
import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.LoadMoreLayout
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.Sizes
import com.huanchengfly.tieba.post.ui.widgets.compose.UserHeader
import com.huanchengfly.tieba.post.utils.DateTimeUtils
@ -96,7 +96,7 @@ fun NotificationsListPage(
loadEnd = !hasMore,
lazyListState = lazyListState,
) {
LazyColumn(
MyLazyColumn(
contentPadding = PaddingValues(vertical = 4.dp),
state = lazyListState,
) {

View File

@ -10,7 +10,6 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
@ -42,6 +41,7 @@ import com.huanchengfly.tieba.post.ui.widgets.compose.Avatar
import com.huanchengfly.tieba.post.ui.widgets.compose.ErrorScreen
import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.LocalShouldLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.Sizes
import com.huanchengfly.tieba.post.ui.widgets.compose.states.StateScreen
import kotlinx.collections.immutable.persistentListOf
@ -125,7 +125,7 @@ fun SearchForumPage(
.fillMaxSize()
.pullRefresh(pullRefreshState)
) {
LazyColumn(modifier = Modifier.fillMaxSize()) {
MyLazyColumn(modifier = Modifier.fillMaxSize()) {
if (showExactMatchResult) {
stickyHeader(key = "ExactMatchHeader") {
Column(

View File

@ -4,7 +4,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
@ -40,6 +39,7 @@ import com.huanchengfly.tieba.post.ui.widgets.compose.ForumInfoChip
import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.LoadMoreLayout
import com.huanchengfly.tieba.post.ui.widgets.compose.LocalShouldLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.Sizes
import com.huanchengfly.tieba.post.ui.widgets.compose.ThreadAgreeBtn
import com.huanchengfly.tieba.post.ui.widgets.compose.ThreadContent
@ -196,7 +196,7 @@ private fun SearchThreadList(
onItemForumClick: (SearchThreadBean.ForumInfo) -> Unit,
modifier: Modifier = Modifier,
) {
LazyColumn(
MyLazyColumn(
state = lazyListState,
modifier = modifier
) {

View File

@ -10,7 +10,6 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
@ -42,6 +41,7 @@ import com.huanchengfly.tieba.post.ui.widgets.compose.Avatar
import com.huanchengfly.tieba.post.ui.widgets.compose.ErrorScreen
import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.LocalShouldLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.Sizes
import com.huanchengfly.tieba.post.ui.widgets.compose.states.StateScreen
import com.huanchengfly.tieba.post.utils.StringUtil
@ -126,7 +126,7 @@ fun SearchUserPage(
.fillMaxSize()
.pullRefresh(pullRefreshState)
) {
LazyColumn(modifier = Modifier.fillMaxSize()) {
MyLazyColumn(modifier = Modifier.fillMaxSize()) {
if (showExactMatchResult) {
stickyHeader(key = "ExactMatchHeader") {
Column(

View File

@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
@ -55,6 +54,7 @@ import com.huanchengfly.tieba.post.ui.page.main.BottomNavigationDivider
import com.huanchengfly.tieba.post.ui.widgets.compose.BackNavigationIcon
import com.huanchengfly.tieba.post.ui.widgets.compose.LocalSnackbarHostState
import com.huanchengfly.tieba.post.ui.widgets.compose.LongClickMenu
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.MyScaffold
import com.huanchengfly.tieba.post.ui.widgets.compose.PagerTabIndicator
import com.huanchengfly.tieba.post.ui.widgets.compose.PromptDialog
@ -116,11 +116,16 @@ fun BlockListPage(
backgroundColor = Color.Transparent,
topBar = {
TitleCentredToolbar(
title = stringResource(id = R.string.title_block_list),
title = {
Text(
text = stringResource(id = R.string.title_block_list),
fontWeight = FontWeight.Bold, style = MaterialTheme.typography.h6
)
},
navigationIcon = {
BackNavigationIcon(onBackPressed = { navigator.navigateUp() })
}
) {
},
content = {
TabRow(
selectedTabIndex = pagerState.currentPage,
indicator = { tabPositions ->
@ -148,6 +153,7 @@ fun BlockListPage(
)
}
}
)
},
bottomBar = {
Column {
@ -232,7 +238,7 @@ fun BlockListPage(
isError = false,
isLoading = isLoading,
loadingScreen = {
LazyColumn(modifier = Modifier.fillMaxSize()) {
MyLazyColumn(modifier = Modifier.fillMaxSize()) {
items(4) {
BlockItemPlaceholder()
}
@ -240,7 +246,7 @@ fun BlockListPage(
},
modifier = Modifier.fillMaxSize()
) {
LazyColumn(Modifier.fillMaxSize()) {
MyLazyColumn(Modifier.fillMaxSize()) {
items(items, key = { it.id }) {
LongClickMenu(menuContent = {
DropdownMenuItem(onClick = {

View File

@ -10,7 +10,6 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
@ -34,6 +33,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastForEach
import com.huanchengfly.tieba.post.App
@ -62,6 +62,7 @@ import com.huanchengfly.tieba.post.ui.widgets.compose.ConfirmDialog
import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.LoadMoreLayout
import com.huanchengfly.tieba.post.ui.widgets.compose.LongClickMenu
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.MyScaffold
import com.huanchengfly.tieba.post.ui.widgets.compose.Sizes
import com.huanchengfly.tieba.post.ui.widgets.compose.TitleCentredToolbar
@ -260,11 +261,14 @@ internal fun SubPostsContent(
modifier = Modifier.fillMaxSize(),
topBar = {
TitleCentredToolbar(
title = post?.let {
title = {
Text(text = post?.let {
stringResource(
id = R.string.title_sub_posts,
it.get { floor })
} ?: stringResource(id = R.string.title_sub_posts_default),
fontWeight = FontWeight.Bold, style = MaterialTheme.typography.h6)
},
navigationIcon = {
IconButton(onClick = { navigator.navigateUp() }) {
Icon(
@ -364,7 +368,7 @@ internal fun SubPostsContent(
lazyListState = lazyListState,
isEmpty = post == null && subPosts.isEmpty(),
) {
LazyColumn(
MyLazyColumn(
modifier = Modifier.padding(paddingValues),
state = lazyListState
) {

View File

@ -23,7 +23,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
@ -141,6 +140,7 @@ import com.huanchengfly.tieba.post.ui.widgets.compose.ListMenuItem
import com.huanchengfly.tieba.post.ui.widgets.compose.LoadMoreLayout
import com.huanchengfly.tieba.post.ui.widgets.compose.LongClickMenu
import com.huanchengfly.tieba.post.ui.widgets.compose.MyBackHandler
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.MyScaffold
import com.huanchengfly.tieba.post.ui.widgets.compose.PromptDialog
import com.huanchengfly.tieba.post.ui.widgets.compose.Sizes
@ -1139,7 +1139,7 @@ fun ThreadPage(
lazyListState = lazyListState,
isEmpty = data.isEmpty()
) {
LazyColumn(
MyLazyColumn(
state = lazyListState,
modifier = Modifier.fillMaxWidth()
) {

View File

@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
@ -15,6 +14,7 @@ import androidx.compose.foundation.text.appendInlineContent
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.LocalContentColor
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
@ -58,6 +58,7 @@ import com.huanchengfly.tieba.post.ui.widgets.compose.ErrorScreen
import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.LoadMoreLayout
import com.huanchengfly.tieba.post.ui.widgets.compose.LongClickMenu
import com.huanchengfly.tieba.post.ui.widgets.compose.MyLazyColumn
import com.huanchengfly.tieba.post.ui.widgets.compose.MyScaffold
import com.huanchengfly.tieba.post.ui.widgets.compose.Sizes
import com.huanchengfly.tieba.post.ui.widgets.compose.TitleCentredToolbar
@ -131,7 +132,12 @@ fun ThreadStorePage(
scaffoldState = scaffoldState,
topBar = {
TitleCentredToolbar(
title = stringResource(id = R.string.title_my_collect),
title = {
Text(
text = stringResource(id = R.string.title_my_collect),
fontWeight = FontWeight.Bold, style = MaterialTheme.typography.h6
)
},
navigationIcon = {
BackNavigationIcon(onBackPressed = { navigator.navigateUp() })
}
@ -167,7 +173,7 @@ fun ThreadStorePage(
loadEnd = !hasMore,
lazyListState = lazyListState
) {
LazyColumn(state = lazyListState) {
MyLazyColumn(state = lazyListState) {
items(
items = data,
key = { it.threadId }

View File

@ -0,0 +1,83 @@
package com.huanchengfly.tieba.post.ui.widgets.compose
import androidx.compose.foundation.gestures.FlingBehavior
import androidx.compose.foundation.gestures.ScrollableDefaults
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.huanchengfly.tieba.post.arch.GlobalEvent
import com.huanchengfly.tieba.post.arch.onGlobalEvent
@Composable
fun MyLazyColumn(
modifier: Modifier = Modifier,
state: LazyListState = rememberLazyListState(),
contentPadding: PaddingValues = PaddingValues(0.dp),
reverseLayout: Boolean = false,
verticalArrangement: Arrangement.Vertical =
if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
userScrollEnabled: Boolean = true,
content: LazyListScope.() -> Unit,
) {
onGlobalEvent<GlobalEvent.ScrollToTop> {
state.animateScrollToItem(0)
}
LazyColumn(
modifier = modifier,
state = state,
contentPadding = contentPadding,
reverseLayout = reverseLayout,
verticalArrangement = verticalArrangement,
horizontalAlignment = horizontalAlignment,
flingBehavior = flingBehavior,
userScrollEnabled = userScrollEnabled,
content = content
)
}
@Composable
fun MyLazyVerticalGrid(
columns: GridCells,
modifier: Modifier = Modifier,
state: LazyGridState = rememberLazyGridState(),
contentPadding: PaddingValues = PaddingValues(0.dp),
reverseLayout: Boolean = false,
verticalArrangement: Arrangement.Vertical =
if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
userScrollEnabled: Boolean = true,
content: LazyGridScope.() -> Unit,
) {
onGlobalEvent<GlobalEvent.ScrollToTop> {
state.animateScrollToItem(0)
}
LazyVerticalGrid(
columns = columns,
modifier = modifier,
state = state,
contentPadding = contentPadding,
reverseLayout = reverseLayout,
verticalArrangement = verticalArrangement,
horizontalArrangement = horizontalArrangement,
flingBehavior = flingBehavior,
userScrollEnabled = userScrollEnabled,
content = content
)
}

View File

@ -1,7 +1,11 @@
package com.huanchengfly.tieba.post.ui.widgets.compose
import android.util.Log
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@ -23,13 +27,14 @@ import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ProvideTextStyle
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Add
import androidx.compose.material.icons.rounded.CheckCircle
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
@ -41,10 +46,13 @@ import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import com.huanchengfly.tieba.post.R
import com.huanchengfly.tieba.post.activities.LoginActivity
import com.huanchengfly.tieba.post.arch.BaseComposeActivity.Companion.LocalWindowSizeClass
import com.huanchengfly.tieba.post.arch.GlobalEvent
import com.huanchengfly.tieba.post.arch.emitGlobalEvent
import com.huanchengfly.tieba.post.goToActivity
import com.huanchengfly.tieba.post.ui.common.theme.compose.ExtendedTheme
import com.huanchengfly.tieba.post.ui.common.windowsizeclass.WindowWidthSizeClass.Companion.Compact
@ -68,7 +76,12 @@ fun AccountNavIcon(
if (spacer) Spacer(modifier = Modifier.width(12.dp))
if (currentAccount == null) {
Image(
painter = rememberDrawablePainter(drawable = LocalContext.current.getDrawable(R.drawable.ic_launcher_new_round)),
painter = rememberDrawablePainter(
drawable = ContextCompat.getDrawable(
LocalContext.current,
R.drawable.ic_launcher_new_round
)
),
contentDescription = null,
modifier = Modifier
.clip(CircleShape)
@ -169,83 +182,53 @@ fun BackNavigationIcon(onBackPressed: () -> Unit) {
}
}
@Deprecated(
"Use the non deprecated overload",
ReplaceWith(
"""TitleCentredToolbar(
title = { Text(text = title, fontWeight = FontWeight.Bold, style = MaterialTheme.typography.h6) },
modifier = modifier,
insets = insets,
navigationIcon = navigationIcon,
actions = actions,
content = content
)""",
"androidx.compose.ui.text.font.FontWeight",
"androidx.compose.material.MaterialTheme",
)
)
@Composable
fun TitleCentredToolbar(
title: String,
modifier: Modifier = Modifier,
insets: Boolean = true,
navigationIcon: @Composable (() -> Unit)? = null,
navigationIcon: (@Composable () -> Unit)? = null,
actions: @Composable RowScope.() -> Unit = {},
content: @Composable ColumnScope.() -> Unit = {}
content: (@Composable ColumnScope.() -> Unit)? = null,
) {
val statusBarModifier = if (insets) {
Modifier.windowInsetsTopHeight(WindowInsets.statusBars)
} else {
Modifier
}
Column {
Spacer(
modifier = statusBarModifier
.fillMaxWidth()
.background(color = ExtendedTheme.colors.topBar.calcStatusBarColor())
TitleCentredToolbar(
title = {
Text(text = title, fontWeight = FontWeight.Bold, style = MaterialTheme.typography.h6)
},
modifier = modifier,
insets = insets,
navigationIcon = navigationIcon,
actions = actions,
content = content
)
TopAppBar(
backgroundColor = ExtendedTheme.colors.topBar,
contentColor = ExtendedTheme.colors.onTopBar,
elevation = 0.dp
) {
Box(modifier = Modifier.fillMaxSize()) {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxHeight()
) {
ProvideContentColor(color = ExtendedTheme.colors.onTopBar) {
navigationIcon?.invoke()
Spacer(modifier = Modifier.weight(1f))
actions()
}
}
Row(
Modifier
.fillMaxHeight()
.align(Alignment.Center),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
ProvideTextStyle(value = MaterialTheme.typography.h6) {
ProvideContentColor(color = ExtendedTheme.colors.onTopBar) {
Text(text = title, fontWeight = FontWeight.Bold)
}
}
}
}
}
Column(
modifier = Modifier
.fillMaxWidth()
.background(color = ExtendedTheme.colors.topBar)
) {
content()
}
}
}
@Composable
fun TitleCentredToolbar(
title: @Composable () -> Unit,
modifier: Modifier = Modifier,
navigationIcon: @Composable (() -> Unit)? = null,
actions: @Composable (RowScope.() -> Unit) = {},
content: @Composable (ColumnScope.() -> Unit) = {},
insets: Boolean = true,
navigationIcon: (@Composable () -> Unit)? = null,
actions: @Composable RowScope.() -> Unit = {},
content: (@Composable ColumnScope.() -> Unit)? = null,
) {
Column(
modifier = Modifier
.background(ExtendedTheme.colors.topBar)
.then(modifier)
) {
TopAppBarContainer(
topBar = {
TopAppBar(
backgroundColor = ExtendedTheme.colors.topBar,
contentColor = ExtendedTheme.colors.onTopBar,
@ -271,26 +254,25 @@ fun TitleCentredToolbar(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
ProvideContentColor(color = ExtendedTheme.colors.onTopBar) {
title()
}
}
}
Column(
modifier = Modifier
.fillMaxWidth()
.background(color = ExtendedTheme.colors.topBar)
) {
content()
}
}
},
modifier = modifier,
insets = insets,
content = content
)
}
@Composable
fun Toolbar(
title: String,
navigationIcon: @Composable (() -> Unit)? = null,
navigationIcon: (@Composable () -> Unit)? = null,
actions: @Composable RowScope.() -> Unit = {},
content: @Composable (ColumnScope.() -> Unit)? = null
content: (@Composable ColumnScope.() -> Unit)? = null,
) {
TopAppBarContainer(
topBar = {
@ -314,9 +296,9 @@ fun Toolbar(
@Composable
fun Toolbar(
title: @Composable (() -> Unit),
navigationIcon: @Composable (() -> Unit)? = null,
navigationIcon: (@Composable () -> Unit)? = null,
actions: @Composable RowScope.() -> Unit = {},
content: @Composable (ColumnScope.() -> Unit)? = null
content: (@Composable ColumnScope.() -> Unit)? = null,
) {
TopAppBarContainer(
topBar = {
@ -336,21 +318,41 @@ fun Toolbar(
}
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun TopAppBarContainer(
topBar: @Composable ColumnScope.() -> Unit,
modifier: Modifier = Modifier,
content: @Composable (ColumnScope.() -> Unit)? = null,
insets: Boolean = true,
content: (@Composable ColumnScope.() -> Unit)? = null,
) {
val statusBarModifier = if (insets) {
Modifier.windowInsetsTopHeight(WindowInsets.statusBars)
} else {
Modifier
}
val coroutineScope = rememberCoroutineScope()
Column(modifier) {
Spacer(
modifier = Modifier
.windowInsetsTopHeight(WindowInsets.statusBars)
modifier = statusBarModifier
.fillMaxWidth()
.background(color = ExtendedTheme.colors.topBar.calcStatusBarColor())
)
topBar()
if (content != null) {
Column(
modifier = Modifier
.fillMaxWidth()
.combinedClickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
onDoubleClick = {
Log.i("TopAppBarContainer", "TopAppBarContainer: onDoubleClick")
coroutineScope.emitGlobalEvent(GlobalEvent.ScrollToTop)
},
onClick = {},
),
content = topBar
)
content?.let {
Column(
modifier = Modifier
.fillMaxWidth()