2023-07-31 12:02:30 +02:00
|
|
|
//
|
2023-08-24 14:18:04 -07:00
|
|
|
// Copyright RevenueCat Inc. All Rights Reserved.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the MIT License (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
|
//
|
2023-07-31 12:02:30 +02:00
|
|
|
// PackageButtonStyle.swift
|
|
|
|
|
//
|
|
|
|
|
// Created by Nacho Soto on 7/29/23.
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
|
|
/// A `ButtonStyle` suitable to be used for a package selection button.
|
|
|
|
|
/// Features:
|
|
|
|
|
/// - Automatic handling of disabled state
|
|
|
|
|
/// - Replaces itself with a loading indicator if it's the selected package.
|
2023-11-08 07:35:19 -08:00
|
|
|
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
|
2023-07-31 12:02:30 +02:00
|
|
|
struct PackageButtonStyle: ButtonStyle {
|
|
|
|
|
|
2023-10-06 09:29:19 -05:00
|
|
|
var fadeDuringPurchases: Bool = true
|
2023-07-31 12:02:30 +02:00
|
|
|
|
2023-07-31 20:56:08 +02:00
|
|
|
@EnvironmentObject
|
|
|
|
|
private var purchaseHandler: PurchaseHandler
|
2023-07-31 12:02:30 +02:00
|
|
|
|
|
|
|
|
func makeBody(configuration: ButtonStyleConfiguration) -> some View {
|
|
|
|
|
configuration
|
|
|
|
|
.label
|
2023-08-30 18:13:14 -07:00
|
|
|
.contentShape(Rectangle())
|
2023-10-06 09:29:19 -05:00
|
|
|
.opacity(
|
|
|
|
|
self.fadeDuringPurchases && self.purchaseHandler.actionInProgress
|
|
|
|
|
? Constants.purchaseInProgressButtonOpacity
|
|
|
|
|
: 1
|
|
|
|
|
)
|
2023-07-31 12:02:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|