Update border
This commit is contained in:
1 parent
042f5654b3
commit
1d305c0b76
7 files changed
+19
-14
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -8,6 +8,7 @@ import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.unit.Density
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlin.math.PI
|
||||
|
||||
@Immutable
|
||||
@@ -27,7 +28,7 @@ sealed interface GlassBorder {
|
||||
@Immutable
|
||||
data class Highlight(
|
||||
val angle: Float = 45f,
|
||||
val decay: Float = 2f
|
||||
val decay: Float = 1f
|
||||
) : GlassBorder {
|
||||
|
||||
private var highlightShaderCache: RuntimeShader? = null
|
||||
@@ -37,8 +38,8 @@ sealed interface GlassBorder {
|
||||
val blurRenderEffect =
|
||||
cachedBlurRenderEffect
|
||||
?: RenderEffect.createBlurEffect(
|
||||
2f,
|
||||
2f,
|
||||
with(density) { 0.5f.dp.toPx() },
|
||||
with(density) { 0.5f.dp.toPx() },
|
||||
Shader.TileMode.DECAL
|
||||
).also { cachedBlurRenderEffect = it }
|
||||
|
||||
|
||||
@@ -240,19 +240,17 @@ internal class LiquidGlassModifierNode(
|
||||
graphicsLayer?.renderEffect = renderEffect.asComposeRenderEffect()
|
||||
|
||||
if (style.border != GlassBorder.None) {
|
||||
borderGraphicsLayer?.let { layer ->
|
||||
val borderOutline = style.shape.createOutline(size, layoutDirection, this)
|
||||
val borderRenderEffect = style.border.createRenderEffect(this, size, cornerRadiusPx)
|
||||
|
||||
borderGraphicsLayer?.let { layer ->
|
||||
layer.renderEffect = borderRenderEffect?.asComposeRenderEffect()
|
||||
layer.blendMode = BlendMode.Plus
|
||||
|
||||
val borderOutline = style.shape.createOutline(size, layoutDirection, this)
|
||||
|
||||
layer.record {
|
||||
drawOutline(
|
||||
outline = borderOutline,
|
||||
brush = SolidColor(Color.White),
|
||||
style = Stroke(1.5f.dp.toPx())
|
||||
brush = SolidColor(Color.White.copy(alpha = 0.4f)),
|
||||
style = Stroke(2.dp.toPx())
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -304,22 +302,28 @@ internal class LiquidGlassModifierNode(
|
||||
}
|
||||
|
||||
override fun onAttach() {
|
||||
val graphicsContext = requireGraphicsContext()
|
||||
graphicsLayer =
|
||||
requireGraphicsContext().createGraphicsLayer().apply {
|
||||
graphicsContext.createGraphicsLayer().apply {
|
||||
compositingStrategy = androidx.compose.ui.graphics.layer.CompositingStrategy.Offscreen
|
||||
}
|
||||
borderGraphicsLayer =
|
||||
requireGraphicsContext().createGraphicsLayer().apply {
|
||||
graphicsContext.createGraphicsLayer().apply {
|
||||
compositingStrategy = androidx.compose.ui.graphics.layer.CompositingStrategy.Offscreen
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetach() {
|
||||
graphicsLayer?.let { layer -> requireGraphicsContext().releaseGraphicsLayer(layer) }
|
||||
borderGraphicsLayer?.let { layer -> requireGraphicsContext().releaseGraphicsLayer(layer) }
|
||||
val graphicsContext = requireGraphicsContext()
|
||||
graphicsLayer?.let { layer ->
|
||||
graphicsContext.releaseGraphicsLayer(layer)
|
||||
graphicsLayer = null
|
||||
}
|
||||
borderGraphicsLayer?.let { layer ->
|
||||
graphicsContext.releaseGraphicsLayer(layer)
|
||||
borderGraphicsLayer = null
|
||||
}
|
||||
}
|
||||
|
||||
fun update(
|
||||
state: LiquidGlassProviderState,
|
||||
|
||||
@@ -180,7 +180,7 @@ internal object LiquidGlassShaders {
|
||||
|
||||
float2 grad = gradSdRoundedRectangle(centeredCoord, halfSize, cornerRadius);
|
||||
float2 topLightNormal = float2(-cos(angle), -sin(angle));
|
||||
float topLightFraction = dot(topLightNormal, grad) * 0.7;
|
||||
float topLightFraction = dot(topLightNormal, grad);
|
||||
float bottomLightFraction = -topLightFraction;
|
||||
float fraction = pow(max(topLightFraction, bottomLightFraction), decay);
|
||||
|
||||
|
||||
Reference in new issue
Block a user