Skip to content

Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.

fix: keep PDF tool controls above carousel surfaces

Chethan6162eb46cbcceb8
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/ViewerGlass.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/ViewerGlass.kt
index b80ae61..fafa27a 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/ViewerGlass.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/ViewerGlass.kt
@@ -8,7 +8,6 @@ import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.CompositingStrategy
import androidx.compose.ui.graphics.Shape
-import androidx.compose.ui.graphics.drawOutline
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -50,10 +49,7 @@ fun Modifier.viewerGlass(
shape: () -> Shape = { ViewerGlassShape },
// Off for surfaces that must NOT cast a drop shadow — e.g. the onboarding page-1 book, whose
// shadow otherwise snapped in the moment the assembled book reached full opacity.
- withShadow: Boolean = true,
- // Panels sometimes host animated/scrolling controls that intentionally float beyond the glass
- // silhouette. The default preserves the original safe behavior for the rest of the app.
- clipContent: Boolean = true
+ withShadow: Boolean = true
): Modifier = drawBackdrop(
backdrop = backdrop,
shape = shape,
@@ -63,12 +59,7 @@ fun Modifier.viewerGlass(
lens(12f.dp.toPx(), 24f.dp.toPx())
},
shadow = if (withShadow) ({ com.kyant.backdrop.shadow.Shadow.Default }) else null,
- clipContent = clipContent,
- onDrawSurface = {
- // When content is allowed to overflow, draw the tint as the glass outline instead of a
- // rectangular wash. This keeps the material rounded while its controls remain un-clipped.
- drawOutline(shape().createOutline(size, layoutDirection, this), color)
- }
+ onDrawSurface = { drawRect(color) }
)
/**
@@ -105,15 +96,17 @@ fun Modifier.viewerGlass(
fun Modifier.carouselEdges(
state: ScrollState,
shape: Shape = ViewerGlassShape,
- fade: Dp = 18.dp
+ fade: Dp = 18.dp,
+ // Keep the fade mask, but allow a caller with its own overflow-safe layer to opt out of
+ // clipping the interactive children to the viewport's rounded outline.
+ clipContent: Boolean = true
): Modifier = this
- // Keep the edge fade isolated. `Offscreen` is not decoration: it is what makes the `DstIn` below
- // mask this strip rather than punch a hole through everything already on the canvas. `clip`
- // stays false on purpose; the glass panel owns the surface shape, while this scrolling content
- // remains a floating layer that is not chopped by the panel's corners.
+ // One layer does both jobs. `Offscreen` is not decoration: it is what makes the `DstIn` below
+ // mask this strip rather than punch a hole through everything already on the canvas.
.graphicsLayer {
compositingStrategy = CompositingStrategy.Offscreen
- clip = false
+ clip = clipContent
+ this.shape = shape
}
.drawWithContent {
drawContent()
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt
index da334f2..77ada9a 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt
@@ -30,6 +30,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@@ -98,6 +99,25 @@ import com.kyant.backdrop.backdrops.LayerBackdrop
*/
private const val FaceHandoffMillis = 150
+/**
+ * A glass surface and its controls are siblings on purpose. [viewerGlass] owns a shaped offscreen
+ * layer, which is exactly what gives the panel its clean rounded material; placing animated buttons
+ * inside that layer clips their press-deformation at the panel edge. This surface keeps the glass
+ * clipped and lets the interactive content paint in an overflow-safe layer above it.
+ */
+@Composable
+private fun ViewerGlassOverflowSurface(
+ modifier: Modifier,
+ backdrop: LayerBackdrop,
+ color: Color,
+ content: @Composable BoxScope.() -> Unit
+) {
+ Box(modifier) {
+ Box(Modifier.matchParentSize().viewerGlass(backdrop, color))
+ Box(Modifier.fillMaxWidth().zIndex(1f), content = content)
+ }
+}
+
@Composable
internal fun PdfViewerBottomToolbar(
// display state
@@ -258,15 +278,19 @@ internal fun PdfViewerBottomToolbar(
},
label = "drawToolsReveal"
) { if (it == EnterExitState.Visible) 1f else 0f }
- Column(
- Modifier.fillMaxWidth()
+ ViewerGlassOverflowSurface(
+ modifier = Modifier.fillMaxWidth()
.graphicsLayer {
scaleY = 0.9f + 0.1f * reveal
transformOrigin = TransformOrigin(0.5f, 1f)
translationY = (1f - reveal) * 8.dp.toPx()
}
- .graphicsLayer { scaleX = toolCompress; transformOrigin = TransformOrigin(0f, 0.5f) }
- .viewerGlass(backdrop, glass, clipContent = false).padding(12.dp),
+ .graphicsLayer { scaleX = toolCompress; transformOrigin = TransformOrigin(0f, 0.5f) },
+ backdrop = backdrop,
+ color = glass
+ ) {
+ Column(
+ Modifier.fillMaxWidth().padding(12.dp),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
Row(
@@ -291,9 +315,9 @@ internal fun PdfViewerBottomToolbar(
Row(
modifier = Modifier
.weight(1f)
- .carouselEdges(toolRowScroll)
+ .carouselEdges(toolRowScroll, clipContent = false)
.horizontalScroll(toolRowScroll)
- .padding(horizontal = 4.dp),
+ .padding(horizontal = 12.dp, vertical = 8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
@@ -418,9 +442,9 @@ internal fun PdfViewerBottomToolbar(
Row(
Modifier
.fillMaxWidth()
- .carouselEdges(attrRowScroll)
+ .carouselEdges(attrRowScroll, clipContent = false)
.horizontalScroll(attrRowScroll)
- .padding(horizontal = 4.dp),
+ .padding(horizontal = 12.dp, vertical = 8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
@@ -454,12 +478,13 @@ internal fun PdfViewerBottomToolbar(
}
}
}
+ }
}
// ── Export feedback row ────────────────────────────────────────────
if (exportError != null || exportMessage != null || isExporting) {
Row(
- Modifier.fillMaxWidth().viewerGlass(backdrop, glass, clipContent = false).padding(12.dp),
+ Modifier.fillMaxWidth().viewerGlass(backdrop, glass).padding(12.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
@@ -516,30 +541,38 @@ internal fun PdfViewerBottomToolbar(
if (docKind == DocKind.Ppt) {
// PowerPoint editing isn't available yet — a friendly placeholder instead of the
// annotation tools (which don't map cleanly onto slides).
- Row(
- Modifier
- .fillMaxWidth()
- .graphicsLayer { scaleX = toolCompress; transformOrigin = TransformOrigin(0f, 0.5f) }
- .viewerGlass(backdrop, pillGlass, clipContent = false)
- .padding(horizontal = 16.dp, vertical = 16.dp),
- horizontalArrangement = Arrangement.spacedBy(10.dp, Alignment.CenterHorizontally),
- verticalAlignment = Alignment.CenterVertically
+ ViewerGlassOverflowSurface(
+ modifier = Modifier.fillMaxWidth()
+ .graphicsLayer { scaleX = toolCompress; transformOrigin = TransformOrigin(0f, 0.5f) },
+ backdrop = backdrop,
+ color = pillGlass
) {
- Icon(Icons.Rounded.Slideshow, null, Modifier.size(20.dp), fg)
- BasicText(stringResource(R.string.viewer_tools_coming_soon), style = TextStyle(fg, 14.sp, FontWeight.SemiBold))
+ Row(
+ Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 16.dp),
+ horizontalArrangement = Arrangement.spacedBy(10.dp, Alignment.CenterHorizontally),
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Icon(Icons.Rounded.Slideshow, null, Modifier.size(20.dp), fg)
+ BasicText(stringResource(R.string.viewer_tools_coming_soon), style = TextStyle(fg, 14.sp, FontWeight.SemiBold))
+ }
}
} else if (docKind == DocKind.Word) {
// Curated Word reading/markup set — Select Text, Highlight, Find. No PDF-centric
// shapes / add-image / text-box / note / eraser / sign.
val wordScroll = rememberScrollState()
+ ViewerGlassOverflowSurface(
+ modifier = Modifier.fillMaxWidth()
+ .graphicsLayer { scaleX = toolCompress; transformOrigin = TransformOrigin(0f, 0.5f) },
+ backdrop = backdrop,
+ color = pillGlass
+ ) {
Row(
Modifier
.fillMaxWidth()
- .graphicsLayer { scaleX = toolCompress; transformOrigin = TransformOrigin(0f, 0.5f) }
- .viewerGlass(backdrop, pillGlass, clipContent = false)
- // Clip to the capsule's own curve and soften the ends. See [carouselEdges]
- // for why the padding has to come after the scroll, not before it.
- .carouselEdges(wordScroll)
+ // Keep the existing fade mask and scroll behavior; the extra vertical
+ // breathing room is what lets a pressed chip deform without touching the
+ // viewport's top or bottom edge.
+ .carouselEdges(wordScroll, clipContent = false)
.horizontalScroll(wordScroll)
.padding(horizontal = 12.dp, vertical = 10.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
@@ -567,17 +600,21 @@ internal fun PdfViewerBottomToolbar(
}
}
}
+ }
} else {
val toolScroll = rememberScrollState()
+ ViewerGlassOverflowSurface(
+ modifier = Modifier.fillMaxWidth()
+ .graphicsLayer { scaleX = toolCompress; transformOrigin = TransformOrigin(0f, 0.5f) },
+ backdrop = backdrop,
+ color = pillGlass
+ ) {
Row(
Modifier
.fillMaxWidth()
- .graphicsLayer { scaleX = toolCompress; transformOrigin = TransformOrigin(0f, 0.5f) }
- .viewerGlass(backdrop, pillGlass, clipContent = false)
- // The chips are meant to disappear behind the capsule's curved ends. Without
- // this the scroll viewport clipped them with a straight vertical line inset
- // from the curve. See [carouselEdges] — the padding order is load-bearing.
- .carouselEdges(toolScroll)
+ // The existing carouselEdges mask remains unchanged; this row is simply
+ // rendered above the separate glass sibling so its chips can overflow cleanly.
+ .carouselEdges(toolScroll, clipContent = false)
.horizontalScroll(toolScroll)
.padding(horizontal = 12.dp, vertical = 10.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
@@ -690,6 +727,7 @@ internal fun PdfViewerBottomToolbar(
}
}
}
+ }
}
// ── Collapsed home bar: one "Editor Tools" pill (expands the tools above it)
diff --git a/backdrop/src/commonMain/kotlin/com/kyant/backdrop/DrawBackdropModifier.kt b/backdrop/src/commonMain/kotlin/com/kyant/backdrop/DrawBackdropModifier.kt
index 20167bd..925b91f 100644
--- a/backdrop/src/commonMain/kotlin/com/kyant/backdrop/DrawBackdropModifier.kt
+++ b/backdrop/src/commonMain/kotlin/com/kyant/backdrop/DrawBackdropModifier.kt
@@ -51,8 +51,7 @@ fun Modifier.drawPlainBackdrop(
onDrawBehind: (DrawScope.() -> Unit)? = null,
onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit = DefaultOnDrawBackdrop,
onDrawSurface: (DrawScope.() -> Unit)? = null,
- onDrawFront: (DrawScope.() -> Unit)? = null,
- clipContent: Boolean = true
+ onDrawFront: (DrawScope.() -> Unit)? = null
): Modifier {
val shapeProvider = ShapeProvider(shape)
return this
@@ -73,12 +72,10 @@ fun Modifier.drawPlainBackdrop(
onDrawBehind = onDrawBehind,
onDrawBackdrop = onDrawBackdrop,
onDrawSurface = onDrawSurface,
- onDrawFront = onDrawFront,
- clipContent = clipContent
+ onDrawFront = onDrawFront
)
)
}
-
fun Modifier.drawBackdrop(
backdrop: Backdrop,
shape: () -> Shape,
@@ -91,8 +88,7 @@ fun Modifier.drawBackdrop(
onDrawBehind: (DrawScope.() -> Unit)? = null,
onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit = DefaultOnDrawBackdrop,
onDrawSurface: (DrawScope.() -> Unit)? = null,
- onDrawFront: (DrawScope.() -> Unit)? = null,
- clipContent: Boolean = true
+ onDrawFront: (DrawScope.() -> Unit)? = null
): Modifier {
val shapeProvider = ShapeProvider(shape)
return this
@@ -143,8 +139,7 @@ fun Modifier.drawBackdrop(
onDrawBehind = onDrawBehind,
onDrawBackdrop = onDrawBackdrop,
onDrawSurface = onDrawSurface,
- onDrawFront = onDrawFront,
- clipContent = clipContent
+ onDrawFront = onDrawFront
)
)
}
@@ -158,8 +153,7 @@ private class DrawBackdropElement(
val onDrawBehind: (DrawScope.() -> Unit)?,
val onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit,
val onDrawSurface: (DrawScope.() -> Unit)?,
- val onDrawFront: (DrawScope.() -> Unit)?,
- val clipContent: Boolean
+ val onDrawFront: (DrawScope.() -> Unit)?
) : ModifierNodeElement<DrawBackdropNode>() {
override fun create(): DrawBackdropNode {
@@ -172,8 +166,7 @@ private class DrawBackdropElement(
onDrawBehind = onDrawBehind,
onDrawBackdrop = onDrawBackdrop,
onDrawSurface = onDrawSurface,
- onDrawFront = onDrawFront,
- clipContent = clipContent
+ onDrawFront = onDrawFront
)
}
@@ -190,7 +183,6 @@ private class DrawBackdropElement(
node.onDrawBackdrop = onDrawBackdrop
node.onDrawSurface = onDrawSurface
node.onDrawFront = onDrawFront
- node.clipContent = clipContent
node.invalidateDrawCache()
}
@@ -205,7 +197,6 @@ private class DrawBackdropElement(
properties["onDrawBackdrop"] = onDrawBackdrop
properties["onDrawSurface"] = onDrawSurface
properties["onDrawFront"] = onDrawFront
- properties["clipContent"] = clipContent
}
override fun equals(other: Any?): Boolean {
@@ -221,7 +212,6 @@ private class DrawBackdropElement(
if (onDrawBackdrop != other.onDrawBackdrop) return false
if (onDrawSurface != other.onDrawSurface) return false
if (onDrawFront != other.onDrawFront) return false
- if (clipContent != other.clipContent) return false
return true
}
@@ -236,7 +226,6 @@ private class DrawBackdropElement(
result = 31 * result + onDrawBackdrop.hashCode()
result = 31 * result + (onDrawSurface?.hashCode() ?: 0)
result = 31 * result + (onDrawFront?.hashCode() ?: 0)
- result = 31 * result + clipContent.hashCode()
return result
}
}
@@ -250,8 +239,7 @@ private class DrawBackdropNode(
var onDrawBehind: (DrawScope.() -> Unit)?,
var onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit,
var onDrawSurface: (DrawScope.() -> Unit)?,
- var onDrawFront: (DrawScope.() -> Unit)?,
- var clipContent: Boolean
+ var onDrawFront: (DrawScope.() -> Unit)?
) : LayoutModifierNode, DrawModifierNode, GlobalPositionAwareModifierNode, ObserverModifierNode, Modifier.Node() {
private val effectScope =
@@ -263,7 +251,7 @@ private class DrawBackdropNode(
private var graphicsLayer: GraphicsLayer? = null
private val layoutLayerBlock: GraphicsLayerScope.() -> Unit = {
- clip = clipContent
+ clip = true
shape = shapeProvider.shape
compositingStrategy = androidx.compose.ui.graphics.CompositingStrategy.Offscreen
}
diff --git a/backdrop/src/main/java/com/kyant/backdrop/DrawBackdropModifier.kt b/backdrop/src/main/java/com/kyant/backdrop/DrawBackdropModifier.kt
index c349c83..60b79a1 100644
--- a/backdrop/src/main/java/com/kyant/backdrop/DrawBackdropModifier.kt
+++ b/backdrop/src/main/java/com/kyant/backdrop/DrawBackdropModifier.kt
@@ -57,8 +57,7 @@ fun Modifier.drawPlainBackdrop(
onDrawBehind: (DrawScope.() -> Unit)? = null,
onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit = DefaultOnDrawBackdrop,
onDrawSurface: (DrawScope.() -> Unit)? = null,
- onDrawFront: (DrawScope.() -> Unit)? = null,
- clipContent: Boolean = true
+ onDrawFront: (DrawScope.() -> Unit)? = null
): Modifier {
val shapeProvider = ShapeProvider(shape)
return this
@@ -79,8 +78,7 @@ fun Modifier.drawPlainBackdrop(
onDrawBehind = onDrawBehind,
onDrawBackdrop = onDrawBackdrop,
onDrawSurface = onDrawSurface,
- onDrawFront = onDrawFront,
- clipContent = clipContent
+ onDrawFront = onDrawFront
)
)
}
@@ -97,8 +95,7 @@ fun Modifier.drawBackdrop(
onDrawBehind: (DrawScope.() -> Unit)? = null,
onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit = DefaultOnDrawBackdrop,
onDrawSurface: (DrawScope.() -> Unit)? = null,
- onDrawFront: (DrawScope.() -> Unit)? = null,
- clipContent: Boolean = true
+ onDrawFront: (DrawScope.() -> Unit)? = null
): Modifier {
val shapeProvider = ShapeProvider(shape)
return this
@@ -149,8 +146,7 @@ fun Modifier.drawBackdrop(
onDrawBehind = onDrawBehind,
onDrawBackdrop = onDrawBackdrop,
onDrawSurface = onDrawSurface,
- onDrawFront = onDrawFront,
- clipContent = clipContent
+ onDrawFront = onDrawFront
)
)
}
@@ -164,8 +160,7 @@ private class DrawBackdropElement(
val onDrawBehind: (DrawScope.() -> Unit)?,
val onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit,
val onDrawSurface: (DrawScope.() -> Unit)?,
- val onDrawFront: (DrawScope.() -> Unit)?,
- val clipContent: Boolean
+ val onDrawFront: (DrawScope.() -> Unit)?
) : ModifierNodeElement<DrawBackdropNode>() {
override fun create(): DrawBackdropNode {
@@ -178,8 +173,7 @@ private class DrawBackdropElement(
onDrawBehind = onDrawBehind,
onDrawBackdrop = onDrawBackdrop,
onDrawSurface = onDrawSurface,
- onDrawFront = onDrawFront,
- clipContent = clipContent
+ onDrawFront = onDrawFront
)
}
@@ -193,7 +187,6 @@ private class DrawBackdropElement(
node.onDrawBackdrop = onDrawBackdrop
node.onDrawSurface = onDrawSurface
node.onDrawFront = onDrawFront
- node.clipContent = clipContent
node.invalidateDrawCache()
}
@@ -208,7 +201,6 @@ private class DrawBackdropElement(
properties["onDrawBackdrop"] = onDrawBackdrop
properties["onDrawSurface"] = onDrawSurface
properties["onDrawFront"] = onDrawFront
- properties["clipContent"] = clipContent
}
override fun equals(other: Any?): Boolean {
@@ -224,7 +216,6 @@ private class DrawBackdropElement(
if (onDrawBackdrop != other.onDrawBackdrop) return false
if (onDrawSurface != other.onDrawSurface) return false
if (onDrawFront != other.onDrawFront) return false
- if (clipContent != other.clipContent) return false
return true
}
@@ -239,7 +230,6 @@ private class DrawBackdropElement(
result = 31 * result + onDrawBackdrop.hashCode()
result = 31 * result + (onDrawSurface?.hashCode() ?: 0)
result = 31 * result + (onDrawFront?.hashCode() ?: 0)
- result = 31 * result + clipContent.hashCode()
return result
}
}
@@ -253,8 +243,7 @@ private class DrawBackdropNode(
var onDrawBehind: (DrawScope.() -> Unit)?,
var onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit,
var onDrawSurface: (DrawScope.() -> Unit)?,
- var onDrawFront: (DrawScope.() -> Unit)?,
- var clipContent: Boolean
+ var onDrawFront: (DrawScope.() -> Unit)?
) : LayoutModifierNode, DrawModifierNode, GlobalPositionAwareModifierNode, ObserverModifierNode, Modifier.Node() {
private val effectScope =
@@ -266,7 +255,7 @@ private class DrawBackdropNode(
private var graphicsLayer: GraphicsLayer? = null
private val layoutLayerBlock: GraphicsLayerScope.() -> Unit = {
- clip = clipContent
+ clip = true
shape = shapeProvider.shape
compositingStrategy = androidx.compose.ui.graphics.CompositingStrategy.Offscreen
}