From 625a9b9ff8855ac02b874f471a5401cf6afacaed Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Fri, 2 Feb 2024 17:03:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BB=8E=E9=80=9A=E7=9F=A5=E6=89=93?= =?UTF-8?q?=E5=BC=80=E6=B6=88=E6=81=AF=E9=A1=B5=E9=9D=A2=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/notifications/NotificationsPage.kt | 54 +++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/NotificationsPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/NotificationsPage.kt index 608564d8..a0681668 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/NotificationsPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/NotificationsPage.kt @@ -35,6 +35,7 @@ import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.navigation.DestinationsNavigator import kotlinx.coroutines.launch +@OptIn(ExperimentalFoundationApi::class) @Destination( deepLinks = [ DeepLink(uriPattern = "tblite://notifications/{initialTab}") @@ -45,8 +46,21 @@ fun NotificationsPage( navigator: DestinationsNavigator, initialTab: Int = 0, ) { + val pages = listOf Unit)>>( + stringResource(id = R.string.title_reply_me) to @Composable { + NotificationsListPage(type = NotificationsType.ReplyMe) + }, + stringResource(id = R.string.title_at_me) to @Composable { + NotificationsListPage(type = NotificationsType.AtMe) + } + ) + val pagerState = rememberPagerState( + initialPage = initialTab, + ) { pages.size } + val coroutineScope = rememberCoroutineScope() ProvideNavigator(navigator = navigator) { MyScaffold( + backgroundColor = Color.Transparent, topBar = { TitleCentredToolbar( title = { Text(text = stringResource(id = R.string.title_notifications)) }, @@ -55,11 +69,45 @@ fun NotificationsPage( navigator.navigateUp() } } - ) + ) { + TabRow( + selectedTabIndex = pagerState.currentPage, + indicator = { tabPositions -> + PagerTabIndicator( + pagerState = pagerState, + tabPositions = tabPositions + ) + }, + divider = {}, + backgroundColor = Color.Transparent, + contentColor = ExtendedTheme.colors.onTopBar, + ) { + pages.forEachIndexed { index, pair -> + Tab( + text = { Text(text = pair.first) }, + selected = pagerState.currentPage == index, + onClick = { + coroutineScope.launch { + pagerState.animateScrollToPage(index) + } + }, + ) + } + } + } }, modifier = Modifier.fillMaxSize(), - ) { - NotificationsPage(initialTab = initialTab) + ) { paddingValues -> + LazyLoadHorizontalPager( + state = pagerState, + contentPadding = paddingValues, + key = { pages[it].first }, + modifier = Modifier.fillMaxSize(), + verticalAlignment = Alignment.Top, + userScrollEnabled = true, + ) { + pages[it].second() + } } } }