Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
fix: 从通知打开消息页面布局异常
Browse files Browse the repository at this point in the history
  • Loading branch information
HuanCheng65 committed Feb 2, 2024
1 parent 9382e30 commit 625a9b9
Showing 1 changed file with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -45,8 +46,21 @@ fun NotificationsPage(
navigator: DestinationsNavigator,
initialTab: Int = 0,
) {
val pages = listOf<Pair<String, (@Composable () -> 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)) },
Expand All @@ -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()
}
}
}
}
Expand Down

0 comments on commit 625a9b9

Please sign in to comment.