Skip to content

Commit

Permalink
[PAN-3453][iOS][Backpack] Bpk price component updating for price caro…
Browse files Browse the repository at this point in the history
…usel (#2107)

* [PAN-3452][iOS][Backpack] Bpk icon for redirect contributing

* adjust spacing

* adjust extra space under different condition

* update snapshot tests

* record snapshots

* Updated snapshots

* retry

* retry

* update icon size setting

* record snapshots

* Updated snapshots

* retry

* add icon type

* record snapshots

* Updated snapshots

* retry

---------

Co-authored-by: Evelyn Xiang <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent 678e7c8 commit 83d4be5
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions Backpack-SwiftUI/Price/Classes/BPKPrice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public struct BPKPrice: View {
private let leadingText: String?
private let previousPrice: String?
private let trailingText: String?
private let icon: (BPKIcon, String)?
private let alignment: Alignment
private let size: Size

Expand All @@ -40,13 +41,15 @@ public struct BPKPrice: View {
leadingText: String? = nil,
previousPrice: String? = nil,
trailingText: String? = nil,
icon: (BPKIcon, String)? = nil,
alignment: Alignment = .leading,
size: Size
) {
self.price = price
self.leadingText = leadingText
self.previousPrice = previousPrice
self.trailingText = trailingText
self.icon = icon
self.alignment = alignment
self.size = size
}
Expand Down Expand Up @@ -78,7 +81,7 @@ public struct BPKPrice: View {
priceLabel
}
case .trailing:
VStack(alignment: .trailing) {
VStack(alignment: .trailing, spacing: 0) {
priceLabel
}
}
Expand All @@ -101,13 +104,33 @@ public struct BPKPrice: View {

@ViewBuilder
private var priceLabel: some View {
BPKText(price, style: priceFontStyle)
switch alignment {
case .leading, .row:
BPKText(price, style: priceFontStyle)
if let icon {
redirectingIcon(icon: icon)
.offset(y: 2)
}
case .trailing:
HStack(spacing: .sm) {
BPKText(price, style: priceFontStyle)
if let icon {
redirectingIcon(icon: icon)
}
}
}
if let trailingText = trailingText {
BPKText(trailingText, style: accessoryFontStyle)
.foregroundColor(.textSecondaryColor)
}
}

private func redirectingIcon(icon: (BPKIcon, String)) -> some View {
let (newIcon, accessibilityLabel) = icon
return BPKIconView(newIcon, size: .small, accessibilityLabel: accessibilityLabel)
.accessibilityAddTraits(.isButton)
}

private var accessoryFontStyle: BPKFontStyle {
switch size {
case .large:
Expand Down Expand Up @@ -154,8 +177,9 @@ struct BPKPrice_Previews: PreviewProvider {
leadingText: "App only deal",
previousPrice: "£2030",
trailingText: "per day",
icon: (.newWindow, ""),
alignment: .leading,
size: .large
size: .extraSmall
)
}
}
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.

0 comments on commit 83d4be5

Please sign in to comment.