prat
03/26/2020, 3:03 AMZach Klippenstein (he/him) [MOD]
03/26/2020, 4:02 AMshikasd
03/26/2020, 10:25 AMprat
03/26/2020, 1:35 PMshikasd
03/26/2020, 1:51 PMcaelum19
03/26/2020, 2:32 PMprat
03/26/2020, 3:03 PMLeland Richardson [G]
03/26/2020, 3:48 PMBox
here was required? It seems like it wouldn’t be since Canvas is basically just a child-less box with a draw callprat
03/26/2020, 4:02 PMBox
is a workaround to increase there tap target size. not sure if there is a proper way to do this?Leland Richardson [G]
03/26/2020, 4:07 PMTouchSlop
notion, but i’m not familiar with it. though if you’re just using a Box
right now i think just adding a LayoutPadding
modifier to the canvas would be sufficientprat
03/26/2020, 4:11 PMLayoutPadding
. will try thatLeland Richardson [G]
03/26/2020, 4:56 PM@Composable
fun ExpandCollapseButton(
up: Boolean,
onStateChange: (Boolean) -> Unit,
modifier: Modifier = Modifier.None,
animationDuration: Int = 200,
color: Color = MaterialTheme.colors().secondary
) {
Box(modifier) {
Ripple(bounded = false) {
Caret(
LayoutPadding(14.dp) +
ContentGravity.Center +
LayoutSize(20.dp) +
OnClick {
onStateChange(!up)
}
up,
color,
animationDuration
)
}
}
}
@Composable
private fun Caret(
modifier: Modifier,
up: Boolean,
activeColor: Color,
animationDuration: Int
) {
val strokeWidthDp = 3.dp
val paint = remember {
Paint().apply {
isAntiAlias = true
strokeCap = StrokeCap.round
color = activeColor
style = PaintingStyle.stroke
}
}
// simpler animation api for simple transitions
// return value will be animated between 1f and 0f. It's just a Float.
val t = animate(if (up) 1f else 0f, animationDuration)
val animatedYOffset = lerp(0f, 1f, t) // equivalent to just `t`, but you get the idea
val fraction = lerp(-1f, 1f, t)
Canvas(modifier) {
val strokeWidth = strokeWidthDp.toPx().value
paint.strokeWidth = strokeWidth
val height = size.height.value / 4
val x = size.height.value / 4
val yOffset = (size.height.value - height) / 2
val path = Path()
path.moveTo(x, yOffset + height * animatedYOffset)
path.relativeLineTo(x, -height * fraction)
path.relativeLineTo(x, height * fraction)
drawPath(path, paint)
}
}
Zach Klippenstein (he/him) [MOD]
03/26/2020, 5:18 PMprat
03/26/2020, 5:52 PMThiago
03/26/2020, 6:09 PMLeland Richardson [G]
03/26/2020, 6:11 PMPaint
allocation?Thiago
03/26/2020, 6:15 PMOnClick
is a modifier?Doris Liu
03/26/2020, 6:15 PManimate
API that @Leland Richardson [G] mentioned above is available to use, since a couple of releases ago. Here is the API doc.Leland Richardson [G]
03/26/2020, 6:16 PMprat
03/26/2020, 6:47 PM