Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DON-594: Add fitsInsideBorder property to Outline #1999

Merged
merged 8 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Backpack-SwiftUI/Select/Classes/BPKSelect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct CustomPickerStyle: ViewModifier {
.background(.surfaceDefaultColor)
.clipShape(RoundedRectangle(cornerRadius: .xs))
.disabled(pickerState.isDisabled)
.outline(pickerState.borderColor, cornerRadius: .xs)
.outline(pickerState.borderColor, cornerRadius: .xs, fitsInsideBorder: true)
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 24 additions & 7 deletions Backpack-SwiftUI/Utils/Classes/Outline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,47 @@ struct Outline: ViewModifier {
let color: BPKColor
let cornerRadius: BPKCornerRadius
let lineWidth: CGFloat
let fitsInsideBorder: Bool

init(color: BPKColor, cornerRadius: BPKCornerRadius, lineWidth: CGFloat = 1.0) {
init(color: BPKColor, cornerRadius: BPKCornerRadius, lineWidth: CGFloat = 1.0, fitsInsideBorder: Bool) {
self.color = color
self.cornerRadius = cornerRadius
self.lineWidth = lineWidth
self.fitsInsideBorder = fitsInsideBorder
}

func body(content: Content) -> some View {
return content
.overlay(
RoundedRectangle(cornerRadius: cornerRadius)
.stroke(Color(color), lineWidth: lineWidth)
Group {
if fitsInsideBorder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we need this check, lets always do this!

RoundedRectangle(cornerRadius: cornerRadius)
.strokeBorder(Color(color), lineWidth: lineWidth)
} else {
RoundedRectangle(cornerRadius: cornerRadius)
.stroke(Color(color), lineWidth: lineWidth)
}
}
)
}
}

extension View {
@ViewBuilder
func outline(_ color: BPKColor?, cornerRadius: BPKCornerRadius, lineWidth: CGFloat = 1.0) -> some View {
func outline(
_ color: BPKColor?,
cornerRadius: BPKCornerRadius,
lineWidth: CGFloat = 1.0,
fitsInsideBorder: Bool = false
) -> some View {
if let color = color {
ModifiedContent(
content: self,
modifier: Outline(color: color, cornerRadius: cornerRadius, lineWidth: lineWidth)
let outline = Outline(
color: color,
cornerRadius: cornerRadius,
lineWidth: lineWidth,
fitsInsideBorder: fitsInsideBorder
)
self.modifier(outline)
} else {
self
}
Expand Down