Skip to content

Commit

Permalink
More SwiftUI sample app improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
markmur committed Oct 16, 2024
1 parent 02d796b commit 2bceb1e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"pins" : [
{
"identity" : "mobile-buy-sdk-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Shopify/mobile-buy-sdk-ios",
"state" : {
"revision" : "e6e85dcf8f9eb95baaa8336ad3d7967ea8c36ade",
"version" : "11.3.0"
}
},
{
"identity" : "swiftlintplugin",
"kind" : "remoteSourceControl",
Expand Down
3 changes: 2 additions & 1 deletion Samples/SwiftUIExample/SwiftUIExample/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct SwiftUIExampleApp: App {
init() {
ShopifyCheckoutSheetKit.configure {
$0.preloading.enabled = true
$0.logLevel = .all
}
}

Expand All @@ -55,7 +56,7 @@ struct RootTabView: View {
CartView(cartManager: cartManager, checkoutURL: $checkoutURL, isShowingCheckout: $isShowingCheckout)
.navigationTitle("Cart")
.navigationBarTitleDisplayMode(.inline)
.padding(20)
.padding(10)
.toolbar {
if cartManager.cart?.lines != nil {
ToolbarItem(placement: .navigationBarTrailing) {
Expand Down
10 changes: 8 additions & 2 deletions Samples/SwiftUIExample/SwiftUIExample/CartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ struct CartLines: View {
HStack {
if let imageUrl = variant?.product.featuredImage?.url {
AsyncImage(url: imageUrl) { image in
image.image?.resizable().aspectRatio(contentMode: .fit)
image.image?
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 80, height: 105)
.clipped()
}
.frame(width: 60, height: 120)
}

VStack(alignment: .leading, spacing: 8
Expand All @@ -170,6 +173,8 @@ struct CartLines: View {
if let price = variant?.price.formattedString() {
HStack(spacing: 80) {
Text("\(price)")
.lineLimit(1)
.minimumScaleFactor(0.5)
.foregroundColor(.gray)

HStack(spacing: 20) {
Expand Down Expand Up @@ -262,5 +267,6 @@ struct CartViewPreviewContent: View {

var body: some View {
CartView(cartManager: CartManager.shared, checkoutURL: $checkoutURL, isShowingCheckout: $isShowingCheckout)
.padding(10)
}
}
11 changes: 8 additions & 3 deletions Samples/SwiftUIExample/SwiftUIExample/CatalogView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ struct CatalogView: View {
var body: some View {
NavigationView {
VStack {
if let product = product, let price = product.variants.nodes.first?.price.formattedString() {
if
let product = product,
let first = product.variants.nodes.first,
let price = first.price.formattedString() {
VStack {
VStack(alignment: .leading) {
AsyncImage(url: product.featuredImage?.url) { image in
Expand Down Expand Up @@ -81,6 +84,7 @@ struct CatalogView: View {
Text(product.description)
.padding(2)
.bold()
.lineLimit(3)
.foregroundColor(.gray)
}.padding(.horizontal, 15)

Expand All @@ -103,15 +107,16 @@ struct CatalogView: View {
.foregroundColor(.white)
.cornerRadius(10)
} else {
Text("Add to cart - \(price)")
Text(product.availableForSale ? (first.price.amount == 0 ? "Add to cart - Free" : "Add to cart - \(price)") : "Out of stock")
.font(.headline)
.padding()
.frame(maxWidth: 400)
.background(Color.blue)
.background(product.availableForSale ? Color.blue : Color.gray)
.foregroundColor(.white)
.cornerRadius(10)
}
})
.disabled(!product.availableForSale)
.accessibilityIdentifier("addToCartButton")
.sheet(isPresented: $isShowingCart) {
NavigationView {
Expand Down
10 changes: 8 additions & 2 deletions Samples/SwiftUIExample/SwiftUIExample/ProductViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,11 @@ extension Storefront.ProductQuery {
.title()
.description()
.vendor()
.availableForSale()
.featuredImage { $0
.url()
.url(
transform: Storefront.ImageTransformInput(maxWidth: 932)
)
}
.variants(first: 1) { $0
.nodes { $0
Expand Down Expand Up @@ -216,8 +219,11 @@ extension Storefront.CartQuery {
.product { $0
.title()
.vendor()
.availableForSale()
.featuredImage { $0
.url()
.url(
transform: Storefront.ImageTransformInput(maxWidth: 120)
)
}
}
}
Expand Down

0 comments on commit 2bceb1e

Please sign in to comment.