Geert
09/18/2020, 8:47 AM@Composable
fun ModifiedShape(){
// TODO: Replace by remember?
val (shape, setShape) = state<Shape> { CircleShape }
// TODO: Fix error
// Destructuring declaration initializer of type Shape must have a 'component1()' function
// Destructuring declaration initializer of type Shape must have a 'component2()' function
// val (shape, setShape) = remember<Shape> { CircleShape }
Image(
asset = imageResource(id = R.drawable.ic_launcher_background),
modifier = Modifier
.size(256.dp)
.padding(16.dp)
.drawShadow(8.dp, shape)
.border(6.dp, MaterialTheme.colors.primary, shape)
.border(12.dp, MaterialTheme.colors.secondary, shape)
.border(18.dp, MaterialTheme.colors.background, shape)
// TODO: Add ripple?
//.ripple(color = MaterialTheme.colors.surface)
.clickable {
setShape(
if (shape == CircleShape) {
CutCornerShape(topLeft = 32.dp, bottomRight = 32.dp)
} else {
CircleShape
}
)
}
)
}Yann Badoual
09/18/2020, 8:50 AM= state with = = remember { mutableStateOf(CircleShape) }Yann Badoual
09/18/2020, 8:51 AMclickable modifier should apply a ripple by default I believe.
It can be changed with the interaction parameter of clickable modifier.
As for the color, I'm not sure what color it's using by default.
But you can create your own instance of RippleIndication and pass the color you want if needed.
You can check the default value in DefaultRippleTheme. By default it seems to be either white or contentColor() depending on current theme (light or dark) and contentColor's lumianceGeert
09/18/2020, 9:07 AMGeert
09/18/2020, 9:07 AMBrett Best
09/18/2020, 9:07 AMBrett Best
09/18/2020, 9:09 AMBrett Best
09/18/2020, 9:09 AMmutableStateOf(CircleShape())Geert
09/18/2020, 9:11 AMBrett Best
09/18/2020, 9:11 AMGeert
09/18/2020, 9:13 AMGeert
09/18/2020, 9:14 AMval (shape, setShape) = remember { mutableStateOf(CircleShape) }
But the CutCornerShape and CircleShape are both inheriting the Shape interface.Geert
09/18/2020, 9:15 AMGeert
09/18/2020, 9:16 AMYann Badoual
09/18/2020, 9:20 AMval (shape, setShape) = remember { mutableStateOf<Shape>(CutCornerShape()) }Yann Badoual
09/18/2020, 9:20 AMmutableStateOf , and the argument should be the default valueYann Badoual
09/18/2020, 9:21 AMGeert
09/18/2020, 9:25 AMGeert
09/18/2020, 9:25 AMGeert
09/18/2020, 9:26 AMval CircleShape = RoundedCornerShape(50)Yann Badoual
09/18/2020, 9:33 AMvar shape by remember { mutableStateOf(CirlceShape) }
and instead of calling setShape , you can use shape as a mutable variable.
If you do, just make sure to add the following import
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
Or you'll get an error (known intellij bug)