wake-ios/wake/View/Components/TextInput.swift
2025-08-14 19:49:54 +08:00

51 lines
1.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
//
enum TextFieldType {
case username
case password
case number
case email
case text
}
struct CustomTextField: View {
// MARK: -
let placeholder: String
let type: TextFieldType
//
@Binding var value: String
// MARK: -
var body: some View {
Group { // 使 Group
if type == .password {
//
SecureField(placeholder, text: $value)
} else {
//
TextField(placeholder, text: $value)
.textInputAutocapitalization(.never) //
.disableAutocorrection(true) //
}
}
.padding()
.background(Color(.systemGray6))
.cornerRadius(8)
.keyboardType(keyboardType(for: type)) //
}
// MARK: -
private func keyboardType(for type: TextFieldType) -> UIKeyboardType {
switch type {
case .number:
return .numberPad
case .email:
return .emailAddress
default:
return .default
}
}
}