Skip to content

Commit

Permalink
Add backgroundColor to configuration (#41)
Browse files Browse the repository at this point in the history
* Add backgroundColor to configuration

* Update README
  • Loading branch information
markmur authored Oct 24, 2023
1 parent bc7de89 commit a680665
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ ShopifyCheckout.configuration.colorScheme = .web
```

#### `spinnerColor`
If the checkout session is not ready and being initialized, a loading spinner is shown and can be customized via `spinnerColor` property:
If the checkout session is not ready and being initialized, a loading spinner is shown and can be customized via the `spinnerColor` property:

```swift
// Use a custom UI color
Expand All @@ -109,6 +109,17 @@ ShopifyCheckout.configuration.spinnerColor = .systemBlue
```
_Note: use preloading to optimize and deliver an instant buyer experience._

#### `backgroundColor`
While the checkout session is being initialized, the background color of the view can be customized via the `backgroundColor` property:

```swift
// Use a custom UI color
ShopifyCheckout.configuration.backgroundColor = UIColor(red: 0.09, green: 0.45, blue: 0.69, alpha: 1.00)

// Use a system color
ShopifyCheckout.configuration.backgroundColor = .systemBackground
```

### 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 waiting 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 @@ -155,6 +155,7 @@ class SettingsViewController: UITableViewController {
let newColorScheme = colorScheme(at: indexPath)
ShopifyCheckout.configuration.colorScheme = newColorScheme
ShopifyCheckout.configuration.spinnerColor = newColorScheme.spinnerColor
ShopifyCheckout.configuration.backgroundColor = newColorScheme.backgroundColor
view?.window?.overrideUserInterfaceStyle = newColorScheme.userInterfaceStyle
tableView.reloadSections(IndexSet(integer: Section.colorScheme.rawValue), with: .automatic)
default:
Expand Down Expand Up @@ -237,11 +238,20 @@ extension Configuration.ColorScheme {
}

var spinnerColor: UIColor {
switch ShopifyCheckout.configuration.colorScheme {
switch self {
case .web:
return UIColor(red: 0.18, green: 0.16, blue: 0.22, alpha: 1.00)
default:
return UIColor(red: 0.09, green: 0.45, blue: 0.69, alpha: 1.00)
}
}

var backgroundColor: UIColor {
switch self {
case .web:
return UIColor(red: 0.94, green: 0.94, blue: 0.91, alpha: 1.00)
default:
return .systemBackground
}
}
}
2 changes: 1 addition & 1 deletion Sources/ShopifyCheckout/CheckoutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CheckoutViewController: UIViewController, UIAdaptivePresentationController
override public func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .systemBackground
view.backgroundColor = ShopifyCheckout.configuration.backgroundColor

view.addSubview(checkoutView)
NSLayoutConstraint.activate([
Expand Down
2 changes: 2 additions & 0 deletions Sources/ShopifyCheckout/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public struct Configuration {

public var spinnerColor: UIColor = UIColor(red: 0.09, green: 0.45, blue: 0.69, alpha: 1.00)

public var backgroundColor: UIColor = .systemBackground

}

extension Configuration {
Expand Down

0 comments on commit a680665

Please sign in to comment.