Files
interject/interject/Interject!/View/BuyButtonStyle.swift
T
2026-07-11 10:17:49 -05:00

51 lines
1.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
See LICENSE folder for this sample’s licensing information.
Abstract:
The style of the product buttons that display in the store view.
*/
import StoreKit
import SwiftUI
struct BuyButtonStyle: ButtonStyle {
let isPurchased: Bool
init(isPurchased: Bool = false) {
self.isPurchased = isPurchased
}
func makeBody(configuration: Self.Configuration) -> some View {
var bgColor: Color = isPurchased ? Color.green : Color.blue
bgColor = configuration.isPressed ? bgColor.opacity(0.7) : bgColor.opacity(1)
return configuration.label
.frame(width: 100)
.padding(10)
.background(bgColor)
.clipShape(RoundedRectangle(cornerRadius: 20, style: .continuous))
.scaleEffect(configuration.isPressed ? 0.9 : 1.0)
}
}
struct BuyButtonStyle_Previews: PreviewProvider {
static var previews: some View {
Group {
Button(action: {}) {
Text("Buy")
.foregroundColor(.white)
.bold()
}
.buttonStyle(BuyButtonStyle())
.previewDisplayName("Normal")
Button(action: {}) {
Image(systemName: "checkmark")
.foregroundColor(.white)
}
.buttonStyle(BuyButtonStyle(isPurchased: true))
.previewDisplayName("Purchased")
}
}
}