1414 * limitations under the License.
1515 */
1616
17- @file:OptIn(ExperimentalSharedTransitionApi ::class )
17+ @file:OptIn(ExperimentalSharedTransitionApi ::class , ExperimentalFoundationStyleApi :: class )
1818
1919package com.example.jetsnack.ui.components
2020
2121import android.content.res.Configuration
2222import androidx.compose.animation.AnimatedVisibility
2323import androidx.compose.animation.ExperimentalSharedTransitionApi
2424import androidx.compose.animation.SharedTransitionScope
25- import androidx.compose.animation.animateColorAsState
26- import androidx.compose.foundation.background
2725import androidx.compose.foundation.interaction.MutableInteractionSource
28- import androidx.compose.foundation.interaction.collectIsPressedAsState
2926import androidx.compose.foundation.layout.Arrangement
3027import androidx.compose.foundation.layout.Box
3128import androidx.compose.foundation.layout.PaddingValues
@@ -35,17 +32,24 @@ import androidx.compose.foundation.lazy.LazyRow
3532import androidx.compose.foundation.lazy.items
3633import androidx.compose.foundation.selection.toggleable
3734import androidx.compose.foundation.shape.CircleShape
35+ import androidx.compose.foundation.style.ExperimentalFoundationStyleApi
36+ import androidx.compose.foundation.style.Style
37+ import androidx.compose.foundation.style.pressed
38+ import androidx.compose.foundation.style.rememberUpdatedStyleState
39+ import androidx.compose.foundation.style.styleable
40+ import androidx.compose.foundation.style.then
3841import androidx.compose.material3.Icon
3942import androidx.compose.material3.IconButton
43+ import androidx.compose.material3.LocalShapes
4044import androidx.compose.material3.MaterialTheme
4145import androidx.compose.material3.Text
4246import androidx.compose.runtime.Composable
43- import androidx.compose.runtime.getValue
4447import androidx.compose.runtime.remember
4548import androidx.compose.ui.Alignment
4649import androidx.compose.ui.Modifier
50+ import androidx.compose.ui.graphics.Brush
4751import androidx.compose.ui.graphics.Color
48- import androidx.compose.ui.graphics.Shape
52+ import androidx.compose.ui.graphics.TileMode
4953import androidx.compose.ui.res.painterResource
5054import androidx.compose.ui.res.stringResource
5155import androidx.compose.ui.tooling.preview.Preview
@@ -54,6 +58,7 @@ import com.example.jetsnack.R
5458import com.example.jetsnack.model.Filter
5559import com.example.jetsnack.ui.FilterSharedElementKey
5660import com.example.jetsnack.ui.theme.JetsnackTheme
61+ import com.example.jetsnack.ui.theme.LocalJetsnackColors
5762
5863@Composable
5964fun FilterBar (
@@ -93,59 +98,62 @@ fun FilterBar(
9398 }
9499 }
95100 items(filters) { filter ->
96- FilterChip (filter = filter, shape = MaterialTheme .shapes.small)
101+ FilterChip (
102+ filter = filter,
103+ style = Style {
104+ shape(LocalShapes .currentValue.small)
105+ },
106+ )
97107 }
98108 }
99109 }
100110}
101111
102112@Composable
103- fun FilterChip (filter : Filter , modifier : Modifier = Modifier , shape : Shape = MaterialTheme .shapes.small) {
113+ fun FilterChip (
114+ filter : Filter ,
115+ modifier : Modifier = Modifier ,
116+ style : Style = Style ,
117+ ) {
118+
104119 val (selected, setSelected) = filter.enabled
105- val backgroundColor by animateColorAsState(
106- if (selected) JetsnackTheme .colors.brandSecondary else JetsnackTheme .colors.uiBackground,
107- label = " background color" ,
108- )
109- val border = Modifier .fadeInDiagonalGradientBorder(
110- showBorder = ! selected,
111- colors = JetsnackTheme .colors.interactiveSecondary,
112- shape = shape,
113- )
114- val textColor by animateColorAsState(
115- if (selected) Color .Black else JetsnackTheme .colors.textSecondary,
116- label = " text color" ,
120+ val interactionSource = remember { MutableInteractionSource () }
121+ val styleState = rememberUpdatedStyleState(
122+ interactionSource,
123+ {
124+ it.isSelected = selected
125+ },
117126 )
118127
119128 JetsnackSurface (
120- modifier = modifier,
121- color = backgroundColor,
122- contentColor = textColor,
123- shape = shape,
124- elevation = 2 .dp,
129+ modifier = modifier
130+ .toggleable(
131+ value = selected,
132+ onValueChange = setSelected,
133+ interactionSource = interactionSource,
134+ indication = null ,
135+ ),
136+ style = JetsnackTheme .appStyles.filterChipStyle then style,
137+ styleState = styleState,
125138 ) {
126- val interactionSource = remember { MutableInteractionSource () }
127-
128- val pressed by interactionSource.collectIsPressedAsState()
129- val backgroundPressed =
130- if (pressed) {
131- Modifier .offsetGradientBackground(
132- JetsnackTheme .colors.interactiveSecondary,
133- 200f ,
134- 0f ,
135- )
136- } else {
137- Modifier .background(Color .Transparent )
139+ val innerBackgroundStyle = Style {
140+ background(Color .Transparent )
141+ pressed {
142+ animate {
143+ background(
144+ Brush .horizontalGradient(
145+ colors = LocalJetsnackColors .currentValue.interactiveSecondary,
146+ startX = 0f ,
147+ endX = 200f ,
148+ tileMode = TileMode .Mirror ,
149+ ),
150+ )
151+ }
138152 }
153+ }
139154 Box (
140155 modifier = Modifier
141- .toggleable(
142- value = selected,
143- onValueChange = setSelected,
144- interactionSource = interactionSource,
145- indication = null ,
146- )
147- .then(backgroundPressed)
148- .then(border),
156+ .styleable(styleState, innerBackgroundStyle),
149157 ) {
150158 Text (
151159 text = filter.name,
0 commit comments