init(id:icon:placeholderIcon:)
Creates a view to load an individual product from the App Store, and merchandise it using its promotional image and a custom placeholder icon.
Declaration
nonisolated init(id productID: Product.ID, @ViewBuilder icon: @escaping (ProductIconPhase) -> Icon, @ViewBuilder placeholderIcon: () -> PlaceholderIcon)Parameters
- productID:
The product identifier to load from the App Store.
- icon:
A closure that receives a Producticonphase as an input, which indicates the state of the loading operation of the product’s promotional image, and returns the view to display for the specified phase.
- placeholderIcon:
A closure that returns an icon to display until the system finishes loading the product from the App Store.
Discussion
The product view shows the placeholderIcon until the system finishes loading the product. After the product finishes loading, the view asynchronously loads and displays the product’s promotional image. Use the ProductIconPhase to monitor the current loading state of the product’s promotional image.
If the product is unavailable, the view displays the placeholderIcon as a fallback.
The ProductIconPhase value indicates whether the promotional image is loading, unavailable, or whether it succeeded or failed to load. Use the phase to decide what to draw. While the image’s loading operation is in the ProductIconPhase.loading phase, consider displaying the same view that you provide in the placeholderIcon closure. For more information, see ProductIconPhase.