Files
purchases-ios/Examples/MagicWeatherSwiftUI/Shared/Sources/Views/WeatherView.swift
T

70 lines
2.1 KiB
Swift
Raw Normal View History

2021-01-29 14:36:54 -05:00
//
// WeatherView.swift
// Magic Weather SwiftUI
//
// Created by Cody Kerns on 1/19/21.
//
import SwiftUI
2021-09-03 14:17:37 -03:00
import RevenueCat
2021-01-29 14:36:54 -05:00
/*
The app's weather tab that displays our pretend weather data.
*/
struct WeatherView: View {
2021-01-29 14:36:54 -05:00
@Binding var paywallPresented: Bool
@ObservedObject var model = WeatherViewModel.shared
@ObservedObject var userModel = UserViewModel.shared
2021-01-29 14:36:54 -05:00
var body: some View {
VStack {
/// - Sample weather details
Text("\(model.currentData.emoji)")
.padding(.top, 32.0)
.font(.system(size: 76))
2021-01-29 15:40:19 -05:00
Text("\(model.currentData.temperature)°\(model.currentData.unit.rawValue.capitalized)")
2021-01-29 14:36:54 -05:00
.multilineTextAlignment(.center)
.font(.custom("ArialRoundedMTBold", size: 96.0))
.padding(.top, 8.0)
/// - Environment button
Button(action: {
}) {
Label("Earth", systemImage: "location.fill")
.foregroundColor(.white)
.font(.headline)
}.padding(.top, 16.0)
/// - we'll change the environment in a future update, disable for now
.allowsHitTesting(false)
Spacer()
/// - The magic button that is disabled behind our paywall
Button("✨ Change the Weather") {
self.performMagic()
2021-01-29 14:36:54 -05:00
}
.foregroundColor(.white)
.font(.headline)
.frame(maxWidth: .infinity, minHeight: 64.0)
}
.padding(.all, 16.0)
.background(Color(model.currentData.weatherColor ?? .systemBackground))
}
private func performMagic() {
2021-01-29 14:36:54 -05:00
/*
We should check if we can magically change the weather (subscription active) and if not, display the paywall.
*/
if self.userModel.subscriptionActive {
self.model.currentData = SampleWeatherData.generateSampleData(for: self.model.currentEnvironment)
} else {
self.paywallPresented.toggle()
2021-01-29 14:36:54 -05:00
}
}
2021-01-29 14:36:54 -05:00
}