add swiftUI code
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// CustomTF.swift
|
||||
// LoginKit
|
||||
//
|
||||
// Created by Balaji on 04/08/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct CustomTF: View {
|
||||
var sfIcon: String
|
||||
var iconTint: Color = .gray
|
||||
var hint: String
|
||||
/// Hides TextField
|
||||
var isPassword: Bool = false
|
||||
var hasDriveLine: Bool = true
|
||||
|
||||
|
||||
@Binding var value: String
|
||||
/// View Properties
|
||||
@State private var showPassword: Bool = false
|
||||
/// When Switching Between Hide/Reveal Password Field, The Keyboard is Closing, to avoid that using the FocusState
|
||||
@FocusState private var passwordState: HideState?
|
||||
|
||||
enum HideState {
|
||||
case hide
|
||||
case reveal
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .top, spacing: 8, content: {
|
||||
Image(systemName: sfIcon)
|
||||
.foregroundStyle(iconTint)
|
||||
/// Since I Need Same Width to Align TextFields Equally
|
||||
.frame(width: 30)
|
||||
/// Slightly Bringing Down
|
||||
.offset(y: 2)
|
||||
|
||||
VStack(alignment: .leading, spacing: 8, content: {
|
||||
if isPassword {
|
||||
Group {
|
||||
/// Revealing Password when users wants to show Password
|
||||
if showPassword {
|
||||
TextField(hint, text: $value)
|
||||
.focused($passwordState, equals: .reveal)
|
||||
} else {
|
||||
SecureField(hint, text: $value)
|
||||
.focused($passwordState, equals: .hide)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
TextField(hint, text: $value)
|
||||
}
|
||||
|
||||
if hasDriveLine {
|
||||
Divider()
|
||||
}
|
||||
|
||||
})
|
||||
.overlay(alignment: .trailing) {
|
||||
/// Password Reveal Button
|
||||
if isPassword {
|
||||
Button(action: {
|
||||
withAnimation {
|
||||
showPassword.toggle()
|
||||
}
|
||||
passwordState = showPassword ? .reveal : .hide
|
||||
}, label: {
|
||||
Image(systemName: showPassword ? "eye.slash" : "eye")
|
||||
.foregroundStyle(.gray)
|
||||
.padding(10)
|
||||
.contentShape(.rect)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user