Contents

ProductViewStyle

A type that specifies the appearance and interaction of In-App Purchase products within the view hierarchy.

Declaration

@MainActor @preconcurrency protocol ProductViewStyle

Overview

To configure the in-app purchase product style for a view hierarchy, use the productViewStyle(_:) modifier.

To create a custom style, declare a type that conforms to the ProductViewStyle protocol. Implement the makeBody(configuration:) method to return a view that composes the elements of the configuration that the system provides to your method. The following code example shows how to create a custom product view style:

struct CustomProductViewStyle: ProductViewStyle {
    func makeBody(configuration: Configuration) -> some View {
        switch configuration.state {
        // Add other cases here.
        case .success(let product):
            VStack(alignment: .center) {
                configuration.icon
                Text(product.displayName)
                Button(product.displayPrice) {}
            }
        }
    }
}

ProductView(id: "com.example.product")
    .productViewStyle(CustomProductViewStyle())
    // Add your code here.

Topics

Getting built-in product view styles

Creating custom product views

Supporting types

See Also

Styling product views