From a6f587400304e6e7c8d9ca9e85d682d4ba40af94 Mon Sep 17 00:00:00 2001 From: Robert Lin Date: Thu, 12 Oct 2023 11:05:23 -0700 Subject: [PATCH] Closes #451: Fix cut off items in scrolling horizontal/vertical list widgets Don't call frameRender() for list widgets since that clips children and any decorative elements to the widget should be applied to the parent. --- .../java/com/android/designcompose/DesignFrame.kt | 4 ++-- .../main/java/com/android/designcompose/Layout.kt | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/designcompose/src/main/java/com/android/designcompose/DesignFrame.kt b/designcompose/src/main/java/com/android/designcompose/DesignFrame.kt index bd690b261..a9bdf2fdc 100644 --- a/designcompose/src/main/java/com/android/designcompose/DesignFrame.kt +++ b/designcompose/src/main/java/com/android/designcompose/DesignFrame.kt @@ -171,9 +171,9 @@ internal fun DesignFrame( } } - // Only render the frame if we don't have a replacement node + // Only render the frame if we don't have a replacement node and layout is absolute val shape = (view.data as ViewData.Container).shape - if (replacementComponent == null) + if (replacementComponent == null && layoutInfo.shouldRender()) m = m.frameRender(style, shape, customImage, document, name, customizations, maskInfo) val lazyContent = customizations.getListContent(name) diff --git a/designcompose/src/main/java/com/android/designcompose/Layout.kt b/designcompose/src/main/java/com/android/designcompose/Layout.kt index 187565cf1..6d31195e1 100644 --- a/designcompose/src/main/java/com/android/designcompose/Layout.kt +++ b/designcompose/src/main/java/com/android/designcompose/Layout.kt @@ -30,7 +30,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Canvas import androidx.compose.ui.layout.Layout -import androidx.compose.ui.layout.Measurable import androidx.compose.ui.layout.MeasurePolicy import androidx.compose.ui.layout.ParentDataModifier import androidx.compose.ui.layout.Placeable @@ -376,7 +375,14 @@ internal fun ParentLayoutInfo.withBaseView(baseView: View?): ParentLayoutInfo { internal val rootParentLayoutInfo = ParentLayoutInfo() val widgetParent = ParentLayoutInfo(isWidgetChild = true) -internal open class SimplifiedLayoutInfo(val selfModifier: Modifier) +internal open class SimplifiedLayoutInfo(val selfModifier: Modifier) { + internal fun shouldRender(): Boolean { + // We only want to render if the layout is an absolute layout, meaning we are using our + // custom Rust layout implementation. All other layout types mean we are using the list + // widget, and any special visual styles applied in Figma should be on the widget's parent. + return this is LayoutInfoAbsolute + } +} internal class LayoutInfoAbsolute(selfModifier: Modifier) : SimplifiedLayoutInfo(selfModifier) @@ -570,8 +576,6 @@ internal class DesignLayoutData(val name: String, val layoutId: Int) : ParentDat } } -internal val Measurable.designLayoutData: DesignLayoutData? - get() = parentData as? DesignLayoutData internal val Placeable.designLayoutData: DesignLayoutData? get() = parentData as? DesignLayoutData