Skip to content

Commit

Permalink
Initialize an default ViewStyle while generating replacement list chi…
Browse files Browse the repository at this point in the history
…ld nodes
  • Loading branch information
timothyfroehlich committed Dec 30, 2024
1 parent e5f6cd2 commit dcb82af
Show file tree
Hide file tree
Showing 51 changed files with 46 additions and 0 deletions.
Binary file modified crates/figma_import/tests/layout-unit-tests.dcf
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,22 @@ import com.android.designcompose.definition.element.background
import com.android.designcompose.definition.element.color
import com.android.designcompose.definition.element.colorOrVar
import com.android.designcompose.definition.element.dimensionProto
import com.android.designcompose.definition.element.dimensionRect
import com.android.designcompose.definition.element.viewShape
import com.android.designcompose.definition.interaction.action
import com.android.designcompose.definition.interaction.reaction
import com.android.designcompose.definition.interaction.trigger
import com.android.designcompose.definition.layout.AlignContent
import com.android.designcompose.definition.layout.AlignItems
import com.android.designcompose.definition.layout.AlignSelf
import com.android.designcompose.definition.layout.FlexDirection
import com.android.designcompose.definition.layout.ItemSpacingKt.auto
import com.android.designcompose.definition.layout.JustifyContent
import com.android.designcompose.definition.layout.Overflow
import com.android.designcompose.definition.layout.OverflowDirection
import com.android.designcompose.definition.layout.PositionType
import com.android.designcompose.definition.layout.itemSpacing
import com.android.designcompose.definition.layout.layoutStyle
import com.android.designcompose.definition.layout.scrollInfo
import com.android.designcompose.definition.plugin.FrameExtras
import com.android.designcompose.definition.plugin.OverlayBackgroundInteraction
Expand Down Expand Up @@ -170,6 +176,8 @@ internal fun resolveVariantsRecursively(
var overrideStyle: ViewStyle? = null
var view = viewFromTree

assert(view.style.layoutStyle.hasPadding())

// If we have a component then we might need to get an override style, and we definitely
// need to get a different layout id.
if (viewFromTree.hasComponentInfo()) {
Expand Down Expand Up @@ -468,6 +476,7 @@ internal fun resolveVariantsRecursively(
)
}
}
assert(resolvedView.view.style.layoutStyle.hasPadding())

return resolvedView
}
Expand All @@ -494,6 +503,43 @@ internal fun generateReplacementListChildNode(
scrollInfo = listChildScrollInfo
data = viewData { container = listChildViewData }
renderMethod = View.RenderMethod.RENDER_METHOD_NONE

// The Rust code currently fails if any of these fields are unset so we initialize
// a default viewStyle. (the nodeStyle isn't needed right now)
style = viewStyle {
layoutStyle = layoutStyle {
padding = dimensionRect {
start = dimensionProto { undefined }
end = dimensionProto { undefined }
top = dimensionProto { undefined }
bottom = dimensionProto { undefined }
}
flexBasis = dimensionProto { undefined }
itemSpacing = itemSpacing { auto = auto {} }
alignContent = AlignContent.ALIGN_CONTENT_FLEX_START
justifyContent = JustifyContent.JUSTIFY_CONTENT_FLEX_START
alignItems = AlignItems.ALIGN_ITEMS_FLEX_START
flexDirection = FlexDirection.FLEX_DIRECTION_NONE
alignSelf = AlignSelf.ALIGN_SELF_AUTO
width = dimensionProto { undefined }
height = dimensionProto { undefined }
minWidth = dimensionProto { undefined }
minHeight = dimensionProto { undefined }
maxWidth = dimensionProto { undefined }
maxHeight = dimensionProto { undefined }
positionType = PositionType.POSITION_TYPE_ABSOLUTE
left = dimensionProto { undefined }
top = dimensionProto { undefined }
right = dimensionProto { undefined }
bottom = dimensionProto { undefined }
margin = dimensionRect {
start = dimensionProto { undefined }
end = dimensionProto { undefined }
top = dimensionProto { undefined }
bottom = dimensionProto { undefined }
}
}
}
}

val listLayoutId = layoutIdAllocator.listLayoutId(node.layoutId)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit dcb82af

Please sign in to comment.