-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
3847256
commit 3b35edb
Showing
5 changed files
with
91 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// OtpTextInputView.swift | ||
// BaseStyle | ||
// | ||
// Created by Amisha Italiya on 20/06/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct OtpTextInputView: View { | ||
|
||
private let OTP_TOTAL_CHARACTERS = 6 | ||
|
||
@Binding var text: String | ||
|
||
var isFocused: FocusState<Bool>.Binding | ||
var keyboardType: UIKeyboardType | ||
|
||
var onOtpVerify: (() -> Void)? | ||
|
||
public init(text: Binding<String>, isFocused: FocusState<Bool>.Binding, | ||
keyboardType: UIKeyboardType = .numberPad, onOtpVerify: ( () -> Void)? = nil) { | ||
self._text = text | ||
self.isFocused = isFocused | ||
self.keyboardType = keyboardType | ||
self.onOtpVerify = onOtpVerify | ||
} | ||
|
||
public var body: some View { | ||
VStack(alignment: .center, spacing: 10) { | ||
TextField("", text: $text) | ||
.kerning(16) | ||
.tint(primaryColor) | ||
.font(.subTitle1(34)) | ||
.foregroundColor(primaryText) | ||
.multilineTextAlignment(.center) | ||
.keyboardType(keyboardType) | ||
.textContentType(.oneTimeCode) | ||
.disableAutocorrection(true) | ||
.focused(isFocused) | ||
.onChange(of: text) { newValue in | ||
if newValue.count == OTP_TOTAL_CHARACTERS { | ||
onOtpVerify?() | ||
UIApplication.shared.endEditing() | ||
} | ||
} | ||
|
||
Divider() | ||
.background(outlineColor) | ||
.padding(.horizontal, 60) | ||
} | ||
} | ||
} |
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