Contents

SubscriptionStoreControlStyle

A type that specifies the appearance and interaction of controls in the subscription store view instances within the view hierarchy.

Declaration

@MainActor @preconcurrency protocol SubscriptionStoreControlStyle

Overview

Use the subscriptionStoreControlStyle(_:) view modifier to configure the subscription store control style for a view hierarchy.

SubscriptionStoreView(groupID: "SAMPLE")
    .subscriptionStoreControlStyle(.prominentPicker)

You can also configure the control placement using the subscriptionStoreControlStyle(_:placement:) view modifier.

Create custom styles

To create a custom style, declare a type that conforms to the SubscriptionStoreControlStyle protocol and implement the required makeBody(configuration:) method. For example, you can define a style that adds price comparison captions to buttons.

struct PriceComparisonButtonsSubscriptionStoreControlStyle: SubscriptionStoreControlStyle {

    func makeBody(configuration: Configuration) -> some View {
        // Return a view displaying a captioned button for each option.
    }
}

Inside the method, use the configuration parameter, which is a SubscriptionStoreControlStyleConfiguration value, to get the properties of the control, such as the subscriptions to merchandise. For examples that show constructing a view from the configuration value, see makeBody(configuration:).

The subscription store control style protocol has a Placement associated type, which represents the placements that the style supports. To optionally restrict the placements your custom style supports, explicitly declare a type alias named Placement. For more information about restricting placements, see SubscriptionStoreControlPlacement. If you don’t declare the type alias, your custom style automatically uses the AutomaticSubscriptionStoreControlPlacement as its Placement associated type.

The following code example declares a Placement type alias:

struct PriceComparisonButtonsSubscriptionStoreControlStyle: SubscriptionStoreControlStyle {

    // Support the same placements as the standard buttons style.
    typealias Placement = ButtonsSubscriptionStoreControlStyle.Placement

    func makeBody(configuration: Configuration) -> some View {
        // Return a view displaying a captioned button for each option.
    }
}

To provide easy access to the new style, declare a corresponding static variable in an extension to SubscriptionStoreControlStyle.

extension SubscriptionStoreControlStyle where Self == 
PriceComparisonButtonsSubscriptionStoreControlStyle {
    static var priceComparisonButtons: Self { Self() }
}

Then, use your custom style as follows:

SubscriptionStoreView(groupID: "SAMPLE")
    .subscriptionStoreControlStyle(.priceComparisonButtons)

Topics

Getting built-in subscription store control styles

Creating custom subscription store control styles

Supporting types

See Also

Styling subscription store controls