-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathWelcomeView.swift
80 lines (73 loc) · 1.88 KB
/
WelcomeView.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
71
72
73
74
75
76
77
78
79
80
//
// WelcomeView.swift
// SuperwallSwiftUIExample
//
// Created by Yusuf Tör on 14/03/2022.
//
import SwiftUI
import SuperwallKit
struct WelcomeView: View {
@Binding var isLoggedIn: Bool
@State private var name: String = ""
var body: some View {
NavigationStack {
ZStack {
VStack(alignment: .center, spacing: 60) {
logo()
Spacer()
Text("Welcome! Enter your name to get started. Your name will be added to the Superwall user attributes, which can then be accessed and displayed within your paywall.")
.lineSpacing(5)
.foregroundColor(.white)
.multilineTextAlignment(.center)
inputField()
Spacer()
logInButton()
}
.padding()
.frame(maxHeight: .infinity)
.background(Color.neutral)
}
.navigationDestination(isPresented: $isLoggedIn) {
HomeView(isLoggedIn: $isLoggedIn)
}
.navigationBarHidden(true)
.navigationTitle("")
}
.accentColor(.primaryTeal)
}
private func logo() -> some View {
VStack(spacing: 0) {
Image("logo")
.resizable()
.scaledToFit()
.frame(width: 200)
Text("Example app")
.foregroundColor(.white)
.italic()
}
}
private func inputField() -> some View {
TextField(
"Enter your name",
text: $name
)
.textContentType(.name)
.textInputAutocapitalization(.never)
.padding()
.background(Color.white)
.clipShape(Capsule())
}
@ViewBuilder
private func logInButton() -> some View {
BrandedButton(title: "Log In") {
Superwall.shared.identify(userId: "abc")
Superwall.shared.setUserAttributes(["firstName": name])
isLoggedIn = true
}
}
}
struct WelcomeView_Previews: PreviewProvider {
static var previews: some View {
WelcomeView(isLoggedIn: .constant(false))
}
}