Peter Mandeljc
06/30/2021, 7:10 AMCicero
06/30/2021, 8:29 AMPeter Mandeljc
06/30/2021, 9:04 AMCicero
06/30/2021, 9:53 AMAndrey Kulikov
06/30/2021, 10:59 AMCicero
06/30/2021, 12:50 PMChris Sinco [G]
06/30/2021, 4:19 PMblur
Modifier in the futureCicero
06/30/2021, 4:45 PMCicero
06/30/2021, 5:09 PMCicero
06/30/2021, 6:24 PM@Composable
fun Modifier.glow(color: Color = Color(0xFFFF00FF), size: Int = 400, thickness: Dp = 8.dp) =
border(
brush = Brush.radialGradient(
0.1f to color,
1.0f to Color.White,
center = Offset.Unspecified,
radius = size.toFloat() * 1.5f,
tileMode = TileMode.Clamp
), width = thickness,
shape = MaterialTheme.shapes.medium
)
I’l probably play more around it, I need to thing about how to give some fluff to this border widthCicero
06/30/2021, 6:27 PMCicero
07/01/2021, 10:19 AMCicero
07/01/2021, 10:21 AMCicero
07/01/2021, 3:18 PMNader Jawad
07/08/2021, 8:20 PMfun Modifier.glowBorder(color: Color, width: Dp): Modifier {
return this.then(Modifier.drawWithCache {
val colorWithOpacity = color.copy(0.5f)
val stops = arrayOf(
0.0f to Color.Transparent,
0.15f to colorWithOpacity,
0.3f to colorWithOpacity,
0.3f to color,
0.4f to Color.White,
0.5f to Color.White,
0.6f to Color.White,
0.7f to color,
0.7f to colorWithOpacity,
0.85f to colorWithOpacity,
1.0f to Color.Transparent
)
val widthPx = width.toPx()
val leftGlowBar = Brush.horizontalGradient(
*stops,
endX = widthPx
)
val topGlowBar = Brush.verticalGradient(*stops,
startY = 0f,
endY = widthPx
)
val rightGlowBar = Brush.horizontalGradient(*stops,
startX = size.width - widthPx,
endX = size.width
)
val bottomGlowBar = Brush.verticalGradient(
*stops,
startY = size.height - widthPx,
endY = size.height
)
val topLeftGlow = Brush.radialGradient(
*stops,
center = Offset(widthPx, widthPx),
radius = widthPx
)
val topRightGlow = Brush.radialGradient(
*stops,
center = Offset(size.width - widthPx, widthPx),
radius = widthPx
)
val bottomRightGlow = Brush.radialGradient(
*stops,
center = Offset(size.width - widthPx, size.height - widthPx),
radius = widthPx
)
val bottomLeftGlow = Brush.radialGradient(
*stops,
center = Offset(widthPx, size.height - widthPx),
radius = widthPx
)
val horizontalBarSize = Size(size.width - widthPx * 2, widthPx)
val verticalBarSize = Size(widthPx, size.height - widthPx * 2)
val topBarOffset = Offset(widthPx, 0f)
val bottomBarOffset = Offset(widthPx, size.height - widthPx)
val leftBarOffset = Offset(0f, widthPx)
val rightBarOffset = Offset(size.width - widthPx, widthPx)
val cornerSize = Size(widthPx, widthPx)
val topLeftOffset = Offset.Zero
val topRightOffset = Offset(size.width - widthPx, 0f)
val bottomRightOffset = Offset(size.width - widthPx, size.height - widthPx)
val bottomLeftOffset = Offset(0f, size.height - widthPx)
onDrawWithContent {
drawContent()
drawRect(topLeftGlow, topLeft = topLeftOffset, size = cornerSize)
drawRect(topRightGlow, topLeft = topRightOffset, size = cornerSize)
drawRect(bottomRightGlow, topLeft = bottomRightOffset, size = cornerSize)
drawRect(bottomLeftGlow, topLeft = bottomLeftOffset, size = cornerSize)
drawRect(leftGlowBar, topLeft = leftBarOffset, size = verticalBarSize)
drawRect(topGlowBar, topLeft = topBarOffset, size = horizontalBarSize)
drawRect(rightGlowBar, topLeft = rightBarOffset, size = verticalBarSize)
drawRect(bottomGlowBar, topLeft = bottomBarOffset, size = horizontalBarSize)
}
})
}
@Composable
fun GlowBorderDemo() {
Box(modifier = Modifier.size(300.dp, 200.dp).glowBorder(Color.Magenta, 30.dp))
}
Nader Jawad
07/08/2021, 8:21 PMNader Jawad
07/08/2021, 8:23 PM