-
Notifications
You must be signed in to change notification settings - Fork 4
/
WeatherView.swift
70 lines (57 loc) · 2.08 KB
/
WeatherView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// WeatherView.swift
// Magic Weather SwiftUI
//
// Created by Cody Kerns on 1/19/21.
//
import SwiftUI
import RevenueCat
/*
The app's weather tab that displays our pretend weather data.
*/
struct WeatherView: View {
@Binding var paywallPresented: Bool
@ObservedObject var model = WeatherViewModel.shared
@ObservedObject var userModel = UserViewModel.shared
var body: some View {
VStack {
/// - Sample weather details
Text("\(model.currentData.emoji)")
.padding(.top, 32.0)
.font(.system(size: 76))
Text("\(model.currentData.temperature)°\(model.currentData.unit.rawValue.capitalized)")
.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()
}
.foregroundColor(.white)
.font(.headline)
.frame(maxWidth: .infinity, minHeight: 64.0)
}
.padding(.all, 16.0)
.background(Color(model.currentData.weatherColor ?? .systemBackground))
}
private func performMagic() {
/*
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()
}
}
}