diff --git a/crates/figma_import/tests/layout-unit-tests.dcf b/crates/figma_import/tests/layout-unit-tests.dcf index 6d8232010..ece51f9f1 100644 Binary files a/crates/figma_import/tests/layout-unit-tests.dcf and b/crates/figma_import/tests/layout-unit-tests.dcf differ diff --git a/designcompose/src/main/assets/figma/DesignSwitcherDoc_Ljph4e3sC0lHcynfXpoh9f.dcf b/designcompose/src/main/assets/figma/DesignSwitcherDoc_Ljph4e3sC0lHcynfXpoh9f.dcf index 587a342b3..bcd29fb82 100644 Binary files a/designcompose/src/main/assets/figma/DesignSwitcherDoc_Ljph4e3sC0lHcynfXpoh9f.dcf and b/designcompose/src/main/assets/figma/DesignSwitcherDoc_Ljph4e3sC0lHcynfXpoh9f.dcf differ diff --git a/designcompose/src/main/java/com/android/designcompose/VariableManager.kt b/designcompose/src/main/java/com/android/designcompose/VariableManager.kt index a33e16698..f66b4924c 100644 --- a/designcompose/src/main/java/com/android/designcompose/VariableManager.kt +++ b/designcompose/src/main/java/com/android/designcompose/VariableManager.kt @@ -31,6 +31,7 @@ import com.android.designcompose.definition.element.NumOrVar import com.android.designcompose.definition.element.Variable import com.android.designcompose.definition.element.VariableMap import com.android.designcompose.definition.element.VariableValue +import com.android.designcompose.definition.element.copy import com.android.designcompose.utils.toColor // A variable mode, e.g. "light" or "dark" @@ -170,20 +171,21 @@ internal object VariableManager { internal fun init(docId: DesignDocId, map: VariableMap) { - // Remove old entries for docId - val oldVarMap = docVarMap[docId.id] - oldVarMap?.collectionsMap?.forEach { varMap.collectionsMap.remove(it.key) } - oldVarMap?.collectionNameMapMap?.forEach { varMap.collectionNameMapMap.remove(it.key) } - oldVarMap?.variablesMap?.forEach { varMap.variablesMap.remove(it.key) } - oldVarMap?.variableNameMapMap?.forEach { varMap.variableNameMapMap.remove(it.key) } - - // Add new entries for docId - docVarMap[docId.id] = map - varMap.collectionsMap.putAll(map.collectionsMap) - varMap.collectionNameMapMap.putAll(map.collectionNameMapMap) - varMap.variablesMap.putAll(map.variablesMap) - varMap.variableNameMapMap.putAll(map.variableNameMapMap) - + varMap = varMap.copy { + // Remove old entries for docId + val oldVarMap = docVarMap[docId.id] + oldVarMap?.collectionsMap?.forEach { this.collections.remove(it.key) } + oldVarMap?.collectionNameMapMap?.forEach { this.collectionNameMap.remove(it.key) } + oldVarMap?.variablesMap?.forEach { this.variables.remove(it.key) } + oldVarMap?.variableNameMapMap?.forEach { this.variableNameMap.remove(it.key) } + + // Add new entries for docId + docVarMap[docId.id] = map + this.collections.putAll(map.collectionsMap) + this.collectionNameMap.putAll(map.collectionNameMapMap) + this.variables.putAll(map.variablesMap) + this.variableNameMap.putAll(map.variableNameMapMap) + } currentDocId = docId } diff --git a/designcompose/src/main/java/com/android/designcompose/squoosh/SquooshLayout.kt b/designcompose/src/main/java/com/android/designcompose/squoosh/SquooshLayout.kt index 5be11ae5e..25c041601 100644 --- a/designcompose/src/main/java/com/android/designcompose/squoosh/SquooshLayout.kt +++ b/designcompose/src/main/java/com/android/designcompose/squoosh/SquooshLayout.kt @@ -209,14 +209,14 @@ private fun updateLayoutTree( layoutNodes.add( layoutNode { - layoutId - parentLayoutId - -1 // not childIdx! - resolvedNode.style.layoutStyle - resolvedNode.view.name - useMeasureFunc - null - null + this.layoutId = layoutId + this.parentLayoutId = parentLayoutId + this.childIndex = -1 // not childIdx! + this.style = resolvedNode.style.layoutStyle + this.name = resolvedNode.view.name + this.useMeasureFunc = useMeasureFunc + clearFixedWidth() + clearFixedHeight() } ) layoutCache[layoutId] = layoutCacheKey @@ -296,8 +296,8 @@ internal fun layoutTree( val layoutParentChildren = arrayListOf() updateLayoutTree(manager, root, layoutCache, layoutNodes, layoutParentChildren) val layoutNodeList = layoutNodeList { - layoutNodes - layoutParentChildren + this.layoutNodes.addAll(layoutNodes) + this.parentChildren.addAll(layoutParentChildren) } // Now we can give the new layoutNodeList to the Rust JNI layout implementation diff --git a/designcompose/src/main/java/com/android/designcompose/squoosh/SquooshTreeBuilder.kt b/designcompose/src/main/java/com/android/designcompose/squoosh/SquooshTreeBuilder.kt index 3974d6aaf..d8da21ef6 100644 --- a/designcompose/src/main/java/com/android/designcompose/squoosh/SquooshTreeBuilder.kt +++ b/designcompose/src/main/java/com/android/designcompose/squoosh/SquooshTreeBuilder.kt @@ -54,6 +54,7 @@ import com.android.designcompose.definition.view.View import com.android.designcompose.definition.view.ViewDataKt.container import com.android.designcompose.definition.view.ViewStyle import com.android.designcompose.definition.view.containerOrNull +import com.android.designcompose.definition.view.copy import com.android.designcompose.definition.view.frameExtrasOrNull import com.android.designcompose.definition.view.overridesOrNull import com.android.designcompose.definition.view.styleOrNull @@ -566,59 +567,61 @@ private fun generateOverlayNode( } } - val nodeStyleBuilder = node.style.nodeStyle.toBuilder() - nodeStyleBuilder.overflow = Overflow.OVERFLOW_VISIBLE - nodeStyleBuilder.backgroundsList.clear() - - overlay.overlayBackgroundOrNull?.colorOrNull?.let { - val bgColor = - com.android.designcompose.definition.element.color { - r = (it.r * 255.0).toInt() - g = (it.g * 255.0).toInt() - b = (it.b * 255.0).toInt() - a = (it.a * 255.0).toInt() - } - nodeStyleBuilder.backgroundsList.add(background { solid = colorOrVar { color = bgColor } }) + val newNodeStyle = node.style.nodeStyle.copy { + this.overflow = Overflow.OVERFLOW_VISIBLE + this.backgrounds.clear() + + overlay.overlayBackgroundOrNull?.colorOrNull?.let { + val bgColor = + com.android.designcompose.definition.element.color { + r = (it.r * 255.0).toInt() + g = (it.g * 255.0).toInt() + b = (it.b * 255.0).toInt() + a = (it.a * 255.0).toInt() + } + this.backgrounds.add(background { solid = colorOrVar { color = bgColor } }) + } } + val overlayStyle = viewStyle { - layoutStyle = layoutStyleBuilder.build() - nodeStyle = nodeStyleBuilder.build() + this.layoutStyle = layoutStyleBuilder.build() + this.nodeStyle = newNodeStyle } // Now synthesize a view. val overlayViewData = container { - shape = viewShape { rect = box { isMask = false } } - children.add(node.view) + this.shape = viewShape { rect = box { isMask = false } } + this.children.add(node.view) } val overlayScrollInfo = scrollInfo { - pagedScrolling = false - overflow = OverflowDirection.OVERFLOW_DIRECTION_NONE + this.pagedScrolling = false + this.overflow = OverflowDirection.OVERFLOW_DIRECTION_NONE } if (node.view.uniqueId !in 0..0xFFFF) { throw RuntimeException("View's unique ID must be in the range 0..0xFFFF") } val overlayView = view { - uniqueId = (node.view.uniqueId + 0x2000) - id = "overlay-${node.view.id}" - name = "Overlay ${node.view.name}" + this.uniqueId = (node.view.uniqueId + 0x2000) + this.id = "overlay-${node.view.id}" + this.name = "Overlay ${node.view.name}" if ( overlay.overlayBackgroundInteraction == OverlayBackgroundInteraction.OVERLAY_BACKGROUND_INTERACTION_CLOSE_ON_CLICK_OUTSIDE ) { - reactions.add( + this.reactions.add( reaction { trigger = trigger { click = empty {} } action = action { close = empty {} } } ) } - scrollInfo = overlayScrollInfo - style = overlayStyle - data = viewData { container = overlayViewData } - renderMethod = View.RenderMethod.RENDER_METHOD_NONE + this.scrollInfo = overlayScrollInfo + this.style = overlayStyle + this.data = viewData { container = overlayViewData } + this.renderMethod = View.RenderMethod.RENDER_METHOD_NONE } val overlayLayoutId = layoutIdAllocator.listLayoutId(node.layoutId) val layoutId = diff --git a/reference-apps/tutorial/app/src/main/assets/figma/TutorialDoc_3z4xExq0INrL9vxPhj9tl7.dcf b/reference-apps/tutorial/app/src/main/assets/figma/TutorialDoc_3z4xExq0INrL9vxPhj9tl7.dcf index d58bedc38..75f61d5cb 100644 Binary files a/reference-apps/tutorial/app/src/main/assets/figma/TutorialDoc_3z4xExq0INrL9vxPhj9tl7.dcf and b/reference-apps/tutorial/app/src/main/assets/figma/TutorialDoc_3z4xExq0INrL9vxPhj9tl7.dcf differ