Skip to content

Commit

Permalink
🐛 Account for border width in box model
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaatttt committed Nov 2, 2022
1 parent ee923df commit d0df51b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
9 changes: 6 additions & 3 deletions Sources/AppcuesKit/Presentation/Extensions/View+Appcues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extension View {
func applyInternalLayout(_ style: AppcuesStyle) -> some View {
self
.padding(style.padding)
.applyBorderStyle(style)
.frame(width: style.width, height: style.height)
.if(style.fillWidth) { view in
view.frame(maxWidth: .infinity)
Expand Down Expand Up @@ -94,10 +95,13 @@ extension View {
}
}

func applyBorderStyle(_ style: AppcuesStyle) -> some View {
private func applyBorderStyle(_ style: AppcuesStyle) -> some View {
self
.ifLet(style.borderColor, style.borderWidth) { view, color, width in
view.overlay(
view
// The border should account for space in the layout, not just be an overlay.
.padding(width)
.overlay(
// Need to adjust the corner radius to match the radius applied to the view.
RoundedRectangle(cornerRadius: (style.cornerRadius ?? 0) - width / 2)
.stroke(color, lineWidth: width)
Expand All @@ -121,7 +125,6 @@ extension View {
.applyForegroundStyle(style)
.applyInternalLayout(style)
.applyBackgroundStyle(style)
.applyBorderStyle(style)
.applyExternalLayout(style)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ internal struct AppcuesButton: View {
}
.applyForegroundStyle(style)
.applyBackgroundStyle(style)
.applyBorderStyle(style)
.applyExternalLayout(style)
.setupActions(on: viewModel, for: model)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ internal struct AppcuesImage: View {
// clip before adding shadows
.clipped()
.applyBackgroundStyle(style)
.applyBorderStyle(style)
.applyExternalLayout(style)
}

Expand Down

0 comments on commit d0df51b

Please sign in to comment.