Add CombinedBackdropDrawer to support drawing multiple backdrops together
This commit is contained in:
1 parent
2bc3c70991
commit
4d7797e305
4 files changed
+76
-6
No files matched your search
@@ -33,16 +33,16 @@ fun rememberBackdrop(
|
||||
}
|
||||
|
||||
@Stable
|
||||
class Backdrop internal constructor(
|
||||
open class Backdrop internal constructor(
|
||||
val graphicsLayer: GraphicsLayer,
|
||||
internal val drawLayer: ContentDrawScope.() -> Unit
|
||||
) {
|
||||
) : BackdropDrawer {
|
||||
|
||||
internal var backdropCoordinates: LayoutCoordinates? by mutableStateOf(null)
|
||||
|
||||
private var inverseLayerScope: InverseLayerScope? = null
|
||||
|
||||
internal fun DrawScope.drawBackdrop(
|
||||
override fun DrawScope.drawBackdrop(
|
||||
density: Density,
|
||||
coordinates: LayoutCoordinates,
|
||||
layerBlock: (GraphicsLayerScope.() -> Unit)?
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.kyant.backdrop
|
||||
|
||||
import androidx.compose.ui.graphics.GraphicsLayerScope
|
||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||
import androidx.compose.ui.layout.LayoutCoordinates
|
||||
import androidx.compose.ui.unit.Density
|
||||
|
||||
interface BackdropDrawer {
|
||||
|
||||
fun DrawScope.drawBackdrop(
|
||||
density: Density,
|
||||
coordinates: LayoutCoordinates,
|
||||
layerBlock: (GraphicsLayerScope.() -> Unit)? = null
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.kyant.backdrop
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.graphics.GraphicsLayerScope
|
||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||
import androidx.compose.ui.layout.LayoutCoordinates
|
||||
import androidx.compose.ui.unit.Density
|
||||
|
||||
@Composable
|
||||
fun rememberCombinedBackdropDrawer(backdrop1: Backdrop, backdrop2: Backdrop): BackdropDrawer {
|
||||
return remember(backdrop1, backdrop2) {
|
||||
CombinedBackdropDrawer(backdrop1, backdrop2)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberCombinedBackdropDrawer(vararg backdrops: Backdrop): BackdropDrawer {
|
||||
return remember(*backdrops) {
|
||||
CombinedBackdropsDrawer(*backdrops)
|
||||
}
|
||||
}
|
||||
|
||||
@Stable
|
||||
private class CombinedBackdropDrawer(
|
||||
val backdrop1: Backdrop,
|
||||
val backdrop2: Backdrop
|
||||
) : BackdropDrawer {
|
||||
|
||||
override fun DrawScope.drawBackdrop(
|
||||
density: Density,
|
||||
coordinates: LayoutCoordinates,
|
||||
layerBlock: (GraphicsLayerScope.() -> Unit)?
|
||||
) {
|
||||
with(backdrop1) { drawBackdrop(density, coordinates, layerBlock) }
|
||||
with(backdrop2) { drawBackdrop(density, coordinates, layerBlock) }
|
||||
}
|
||||
}
|
||||
|
||||
@Stable
|
||||
private class CombinedBackdropsDrawer(
|
||||
vararg val backdrops: Backdrop
|
||||
) : BackdropDrawer {
|
||||
|
||||
override fun DrawScope.drawBackdrop(
|
||||
density: Density,
|
||||
coordinates: LayoutCoordinates,
|
||||
layerBlock: (GraphicsLayerScope.() -> Unit)?
|
||||
) {
|
||||
backdrops.forEach {
|
||||
with(it) { drawBackdrop(density, coordinates, layerBlock) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ internal val DefaultShadow = { Shadow() }
|
||||
private val DefaultOnDrawBackdrop: DrawScope.(DrawScope.() -> Unit) -> Unit = { it() }
|
||||
|
||||
fun Modifier.drawBackdrop(
|
||||
backdrop: Backdrop,
|
||||
backdrop: BackdropDrawer,
|
||||
shape: () -> Shape,
|
||||
highlight: (() -> Highlight?)? = DefaultHighlight,
|
||||
shadow: (() -> Shadow?)? = DefaultShadow,
|
||||
@@ -95,7 +95,7 @@ fun Modifier.drawBackdrop(
|
||||
}
|
||||
|
||||
private class DrawBackdropElement(
|
||||
val backdrop: Backdrop,
|
||||
val backdrop: BackdropDrawer,
|
||||
val shapeProvider: BackdropShapeProvider,
|
||||
val layerBlock: (GraphicsLayerScope.() -> Unit)?,
|
||||
val onDrawBehind: (DrawScope.() -> Unit)?,
|
||||
@@ -172,7 +172,7 @@ private class DrawBackdropElement(
|
||||
}
|
||||
|
||||
private class DrawBackdropNode(
|
||||
var backdrop: Backdrop,
|
||||
var backdrop: BackdropDrawer,
|
||||
var shapeProvider: BackdropShapeProvider,
|
||||
var layerBlock: (GraphicsLayerScope.() -> Unit)?,
|
||||
var onDrawBehind: (DrawScope.() -> Unit)?,
|
||||
|
||||
Reference in new issue
Block a user