11package dev.dimension.flare.ui.screen.home
22
3- import androidx.compose.animation.AnimatedVisibility
4- import androidx.compose.foundation.background
5- import androidx.compose.foundation.clickable
6- import androidx.compose.foundation.horizontalScroll
73import androidx.compose.foundation.layout.Arrangement
84import androidx.compose.foundation.layout.Box
95import androidx.compose.foundation.layout.Row
106import androidx.compose.foundation.layout.fillMaxWidth
117import androidx.compose.foundation.layout.padding
128import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpan
139import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
14- import androidx.compose.foundation.rememberScrollState
15- import androidx.compose.foundation.shape.RoundedCornerShape
10+ import androidx.compose.foundation.shape.CircleShape
1611import androidx.compose.material3.Badge
17- import androidx.compose.material3.ButtonGroup
1812import androidx.compose.material3.ExperimentalMaterial3Api
1913import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
20- import androidx.compose.material3.LocalTextStyle
14+ import androidx.compose.material3.FilterChip
15+ import androidx.compose.material3.LeadingIconTab
16+ import androidx.compose.material3.LocalContentColor
2117import androidx.compose.material3.MaterialTheme
18+ import androidx.compose.material3.SecondaryScrollableTabRow
2219import androidx.compose.material3.Text
2320import androidx.compose.material3.TopAppBarDefaults
2421import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
2522import androidx.compose.runtime.Composable
26- import androidx.compose.runtime.CompositionLocalProvider
2723import androidx.compose.runtime.getValue
2824import androidx.compose.runtime.remember
2925import androidx.compose.runtime.rememberCoroutineScope
3026import androidx.compose.ui.Alignment
3127import androidx.compose.ui.Modifier
3228import androidx.compose.ui.draw.clip
29+ import androidx.compose.ui.graphics.Color
3330import androidx.compose.ui.input.nestedscroll.nestedScroll
3431import androidx.compose.ui.res.stringResource
3532import androidx.compose.ui.unit.dp
@@ -43,6 +40,7 @@ import dev.dimension.flare.ui.component.AvatarComponent
4340import dev.dimension.flare.ui.component.FlareScaffold
4441import dev.dimension.flare.ui.component.FlareTopAppBar
4542import dev.dimension.flare.ui.component.RefreshContainer
43+ import dev.dimension.flare.ui.component.TabRowIndicator
4644import dev.dimension.flare.ui.component.status.LazyStatusVerticalStaggeredGrid
4745import dev.dimension.flare.ui.component.status.status
4846import dev.dimension.flare.ui.model.onSuccess
@@ -80,108 +78,58 @@ internal fun NotificationScreen() {
8078 FlareTopAppBar (
8179 title = {
8280 if (state.notifications.size > 1 ) {
83- Row (
81+ SecondaryScrollableTabRow (
82+ containerColor = Color .Transparent ,
8483 modifier =
8584 Modifier
86- .fillMaxWidth()
87- .horizontalScroll(rememberScrollState()),
88- verticalAlignment = Alignment .CenterVertically ,
89- horizontalArrangement = Arrangement .spacedBy(8 .dp),
85+ .fillMaxWidth(),
86+ selectedTabIndex = state.selectedAccountIndex,
87+ edgePadding = 0 .dp,
88+ divider = {},
89+ indicator = {
90+ TabRowIndicator (
91+ selectedIndex = state.selectedAccountIndex,
92+ )
93+ },
94+ minTabWidth = 48 .dp,
9095 ) {
9196 state.notifications.forEach { (account, badge) ->
92- Row (
93- verticalAlignment = Alignment .CenterVertically ,
94- modifier =
95- Modifier
96- .clip(RoundedCornerShape (100 ))
97- .background(
98- if (state.selectedAccount?.key == account.key) {
99- MaterialTheme .colorScheme.primaryContainer
100- } else {
101- MaterialTheme .colorScheme.surfaceVariant
102- },
103- ).clickable {
104- state.setAccount(account)
105- }.padding(8 .dp),
106- ) {
107- AvatarComponent (
108- account.avatar,
109- size = 24 .dp,
110- )
111- CompositionLocalProvider (
112- LocalTextStyle provides MaterialTheme .typography.titleMedium,
113- ) {
114- AnimatedVisibility (state.selectedAccount?.key == account.key) {
115- Text (
116- text = account.handle,
117- modifier = Modifier .padding(horizontal = 4 .dp),
118- maxLines = 1 ,
97+ LeadingIconTab (
98+ modifier = Modifier .clip(CircleShape ),
99+ selectedContentColor = MaterialTheme .colorScheme.onSecondaryContainer,
100+ unselectedContentColor = LocalContentColor .current,
101+ selected = state.selectedAccount?.key == account.key,
102+ onClick = {
103+ state.setAccount(account)
104+ },
105+ text = {
106+ Text (
107+ text = account.handle,
108+ maxLines = 1 ,
109+ )
110+ },
111+ icon = {
112+ Box (
113+ contentAlignment = Alignment .BottomEnd ,
114+ ) {
115+ AvatarComponent (
116+ account.avatar,
117+ size = 24 .dp,
119118 )
120- }
121- AnimatedVisibility (badge > 0 ) {
122- Badge {
123- Text (
124- text = badge.toString() ,
125- modifier = Modifier .padding( 4 .dp) ,
126- maxLines = 1 ,
127- )
119+ if (badge > 0 ) {
120+ Badge {
121+ Text (
122+ text = badge.toString(),
123+ maxLines = 1 ,
124+ style = MaterialTheme .typography.labelSmall ,
125+ )
126+ }
128127 }
129128 }
130- }
131- }
129+ },
130+ )
132131 }
133132 }
134- // SecondaryScrollableTabRow(
135- // containerColor = Color.Transparent,
136- // modifier =
137- // Modifier
138- // .fillMaxWidth(),
139- // edgePadding = 0.dp,
140- // divider = {},
141- // indicator = {
142- // TabRowIndicator(
143- // selectedIndex =
144- // state.notifications.keys
145- // .indexOf(state.selectedAccount)
146- // .coerceIn(0, state.notifications.size - 1),
147- // )
148- // },
149- // minTabWidth = 48.dp,
150- // selectedTabIndex =
151- // state.notifications.keys
152- // .indexOf(state.selectedAccount)
153- // .coerceIn(0, state.notifications.size - 1),
154- // ) {
155- // state.notifications.forEach { (account, badge) ->
156- // LeadingIconTab(
157- // selectedContentColor = MaterialTheme.colorScheme.onSecondaryContainer,
158- // unselectedContentColor = LocalContentColor.current,
159- // selected = state.selectedAccount == account,
160- // onClick = {
161- // state.setAccount(account)
162- // },
163- // text = {
164- // if (state.selectedAccount == account) {
165- // Text(text = account.handle)
166- // }
167- // if (badge > 0) {
168- // if (state.selectedAccount == account) {
169- // Spacer(modifier = Modifier.width(4.dp))
170- // }
171- // Badge {
172- // Text(text = badge.toString())
173- // }
174- // }
175- // },
176- // icon = {
177- // AvatarComponent(
178- // data = account.avatar,
179- // size = AvatarComponentDefaults.compatSize,
180- // )
181- // },
182- // )
183- // }
184- // }
185133 } else {
186134 Text (text = stringResource(id = R .string.home_tab_notifications_title))
187135 }
@@ -258,18 +206,19 @@ private fun NotificationFilterSelector(
258206 onFilterChanged : (NotificationFilter ) -> Unit ,
259207 modifier : Modifier = Modifier ,
260208) {
261- val titles = filters.map { stringResource(id = it.title) }
262- ButtonGroup (
209+ Row (
263210 modifier = modifier,
264- overflowIndicator = {} ,
211+ horizontalArrangement = Arrangement .spacedBy( 8 .dp) ,
265212 ) {
266- filters.forEachIndexed { index, notificationType ->
267- toggleableItem(
268- checked = selectedFilter == notificationType,
269- onCheckedChange = {
270- onFilterChanged(notificationType)
213+ filters.forEach { filter ->
214+ FilterChip (
215+ selected = filter == selectedFilter,
216+ onClick = {
217+ onFilterChanged(filter)
218+ },
219+ label = {
220+ Text (stringResource(id = filter.title))
271221 },
272- label = titles[index],
273222 )
274223 }
275224 }
0 commit comments