fixing some ui things

This commit is contained in:
talksik
2021-12-18 01:49:58 -08:00
parent 37fabeefbb
commit 07bd9f2196
2 changed files with 91 additions and 77 deletions
@@ -24,6 +24,14 @@ struct PhoneVerificationView: View {
@State var isLoading = false @State var isLoading = false
let formatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
return formatter
}()
@FocusState private var focusedInputField: Bool
// TODO: format the input so that it shows the parentheses and stuff (949)923-0445 // TODO: format the input so that it shows the parentheses and stuff (949)923-0445
var body: some View { var body: some View {
ZStack(alignment: .topLeading) { ZStack(alignment: .topLeading) {
@@ -44,11 +52,11 @@ struct PhoneVerificationView: View {
self.showToast.toggle() self.showToast.toggle()
} }
TextField("(650) 555 - 1234", text: $phoneNumber) TextField("(650) 555 - 1234", text: self.$phoneNumber)
.padding() .padding()
.background(.ultraThinMaterial) .background(.ultraThinMaterial)
.clipShape(Capsule()) .clipShape(Capsule())
.keyboardType(.decimalPad) .keyboardType(.phonePad)
.shadow(color: Color.black.opacity(0.3), radius: 20, x: 0, y: 20) .shadow(color: Color.black.opacity(0.3), radius: 20, x: 0, y: 20)
.font(.subheadline) .font(.subheadline)
.onReceive(Just(self.phoneNumber)) {newValue in .onReceive(Just(self.phoneNumber)) {newValue in
@@ -59,6 +67,7 @@ struct PhoneVerificationView: View {
self.phoneNumber = filtered self.phoneNumber = filtered
} }
} }
.focused(self.$focusedInputField)
Spacer() Spacer()
} }
@@ -69,15 +78,20 @@ struct PhoneVerificationView: View {
Button { Button {
let concatPhoneNumber = "+"+self.ccode+self.phoneNumber let concatPhoneNumber = "+"+self.ccode+self.phoneNumber
//disable focused textfield...important: draw the focus field out first and then the loading screen
self.focusedInputField.toggle()
//show loading screen //show loading screen
self.isLoading.toggle() self.isLoading.toggle()
DispatchQueue.main.async {
print("sending sms and/or redirecting") print("sending sms and/or redirecting")
// TODO: do all of this in view model
// do auth stuff from firebase // do auth stuff from firebase
PhoneAuthProvider.provider() PhoneAuthProvider.provider()
.verifyPhoneNumber(concatPhoneNumber, uiDelegate: nil) { verificationID, error in .verifyPhoneNumber(concatPhoneNumber, uiDelegate: nil) { verificationID, error in
print("firebase auth done, now running my callback")
// got a response...done loading... either error to show or next page // got a response...done loading... either error to show or next page
self.isLoading.toggle() self.isLoading.toggle()
@@ -92,17 +106,11 @@ struct PhoneVerificationView: View {
return return
} }
// TODO: Sign in using the verificationID and the code sent to the user // use this in the next screen to verify with the code provided
// if there is no user with the phone number, then create one
UserDefaults.standard.set(verificationID, forKey: "authVerificationID") UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
// then async send to next page
// TODO: coming back after function end and then having 1 second before hitting this...need to use async and combine and all of that to make sure that the main thread is not affected and it's all smooth
self.navigationStack.push(PhoneVerificationCodeView()) // verify code page self.navigationStack.push(PhoneVerificationCodeView()) // verify code page
} }
}
} label: { } label: {
VStack { VStack {
Text("Send Verification") Text("Send Verification")
@@ -149,8 +157,6 @@ struct PhoneVerificationView: View {
if self.isLoading { if self.isLoading {
SplashView() SplashView()
} }
SplashView()
} }
.alert(self.toastText, isPresented: self.$showToast) { .alert(self.toastText, isPresented: self.$showToast) {
Button("OK", role: ButtonRole.cancel) { } Button("OK", role: ButtonRole.cancel) { }
@@ -179,6 +185,14 @@ struct PhoneVerificationCodeView: View {
@State var isLoading = false @State var isLoading = false
@FocusState private var focusedInputField: Bool
let formatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
return formatter
}()
var body: some View { var body: some View {
ZStack(alignment: .topLeading) { ZStack(alignment: .topLeading) {
Color.clear Color.clear
@@ -189,26 +203,26 @@ struct PhoneVerificationCodeView: View {
.padding() .padding()
.background(.ultraThinMaterial) .background(.ultraThinMaterial)
.clipShape(Capsule()) .clipShape(Capsule())
.keyboardType(.decimalPad)
.shadow(color: Color.black.opacity(0.3), radius: 20, x: 0, y: 20) .shadow(color: Color.black.opacity(0.3), radius: 20, x: 0, y: 20)
.font(.largeTitle) .font(.title)
.multilineTextAlignment(.center) .multilineTextAlignment(.center)
.padding(.vertical) .padding(.vertical)
// .onReceive(Just(self.$verificationCode)) { newValue in .keyboardType(.phonePad)
// let filtered = newValue.filter { "0123456789".contains($0) } .focused(self.$focusedInputField)
//
// if filtered != newValue {
// self.verificationCode = filtered
// }
// }
if self.verificationCode.count == 6 { if self.verificationCode.count == 6 {
Button { Button {
print("started verification process of code") print("started verification process of code")
//disable focused textfield
self.focusedInputField.toggle()
// show loading screen // show loading screen
self.isLoading.toggle() self.isLoading.toggle()
// TODO: do all of this in view model authstore
// get it from the previous screen but from storage // get it from the previous screen but from storage
let verificationID = UserDefaults.standard.string(forKey: "authVerificationID") let verificationID = UserDefaults.standard.string(forKey: "authVerificationID")
@@ -217,8 +231,6 @@ struct PhoneVerificationCodeView: View {
self.showToast.toggle() self.showToast.toggle()
} }
// TESTING: let it do it's thing but don't ruin the ui main thread
DispatchQueue.main.async {
// if we got a value, then continue with verifying their code // if we got a value, then continue with verifying their code
let credential = PhoneAuthProvider.provider().credential( let credential = PhoneAuthProvider.provider().credential(
withVerificationID: verificationID!, withVerificationID: verificationID!,
@@ -254,7 +266,7 @@ struct PhoneVerificationCodeView: View {
// then sending to next page // then sending to next page
self.navigationStack.push(PhoneVerificationCodeView()) // verify code page self.navigationStack.push(PhoneVerificationCodeView()) // verify code page
} }
}
} label: { } label: {
Text("Verify") Text("Verify")
.bold() .bold()
@@ -9,6 +9,8 @@ import Foundation
final class PhoneVerificationViewModel : ObservableObject { final class PhoneVerificationViewModel : ObservableObject {
} }
extension String { extension String {