Skip to content

Commit

Permalink
Fix padding around infinite frame bug
Browse files Browse the repository at this point in the history
  • Loading branch information
aabewhite committed Nov 1, 2024
1 parent 8a42bc6 commit f6c1592
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions Sources/SkipUI/SkipUI/Compose/ComposeLayouts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,24 @@ private func adjacentSafeAreaEdges(bounds: Rect, safeArea: SafeArea, isRTL: Bool
}

@Composable func PaddingLayout(padding: EdgeInsets, context: ComposeContext, target: @Composable (ComposeContext) -> Void) {
let density = LocalDensity.current
let topPx = with(density) { padding.top.dp.roundToPx() }
let bottomPx = with(density) { padding.bottom.dp.roundToPx() }
let leadingPx = with(density) { padding.leading.dp.roundToPx() }
let trailingPx = with(density) { padding.trailing.dp.roundToPx() }
Layout(modifier: context.modifier, content = {
target(context.content())
}) { measurables, constraints in
guard !measurables.isEmpty() else {
return layout(width: 0, height: 0) {}
}
let updatedConstraints = constraints.copy(minWidth: constraint(constraints.minWidth, subtracting: leadingPx + trailingPx), minHeight: constraint(constraints.minHeight, subtracting: topPx + bottomPx), maxWidth: constraint(constraints.maxWidth, subtracting: leadingPx + trailingPx), maxHeight: constraint(constraints.maxHeight, subtracting: topPx + bottomPx))
let targetPlaceables = measurables.map { $0.measure(updatedConstraints) }
layout(width: targetPlaceables[0].width + leadingPx + trailingPx, height: targetPlaceables[0].height + topPx + bottomPx) {
for targetPlaceable in targetPlaceables {
targetPlaceable.placeRelative(x: leadingPx, y: topPx)
ComposeContainer(modifier: context.modifier) { modifier in
let density = LocalDensity.current
let topPx = with(density) { padding.top.dp.roundToPx() }
let bottomPx = with(density) { padding.bottom.dp.roundToPx() }
let leadingPx = with(density) { padding.leading.dp.roundToPx() }
let trailingPx = with(density) { padding.trailing.dp.roundToPx() }
Layout(modifier: modifier, content = {
target(context.content())
}) { measurables, constraints in
guard !measurables.isEmpty() else {
return layout(width: 0, height: 0) {}
}
let updatedConstraints = constraints.copy(minWidth: constraint(constraints.minWidth, subtracting: leadingPx + trailingPx), minHeight: constraint(constraints.minHeight, subtracting: topPx + bottomPx), maxWidth: constraint(constraints.maxWidth, subtracting: leadingPx + trailingPx), maxHeight: constraint(constraints.maxHeight, subtracting: topPx + bottomPx))
let targetPlaceables = measurables.map { $0.measure(updatedConstraints) }
layout(width: targetPlaceables[0].width + leadingPx + trailingPx, height: targetPlaceables[0].height + topPx + bottomPx) {
for targetPlaceable in targetPlaceables {
targetPlaceable.placeRelative(x: leadingPx, y: topPx)
}
}
}
}
Expand Down

0 comments on commit f6c1592

Please sign in to comment.