70 lines
2.5 KiB
Swift
70 lines
2.5 KiB
Swift
//
|
|
// PurchaseButtonView.swift
|
|
// Feels
|
|
//
|
|
// Created by Trey Tartt on 7/7/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
import StoreKit
|
|
|
|
struct IAPWarningView: View {
|
|
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
|
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
|
|
@AppStorage(UserDefaultsStore.Keys.firstLaunchDate.rawValue, store: GroupUserDefaults.groupDefaults) private var firstLaunchDate = Date()
|
|
|
|
var iapManager: IAPManager
|
|
|
|
private let height: Float
|
|
private let showManageSubClosure: (() -> Void)?
|
|
|
|
@State private var showSettings = false
|
|
|
|
public init(height: Float, iapManager: IAPManager, showManageSubClosure: (() -> Void)? = nil, showCountdownTimer: Bool = false) {
|
|
self.height = height
|
|
self.showManageSubClosure = showManageSubClosure
|
|
self.iapManager = iapManager
|
|
}
|
|
|
|
var body: some View {
|
|
VStack {
|
|
if let date = Calendar.current.date(byAdding: .day, value: 30, to: firstLaunchDate) {
|
|
Text(String(localized: "iap_warning_view_title"))
|
|
.font(.body)
|
|
.frame(minWidth: 0, maxWidth: .infinity)
|
|
.background(theme.currentTheme.secondaryBGColor)
|
|
|
|
Text(date, style: .relative)
|
|
.font(.body)
|
|
.bold()
|
|
.foregroundColor(textColor)
|
|
|
|
Button(action: {
|
|
showSettings.toggle()
|
|
}, label: {
|
|
Text(String(localized: "iap_warning_view_buy_button"))
|
|
.foregroundColor(.white)
|
|
.bold()
|
|
.frame(maxWidth: .infinity)
|
|
.contentShape(Rectangle())
|
|
})
|
|
.frame(maxWidth: .infinity)
|
|
.frame(height: 50)
|
|
.background(RoundedRectangle(cornerRadius: 10).fill(DefaultMoodTint.color(forMood: .great)))
|
|
}
|
|
}
|
|
.frame(minWidth: 0, maxWidth: .infinity)
|
|
.padding()
|
|
.background(theme.currentTheme.secondaryBGColor)
|
|
.sheet(isPresented: $showSettings) {
|
|
SettingsView()
|
|
}
|
|
}
|
|
}
|
|
|
|
struct IAPWarningView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
IAPWarningView(height: 175, iapManager: IAPManager())
|
|
}
|
|
}
|