Configured and applied SwiftFormat

This commit is contained in:
Stefan Ceriu
2022-09-27 10:17:22 +03:00
committed by Stefan Ceriu
parent ff2e6ddfa7
commit 43c28d23b7
663 changed files with 2329 additions and 2840 deletions
@@ -19,18 +19,17 @@ import SwiftUI
struct UIKitTextInputConfiguration {
var keyboardType: UIKeyboardType = .default
var returnKeyType: UIReturnKeyType = .default
var isSecureTextEntry: Bool = false
var isSecureTextEntry = false
var autocapitalizationType: UITextAutocapitalizationType = .sentences
var autocorrectionType: UITextAutocorrectionType = .default
}
struct ThemableTextField: UIViewRepresentable {
// MARK: Properties
@State var placeholder: String?
@Binding var text: String
@State var configuration: UIKitTextInputConfiguration = UIKitTextInputConfiguration()
@State var configuration = UIKitTextInputConfiguration()
@Binding var isSecureTextVisible: Bool
var onEditingChanged: ((_ edit: Bool) -> Void)?
var onCommit: (() -> Void)?
@@ -39,7 +38,7 @@ struct ThemableTextField: UIViewRepresentable {
@Environment(\.theme) private var theme: ThemeSwiftUI
private let textField: UITextField = UITextField()
private let textField = UITextField()
private let internalParams = InternalParams()
// MARK: Setup
@@ -50,10 +49,10 @@ struct ThemableTextField: UIViewRepresentable {
isSecureTextVisible: Binding<Bool> = .constant(false),
onEditingChanged: ((_ edit: Bool) -> Void)? = nil,
onCommit: (() -> Void)? = nil) {
self._text = text
self._placeholder = State(initialValue: placeholder)
self._configuration = State(initialValue: configuration)
self._isSecureTextVisible = isSecureTextVisible
_text = text
_placeholder = State(initialValue: placeholder)
_configuration = State(initialValue: configuration)
_isSecureTextVisible = isSecureTextVisible
self.onEditingChanged = onEditingChanged
self.onCommit = onCommit
@@ -84,8 +83,8 @@ struct ThemableTextField: UIViewRepresentable {
uiView.textColor = UIColor(theme.colors.primaryContent)
uiView.tintColor = UIColor(theme.colors.accent)
if uiView.text != self.text {
uiView.text = self.text
if uiView.text != text {
uiView.text = text
}
uiView.placeholder = placeholder
@@ -103,17 +102,16 @@ struct ThemableTextField: UIViewRepresentable {
// MARK: - Private
private func replaceText(with newText: String) {
self.text = newText
text = newText
}
// MARK: - Coordinator
func makeCoordinator() -> Coordinator {
return Coordinator(self)
Coordinator(self)
}
class Coordinator: NSObject, UITextFieldDelegate {
var parent: ThemableTextField
init(_ parent: ThemableTextField) {
@@ -146,14 +144,13 @@ struct ThemableTextField: UIViewRepresentable {
private class InternalParams {
var isFirstResponder = false
}
}
// MARK: - modifiers
extension ThemableTextField {
func makeFirstResponder() -> ThemableTextField {
return makeFirstResponder(true)
makeFirstResponder(true)
}
func makeFirstResponder(_ isFirstResponder: Bool) -> ThemableTextField {
@@ -167,7 +164,7 @@ extension ThemableTextField {
/// - alignment: The vertical alignment of the button in the text field. Default to `center`
@ViewBuilder
func addButton(_ show: Bool, alignment: VerticalAlignment = .center) -> some View {
if show && configuration.isSecureTextEntry {
if show, configuration.isSecureTextEntry {
modifier(PasswordButtonModifier(text: text,
isSecureTextVisible: $isSecureTextVisible,
alignment: alignment))