KotlinLeaner
08/02/2022, 1:44 PMbinding.itemComposable.setContent {
Column(modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(12.dp)) {
val options = getOptions()
options.forEachIndexed { _, optionText ->
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()
val backgroundColor = if (isPressed) DuckEggBlue else OffWhite
val textColor = if (isPressed) TealBlue else Slate
val borderWidth = if (isPressed) 1.dp else 0.dp
val borderColor = if (isPressed) Aqua else OffWhite
Surface(
onClick = {
logE("Item Click")
},
shape = RoundedCornerShape(4.dp),
border = BorderStroke(borderWidth, borderColor),
interactionSource = interactionSource
) {
Text(
modifier = Modifier
.fillMaxWidth()
.background(backgroundColor)
.padding(16.dp),
text = optionText,
style = Typography.h3,
fontWeight = FontWeight.Medium,
color = textColor
)
}
}
}
}
val DuckEggBlue = Color(0xFFF0FCFC)
This is my color which I am using.@Immutable
private object SecondaryRippleTheme : RippleTheme {
@Composable
override fun defaultColor() = RippleTheme.defaultRippleColor(
contentColor = DuckEggBlue,
lightTheme = true
)
@Composable
override fun rippleAlpha() = RippleTheme.defaultRippleAlpha(
contentColor = DuckEggBlue,
lightTheme = true
)
}
In my code
CompositionLocalProvider(LocalRippleTheme provides SecondaryRippleTheme) {
Text(
modifier = Modifier
.fillMaxWidth()
.background(OffWhite)
.padding(16.dp),
text = optionText,
style = Typography.h3,
fontWeight = FontWeight.Medium,
color = textColor
)
}
but nothing works. It still grey ripple effect.oianmol
08/02/2022, 1:49 PM@Composable
override fun defaultColor() = RippleTheme.defaultRippleColor(
contentColor = LocalContentColor.current,
lightTheme = MaterialTheme.colors.isLight
)
@Composable
override fun rippleAlpha() = RippleTheme.defaultRippleAlpha(
contentColor = LocalContentColor.current,
lightTheme = MaterialTheme.colors.isLight
)
It takes in the contentColor!KotlinLeaner
08/02/2022, 1:51 PMSurface(
onClick = {
println("Item Click")
},
shape = RoundedCornerShape(4.dp),
border = BorderStroke(borderWidth, borderColor),
interactionSource = interactionSource
indication = rememberRipple(bounded = false),
)
@oianmol I am doing correct?oianmol
08/02/2022, 1:53 PMKotlinLeaner
08/02/2022, 1:54 PMoianmol
08/02/2022, 1:54 PM@Composable
public fun rememberRipple(
bounded: Boolean = true,
radius: Dp = Dp.Unspecified,
color: Color = Color.Unspecified
)
KotlinLeaner
08/02/2022, 1:55 PMoianmol
08/02/2022, 1:55 PMKotlinLeaner
08/02/2022, 1:56 PMoianmol
08/02/2022, 1:56 PMfun Colors.contentColorFor(backgroundColor: Color): Color {
return when (backgroundColor) {
primary -> onPrimary
primaryVariant -> onPrimary
secondary -> onSecondary
secondaryVariant -> onSecondary
background -> onBackground
surface -> onSurface
error -> onError
else -> Color.Unspecified
}
}
KotlinLeaner
08/02/2022, 1:56 PMoianmol
08/02/2022, 1:58 PMinteractionSource
since Surface makes one for youKotlinLeaner
08/02/2022, 1:59 PMoianmol
08/02/2022, 2:11 PMrememberRipple(bounded = true, color = TealBlue)
KotlinLeaner
08/02/2022, 2:11 PMbounded = true
?oianmol
08/02/2022, 2:19 PMinternal fun Density.getRippleEndRadius(bounded: Boolean, size: Size): Float {
val radiusCoveringBounds =
(Offset(size.width, size.height).getDistance() / 2f)
return if (bounded) {
radiusCoveringBounds + BoundedRippleExtraRadius.toPx()
} else {
radiusCoveringBounds
}
}
KotlinLeaner
08/02/2022, 2:20 PMoianmol
08/02/2022, 2:21 PM