Skip to content

Commit

Permalink
Expose BPKDividedCard alignment (#1956)
Browse files Browse the repository at this point in the history
* Expose BPKDividedCard alignment

* Update test

* Record snapshots

* Updated snapshots

* Record snapshots

* Record snapshots

* Updated snapshots

* Rerun CI

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
ToniRealp and github-actions[bot] committed May 8, 2024
1 parent d53ff06 commit 0ae3c05
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
27 changes: 19 additions & 8 deletions Backpack-SwiftUI/Card/Classes/BPKDividedCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ public struct BPKDividedCard<PrimaryContent: View, SecondaryContent: View>: View
private let primaryContent: PrimaryContent
private let secondaryContent: SecondaryContent
private var tapAction: () -> Void = {}
private let alignment: HorizontalAlignment

public init(
alignment: HorizontalAlignment = .center,
elevation: BPKCardElevation = .default,
@ViewBuilder primaryContent: () -> PrimaryContent,
@ViewBuilder secondaryContent: () -> SecondaryContent
) {
self.alignment = alignment
self.elevation = elevation
self.primaryContent = primaryContent()
self.secondaryContent = secondaryContent()
}

public var body: some View {
BPKCard(padding: .none, elevation: elevation) {
VStack(spacing: 0) {
VStack(alignment: alignment, spacing: 0) {
primaryContent
Color(BPKColor.lineColor)
.frame(height: 1)
Expand All @@ -47,7 +50,7 @@ public struct BPKDividedCard<PrimaryContent: View, SecondaryContent: View>: View
}
}
}

public func onTapGesture(perform: @escaping () -> Void) -> BPKDividedCard {
var result = self
result.tapAction = perform
Expand All @@ -59,18 +62,18 @@ struct BPKDividedCard_Previews: PreviewProvider {

private static func primaryContent(title: String) -> some View {
let message = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. " +
"Aenean commodo ligula eget dolor. Aenean massa."
"Aenean commodo ligula eget dolor. Aenean massa."
return VStack {
BPKText(title, style: .heading3)
BPKText(message)
.lineLimit(3)
}
}

private static func secondaryContent() -> some View {
BPKText("Lorem ipsum dolor sit amet")
}

// swiftlint:disable closure_body_length
static var previews: some View {
ZStack {
Expand All @@ -83,26 +86,34 @@ struct BPKDividedCard_Previews: PreviewProvider {
} secondaryContent: {
secondaryContent()
}

BPKDividedCard(elevation: .focus) {
primaryContent(title: "Focused")
} secondaryContent: {
secondaryContent()
}

BPKDividedCard(elevation: .none) {
primaryContent(title: "Not Elevated")
} secondaryContent: {
secondaryContent()
}

BPKDividedCard {
primaryContent(title: "Padded")
.padding()
} secondaryContent: {
secondaryContent()
.padding()
}

BPKDividedCard(alignment: .leading) {
primaryContent(title: "Aligned left")
.padding()
} secondaryContent: {
secondaryContent()
.padding()
}
}
.padding()
}
Expand Down
15 changes: 15 additions & 0 deletions Backpack-SwiftUI/Tests/Card/BPKDividedCardTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,19 @@ class BPKDividedCardTests: XCTestCase {
}
)
}

func testDividedCardWithLeadingAlignment() {
assertSnapshot(
ZStack {
Color(BPKColor.canvasContrastColor)
.ignoresSafeArea()
BPKDividedCard(alignment: .leading) {
primaryContent(title: "Aligned Leading")
} secondaryContent: {
secondaryContent()
}
.padding()
}
)
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ struct DividedCardExampleView: View {
secondaryContent()
.padding()
}

BPKDividedCard(alignment: .leading) {
primaryContent(title: "Aligned Left")
.padding()
} secondaryContent: {
secondaryContent()
.padding()
}
}
.padding()
}
Expand Down

0 comments on commit 0ae3c05

Please sign in to comment.