-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
397 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
ScribbleLab/Core/Auth/View/OTP+2FA/OTP+2FA Config/SLOTP+2FA_ConfigView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// SLOTP+2FA_ConfigView.swift | ||
// ScribbleLab | ||
// | ||
// Created by Nevio Hirani on 14.11.23. | ||
// | ||
|
||
import SwiftUI | ||
import SwiftRUI | ||
import GoogleSignIn | ||
import GoogleSignInSwift | ||
import FirebaseAuth | ||
import FirebaseCore | ||
import AlertToast | ||
import iPhoneNumberField | ||
|
||
struct SLOTP_2FA_ConfigView: View { | ||
@State private var phoneNumber = "" | ||
@Environment(\.dismiss) var dismiss | ||
|
||
var body: some View { | ||
VStack { | ||
Spacer() | ||
|
||
Image(.personIllustartionOrange) | ||
.frame(width: 600, height: 700) | ||
.padding(10) | ||
|
||
Text("Enter your Phone Number") | ||
.font(.title) | ||
.fontWeight(.bold) | ||
|
||
VStack(spacing: 2) { | ||
Text("To set 2FA up you need to give us a valide") | ||
Text("phone number in order to get 2FA Codes or") | ||
Text("to sign in via phone number") | ||
} | ||
.padding(.vertical, 4) | ||
.font(.headline) | ||
.fontWeight(.medium) | ||
|
||
VStack(spacing: 10) { | ||
iPhoneNumberField("+49 0000-0000", text: $phoneNumber) | ||
.flagHidden(false) | ||
.prefixHidden(false) | ||
.flagSelectable(true) | ||
.clearButtonMode(.always) | ||
.maximumDigits(13) | ||
.accentColor(Color.orange) | ||
.padding(.horizontal, 8) | ||
.frame(width: 356, height: 50, alignment: .center) | ||
.background { | ||
RoundedRectangle(cornerRadius: 15) | ||
.strokeBorder(Color(red: 194/255, green: 194/255, blue: 194/255), lineWidth: 0.5) | ||
Color.gray.opacity(0.02) | ||
} | ||
.padding(12) | ||
|
||
Button { | ||
// TODO: Check if the phone number is valide and send request to FirebaseAuth and Firestore | ||
|
||
} label: { | ||
Text("Next") | ||
.modifier(IGButtonModifier()) | ||
} | ||
} | ||
.padding() | ||
|
||
Button { | ||
dismiss() | ||
} label: { | ||
Text("Cancel").bold() | ||
.padding() | ||
.foregroundStyle(.orange) | ||
} | ||
|
||
Spacer() | ||
|
||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
SLOTP_2FA_ConfigView() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// OTPTextFieldView.swift | ||
// ScribbleLab | ||
// | ||
// Created by Nevio Hirani on 14.11.23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct OTPTextFieldView: View { | ||
|
||
let numberOfFields: Int | ||
|
||
@State var enterValue: [String] | ||
@FocusState private var fieldFocus: Int? | ||
@State private var oldValue = "" | ||
|
||
init(numberOfFields: Int) { | ||
self.numberOfFields = numberOfFields | ||
self.enterValue = Array(repeating: "", count: numberOfFields) | ||
} | ||
|
||
var body: some View { | ||
HStack { | ||
ForEach(0 ..< numberOfFields, id: \.self) { index in | ||
TextField("", text: $enterValue[index], onEditingChanged: { editing in | ||
if editing { | ||
oldValue = enterValue[index] | ||
} | ||
}) | ||
.keyboardType(.numberPad) | ||
.frame(width: 48, height: 48) | ||
.background { | ||
RoundedRectangle(cornerRadius: 15) | ||
.strokeBorder(Color(red: 194/255, green: 194/255, blue: 194/255), lineWidth: 0.5) | ||
Color.gray.opacity(0.02) | ||
} | ||
.multilineTextAlignment(.center) | ||
.focused($fieldFocus, equals: index) | ||
.tag(index) | ||
.onChange(of: enterValue[index]) { newValue in | ||
if enterValue[index].count > 1 { | ||
let currentValue = Array(enterValue[index]) | ||
|
||
if currentValue[0] == Character(oldValue) { | ||
enterValue[index] = String(enterValue[index].suffix(1)) | ||
} else { | ||
enterValue[index] = String(enterValue[index].prefix(1)) | ||
} | ||
} | ||
|
||
if !newValue.isEmpty { | ||
if index == numberOfFields - 1 { | ||
fieldFocus = nil | ||
} else { | ||
fieldFocus = (fieldFocus ?? 0) + 1 | ||
} | ||
} else { | ||
fieldFocus = (fieldFocus ?? 0) - 1 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
OTPTextFieldView(numberOfFields: 6) | ||
} |
Oops, something went wrong.