Skip to content

Commit 2bceb1e

Browse files
committed
More SwiftUI sample app improvements
1 parent 02d796b commit 2bceb1e

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

Samples/SimpleAppIntegration/SimpleAppIntegration.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
{
22
"pins" : [
3-
{
4-
"identity" : "mobile-buy-sdk-ios",
5-
"kind" : "remoteSourceControl",
6-
"location" : "https://github.com/Shopify/mobile-buy-sdk-ios",
7-
"state" : {
8-
"revision" : "e6e85dcf8f9eb95baaa8336ad3d7967ea8c36ade",
9-
"version" : "11.3.0"
10-
}
11-
},
123
{
134
"identity" : "swiftlintplugin",
145
"kind" : "remoteSourceControl",

Samples/SwiftUIExample/SwiftUIExample/App.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct SwiftUIExampleApp: App {
2929
init() {
3030
ShopifyCheckoutSheetKit.configure {
3131
$0.preloading.enabled = true
32+
$0.logLevel = .all
3233
}
3334
}
3435

@@ -55,7 +56,7 @@ struct RootTabView: View {
5556
CartView(cartManager: cartManager, checkoutURL: $checkoutURL, isShowingCheckout: $isShowingCheckout)
5657
.navigationTitle("Cart")
5758
.navigationBarTitleDisplayMode(.inline)
58-
.padding(20)
59+
.padding(10)
5960
.toolbar {
6061
if cartManager.cart?.lines != nil {
6162
ToolbarItem(placement: .navigationBarTrailing) {

Samples/SwiftUIExample/SwiftUIExample/CartView.swift

+8-2
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,12 @@ struct CartLines: View {
150150
HStack {
151151
if let imageUrl = variant?.product.featuredImage?.url {
152152
AsyncImage(url: imageUrl) { image in
153-
image.image?.resizable().aspectRatio(contentMode: .fit)
153+
image.image?
154+
.resizable()
155+
.aspectRatio(contentMode: .fill)
156+
.frame(width: 80, height: 105)
157+
.clipped()
154158
}
155-
.frame(width: 60, height: 120)
156159
}
157160

158161
VStack(alignment: .leading, spacing: 8
@@ -170,6 +173,8 @@ struct CartLines: View {
170173
if let price = variant?.price.formattedString() {
171174
HStack(spacing: 80) {
172175
Text("\(price)")
176+
.lineLimit(1)
177+
.minimumScaleFactor(0.5)
173178
.foregroundColor(.gray)
174179

175180
HStack(spacing: 20) {
@@ -262,5 +267,6 @@ struct CartViewPreviewContent: View {
262267

263268
var body: some View {
264269
CartView(cartManager: CartManager.shared, checkoutURL: $checkoutURL, isShowingCheckout: $isShowingCheckout)
270+
.padding(10)
265271
}
266272
}

Samples/SwiftUIExample/SwiftUIExample/CatalogView.swift

+8-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ struct CatalogView: View {
4545
var body: some View {
4646
NavigationView {
4747
VStack {
48-
if let product = product, let price = product.variants.nodes.first?.price.formattedString() {
48+
if
49+
let product = product,
50+
let first = product.variants.nodes.first,
51+
let price = first.price.formattedString() {
4952
VStack {
5053
VStack(alignment: .leading) {
5154
AsyncImage(url: product.featuredImage?.url) { image in
@@ -81,6 +84,7 @@ struct CatalogView: View {
8184
Text(product.description)
8285
.padding(2)
8386
.bold()
87+
.lineLimit(3)
8488
.foregroundColor(.gray)
8589
}.padding(.horizontal, 15)
8690

@@ -103,15 +107,16 @@ struct CatalogView: View {
103107
.foregroundColor(.white)
104108
.cornerRadius(10)
105109
} else {
106-
Text("Add to cart - \(price)")
110+
Text(product.availableForSale ? (first.price.amount == 0 ? "Add to cart - Free" : "Add to cart - \(price)") : "Out of stock")
107111
.font(.headline)
108112
.padding()
109113
.frame(maxWidth: 400)
110-
.background(Color.blue)
114+
.background(product.availableForSale ? Color.blue : Color.gray)
111115
.foregroundColor(.white)
112116
.cornerRadius(10)
113117
}
114118
})
119+
.disabled(!product.availableForSale)
115120
.accessibilityIdentifier("addToCartButton")
116121
.sheet(isPresented: $isShowingCart) {
117122
NavigationView {

Samples/SwiftUIExample/SwiftUIExample/ProductViewModel.swift

+8-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,11 @@ extension Storefront.ProductQuery {
179179
.title()
180180
.description()
181181
.vendor()
182+
.availableForSale()
182183
.featuredImage { $0
183-
.url()
184+
.url(
185+
transform: Storefront.ImageTransformInput(maxWidth: 932)
186+
)
184187
}
185188
.variants(first: 1) { $0
186189
.nodes { $0
@@ -216,8 +219,11 @@ extension Storefront.CartQuery {
216219
.product { $0
217220
.title()
218221
.vendor()
222+
.availableForSale()
219223
.featuredImage { $0
220-
.url()
224+
.url(
225+
transform: Storefront.ImageTransformInput(maxWidth: 120)
226+
)
221227
}
222228
}
223229
}

0 commit comments

Comments
 (0)