Skip to content

Commit

Permalink
Improvements to SwiftUI
Browse files Browse the repository at this point in the history
  • Loading branch information
markmur committed Mar 6, 2024
1 parent 3d0054e commit fa304da
Show file tree
Hide file tree
Showing 29 changed files with 1,316 additions and 534 deletions.
66 changes: 51 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pod "ShopifyCheckoutSheetKit", "~> 2"

For more information on CocoaPods, please see their [getting started guide](https://guides.cocoapods.org/using/getting-started.html).

### Basic Usage
### Programmatic Usage

Once the SDK has been added as a dependency, you can import the library:

Expand Down Expand Up @@ -85,25 +85,46 @@ class MyViewController: UIViewController {
}
```

Alternatively, with SwiftUI:
### SwiftUI Usage

```swift
import SwiftUI
import ShopifyCheckoutSheetKit

struct ContentView: View {
@State private var isPresented = false
let url: URL
let delegate: CheckoutDelegate?

var body: some View {
Button("Checkout") {
self.isPresented = true
}
.sheet(isPresented: $isPresented) {
CheckoutViewController.Representable(url: url, delegate: delegate)
}
@State var isPresented = false
@State var checkoutURL: URL?

var body: some View {
Button("Checkout") {
isPresented = true
}
.sheet(isPresented: $isPresented) {
if let url = checkoutURL {
CheckoutSheet(url: url)
/// Configuration
.title("Checkout")
.colorScheme(.automatic)
.tintColor(.blue)
.backgroundColor(.white)

/// Lifecycle events
.onCancel {
isPresented = false
}
.onComplete { event in
handleCompletedEvent(event)
}
.onFail { error in
handleError(error)
}
.onPixelEvent { event in
handlePixelEvent(event)
}
.edgesIgnoringSafeArea(.all)
}
}
}
}
```

Expand Down Expand Up @@ -158,8 +179,6 @@ ShopifyCheckoutSheetKit.configuration.backgroundColor = UIColor(red: 0.09, green
ShopifyCheckoutSheetKit.configuration.backgroundColor = .systemBackground
```

### Localization

#### `title`

By default, the Checkout Sheet Kit will look for a `shopify_checkout_sheet_title` key in a `Localizable.xcstrings` file to set the sheet title, otherwise it will fallback to "Checkout" across all locales.
Expand Down Expand Up @@ -197,6 +216,23 @@ Here is an example of a `Localizable.xcstrings` containing translations for 2 lo
}
```

#### SwiftUI Configuration

Similarly, configuration modifiers are available to set the configuration of your checkout when using SwiftUI:

```swift
CheckoutSheet(checkout: checkoutURL)
.title("Checkout")
.colorScheme(.automatic)
.tintColor(.blue)
.backgroundColor(.black)
```

> [!NOTE]
> Note that if the values of your SwiftUI configuration are **variable** and you are using `preload()`,
> you will need to call `preload()` each time your variables change to ensure that the checkout cache
> has been invalidated, for checkout to be loaded with the new configuration.
### Preloading

Initializing a checkout session requires communicating with Shopify servers and, depending on the network weather and the quality of the buyer's connection, can result in undesirable wait time for the buyer. To help optimize and deliver the best experience, the SDK provides a preloading hint that allows app developers to signal and initialize the checkout session in the background and ahead of time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@
repositoryURL = "https://github.com/Shopify/mobile-buy-sdk-ios";
requirement = {
kind = exactVersion;
version = 11.1.0;
version = 11.3.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Shopify/mobile-buy-sdk-ios",
"state" : {
"revision" : "e6e85dcf8f9eb95baaa8336ad3d7967ea8c36ade",
"version" : "11.1.0"
"revision" : "3a6ecdce6b9e8f356078fbdc2b738ac32cd18153",
"version" : "11.3.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Shopify/mobile-buy-sdk-ios",
"state" : {
"revision" : "e6e85dcf8f9eb95baaa8336ad3d7967ea8c36ade",
"version" : "11.1.0"
"revision" : "3a6ecdce6b9e8f356078fbdc2b738ac32cd18153",
"version" : "11.3.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
{
"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",
"location" : "https://github.com/lukepistrol/SwiftLintPlugin",
"state" : {
"revision" : "b1090ecd269dddd96bda0df24ca3f1aa78f33578",
"version" : "0.52.4"
"revision" : "ea6d3ca895b49910f790e98e4b4ca658e0fe490e",
"version" : "0.54.0"
}
}
],
Expand Down
Loading

0 comments on commit fa304da

Please sign in to comment.