-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
parentProduct: POSParentProduct
case to POSItem
enum, parse p…
…roducts based on product type in item service, and show new `ParentProductCardView` for parent products.
- Loading branch information
Showing
7 changed files
with
133 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
WooCommerce/Classes/POS/Presentation/ParentProductCardView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import SwiftUI | ||
import struct Yosemite.POSParentProduct | ||
|
||
struct ParentProductCardView: View { | ||
private let parentProduct: POSParentProduct | ||
|
||
@ScaledMetric private var scale: CGFloat = 1.0 | ||
@Environment(\.dynamicTypeSize) var dynamicTypeSize | ||
|
||
init(parentProduct: POSParentProduct) { | ||
self.parentProduct = parentProduct | ||
} | ||
|
||
var body: some View { | ||
HStack(spacing: Constants.cardSpacing) { | ||
if let imageSource = parentProduct.productImageSource { | ||
ProductImageThumbnail(productImageURL: URL(string: imageSource), | ||
productImageSize: Constants.productCardSize * scale, | ||
scale: scale, | ||
foregroundColor: .clear, | ||
cachesOriginalImage: true) | ||
.frame(width: min(Constants.productCardSize * scale, Constants.maximumProductCardSize), | ||
height: Constants.productCardSize * scale) | ||
.clipped() | ||
} else { | ||
Rectangle() | ||
.frame(width: min(Constants.productCardSize * scale, Constants.maximumProductCardSize), | ||
height: Constants.productCardSize * scale) | ||
.foregroundColor(Color(.secondarySystemFill)) | ||
} | ||
|
||
DynamicHStack(spacing: Constants.textSpacing) { | ||
Spacer().renderedIf(dynamicTypeSize.isAccessibilitySize) | ||
Text(parentProduct.name) | ||
.lineLimit(2) | ||
.foregroundStyle(Color.posPrimaryText) | ||
.multilineTextAlignment(.leading) | ||
.font(Constants.itemNameFont) | ||
Spacer().renderedIf(dynamicTypeSize.isAccessibilitySize) | ||
} | ||
.padding(.horizontal, Constants.horizontalTextPadding * (1 / scale)) | ||
.padding(.vertical, Constants.verticalTextPadding * (1 / scale)) | ||
Spacer() | ||
} | ||
.frame(maxWidth: .infinity, idealHeight: Constants.productCardSize * scale) | ||
.background(Color.posSecondaryBackground) | ||
.overlay { | ||
RoundedRectangle(cornerRadius: Constants.productCardCornerRadius) | ||
.stroke(Color.black, lineWidth: Constants.nilOutline) | ||
} | ||
.clipShape(RoundedRectangle(cornerRadius: Constants.productCardCornerRadius)) | ||
.shadow(color: Color.black.opacity(0.08), radius: 4, y: 2) | ||
} | ||
} | ||
|
||
private extension ParentProductCardView { | ||
enum Constants { | ||
static let productCardSize: CGFloat = 112 | ||
static let maximumProductCardSize: CGFloat = Constants.productCardSize * 2 | ||
static let productCardCornerRadius: CGFloat = 8 | ||
// The use of stroke means the shape is rendered as an outline (border) rather than a filled shape, | ||
// since we still have to give it a value, we use 0 so it renders no border but it's shaped as one. | ||
static let nilOutline: CGFloat = 0 | ||
static let cardSpacing: CGFloat = 0 | ||
static let textSpacing: CGFloat = 8 | ||
static let horizontalTextPadding: CGFloat = 32 | ||
static let verticalTextPadding: CGFloat = 8 | ||
static let itemNameFont: POSFontStyle = .posBodyEmphasized | ||
} | ||
} | ||
|
||
#if DEBUG | ||
#Preview { | ||
let parentProduct = POSParentProduct(id: UUID(), name: "Parent product 1", productImageSource: nil, productID: 42, type: .variable) | ||
ParentProductCardView(parentProduct: parentProduct) | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Foundation | ||
|
||
public enum POSParentProductType { | ||
case variable | ||
} | ||
|
||
public struct POSParentProduct: Equatable, Hashable, Identifiable { | ||
public let id: UUID | ||
public let name: String | ||
public let productImageSource: String? | ||
public let productID: Int64 | ||
public let type: POSParentProductType | ||
|
||
public init(id: UUID, name: String, productImageSource: String?, productID: Int64, type: POSParentProductType) { | ||
self.id = id | ||
self.name = name | ||
self.productImageSource = productImageSource | ||
self.productID = productID | ||
self.type = type | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters