Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ns-vasilev committed May 3, 2024
1 parent 67c98b4 commit c250b29
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Creating a Custom Product Style

Learn how to create a custom style for a product.

## Custom Product Style

The `FlareUI` provides a simple way to customize the appearance of the products. For this, you need to implement an object that conforms to ``IProductStyle`` and pass it to ``SwiftUI/View/productViewStyle(_:)`` or ``SwiftUI/View/productViewStyle(_:)``.

> note: You can use one of the predefined styles that are optimized for various platforms: ``LargeProductStyle`` and ``CompactProductStyle``.
Based on the ``ProductStyleConfiguration/State-swift.enum`` enum, you can define different views to display for various states.

```swift
struct CustomProductStyle: IProductStyle {
func makeBody(configuration: Configuration) -> some View {
switch configuration.state {
case .loading:
// Provide a custom loader view
case let .product(product):
// Provide a custom view that displays the product's info
case let .error(error):
// Provide a view for displaying an error to a user.
}
}
}
```

## Custom Subscription Style

58 changes: 58 additions & 0 deletions Sources/FlareUI/FlareUI.docc/Articles/displaying-products.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Displaying Products

Learn how to display a set of products to a user.

## Overview

The `FlareUI` provides an easy way to display different kinds of products with a single line of code. To display a set of products to the user, just pass a collection of identifiers to the ``ProductsView``.

```swift
ProductsView(ids: ["com.company.product_id_1", "com.company.product_id_2"])
```

Once `ProductsView` fetches these products from the App Store, it will display them to the user. If the products can't be fetched for any reason, the `ProductsView` shows a message to the user that the App Store is not available.

> important: By default, all Flare views use cached data if available; otherwise, they fetch the data. If you want to change this behavior, please read more about Flare configuration [here](link).
## UIKit

The `FlareUI` package provides wrappers for the UIKit views. It can be easily integrated into UIKit environments using ``ProductsViewController``.

```swift
let productsVC = ProductsViewController(ids: ["com.company.product_id_1", "com.company.product_id_2"])
let nav = UINavigationController(rootViewController: productsVC)
present(nav, animated: true)
```

The `ProductsViewController` is backed by `ProductsView`, and its behavior is the same.

## Customization

The appearance of the displayed products can be customized using ``SwiftUI/View/productViewStyle(_:)``. There are predefined styles for different platforms: ``LargeProductStyle``, ``CompactProductStyle``.

You can also create your own style. For this, please, read [How to Create a Custom Product Style](<doc:creating-custom-product-style>).

## Custom Buttons

If you have restorable products, the `ProductsView` can show a restore button to the customer. For this, you can use ``SwiftUI/View/storeButton(_:types:)-4x8yd`` or ``ProductsViewController/storeButton(_:types:)``.

```swift
// SwiftUI

ProductsView(ids: ["com.company.product_id_1", "com.company.product_id_2"])
.storeButton(.visible, types: .restore)
```

```swift
// UIKit

let productsVC = ProductsViewController(ids: ["com.company.product_id_1", "com.company.product_id_2"])
productsVC.storeButton(.visible, types: [.restore])
```

## Topics

### Articles

- <doc:creating-custom-product-style>
- <doc:handling-transactions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Displaying Subscriptions

Learn how to display a set of subscriptions to a user.
19 changes: 19 additions & 0 deletions Sources/FlareUI/FlareUI.docc/Articles/handling-transactions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Handling Transactions

Learn how to handle transactions.

## Overview

If you have restorable products, the `ProductsView` can show a restore button to the customer. For this, you can use ``SwiftUI/View/onInAppPurchaseCompletion(completion:)`` or ``ProductsViewController/onInAppPurchaseCompletion``.

```swift
ProductsView(ids: ["com.company.product_id_1", "com.company.product_id_2"])
.onInAppPurchaseCompletion { result in
switch result {
case let .success(transaction):
// Handle the transaction
case let .failure(error):
// Handle the error
}
}
```
28 changes: 28 additions & 0 deletions Sources/FlareUI/FlareUI.docc/FlareUI.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,31 @@ Display a customizable in-app purchase store using StoreKit views for UIKit and
## Overview

FlareUI provides UI to help you build a store for your in-app purchases, and provide a way for customers to complete the purchase. The views support localization, so your customers see the product names, descriptions, and prices appropriate to their App Store storefront.

## SwiftUI

The easiest way to display in-app purchases is by using ``SubscriptionsView`` and ``ProductsView``.

```swift
SubscriptionsView(ids: [com.company.subscription_id])
```

## UIKit

To present the in-app purchases from UIKit, use ``SubscriptionsViewController`` or ``ProductsViewController``.

```swift
let subscriptionsVC = SubscriptionsViewController(ids: [com.company.subscription_id])
let nav = UINavigationController(rootViewController: subscriptionsVC)
present(nav, animated: true)
```

## Minimum Requirements

| FlareUI | Date | Swift | Xcode | Platforms |
|---------|------------|-------|---------|-------------------------------------------------------------|
| 3.0 | unreleased | 5.7 | 14.1 | iOS 13.0, macOS 10.15, tvOS 13.0

## License

flare is available under the MIT license. See the LICENSE file for more info.

0 comments on commit c250b29

Please sign in to comment.