diff --git a/core/Sources/Components/TextField/View/SwiftUI/TextFieldView.swift b/core/Sources/Components/TextField/View/SwiftUI/TextFieldView.swift index a76d33e71..610c8b576 100644 --- a/core/Sources/Components/TextField/View/SwiftUI/TextFieldView.swift +++ b/core/Sources/Components/TextField/View/SwiftUI/TextFieldView.swift @@ -97,12 +97,14 @@ public struct TextFieldView: View { TextFieldViewInternal( titleKey: self.titleKey, text: self.text, - viewModel: self.viewModel - .enabled(self.isEnabled) - .focused(self.isFocused), + viewModel: self.viewModel, type: self.type, leftView: self.leftView, rightView: self.rightView) + .update( + isEnabled: self.isEnabled, + isFocused: self.isFocused + ) .focused($isFocused) } diff --git a/core/Sources/Components/TextField/View/SwiftUI/TextFieldViewInternal.swift b/core/Sources/Components/TextField/View/SwiftUI/TextFieldViewInternal.swift index 650fa49af..66aef2fff 100644 --- a/core/Sources/Components/TextField/View/SwiftUI/TextFieldViewInternal.swift +++ b/core/Sources/Components/TextField/View/SwiftUI/TextFieldViewInternal.swift @@ -76,4 +76,12 @@ struct TextFieldViewInternal: View { .foregroundStyle(self.viewModel.textColor.color) .accessibilityIdentifier(TextFieldAccessibilityIdentifier.view) } + + func update(isEnabled: Bool, isFocused: Bool) -> some View { + DispatchQueue.main.async { + self.viewModel.isEnabled = isEnabled + self.viewModel.isFocused = isFocused + } + return self + } } diff --git a/core/Sources/Components/TextField/ViewModel/TextFieldViewModel.swift b/core/Sources/Components/TextField/ViewModel/TextFieldViewModel.swift index 6ac305aa4..7d48a6207 100644 --- a/core/Sources/Components/TextField/ViewModel/TextFieldViewModel.swift +++ b/core/Sources/Components/TextField/ViewModel/TextFieldViewModel.swift @@ -10,7 +10,7 @@ import UIKit import SwiftUI import Combine -class TextFieldViewModel: ObservableObject, Updateable { +class TextFieldViewModel: ObservableObject { // Colors @Published private(set) var textColor: any ColorToken @@ -167,14 +167,4 @@ class TextFieldViewModel: ObservableObject, Updateable { private func setFont() { self.font = self.theme.typography.body1 } - - func enabled(_ isEnabled: Bool) -> Self { - self.isEnabled = isEnabled - return self - } - - func focused(_ isFocused: Bool) -> Self { - self.isFocused = isFocused - return self - } } diff --git a/core/Sources/Components/TextField/ViewModel/TextFieldViewModelTests.swift b/core/Sources/Components/TextField/ViewModel/TextFieldViewModelTests.swift index 2cb7e96d1..bee749261 100644 --- a/core/Sources/Components/TextField/ViewModel/TextFieldViewModelTests.swift +++ b/core/Sources/Components/TextField/ViewModel/TextFieldViewModelTests.swift @@ -619,64 +619,6 @@ final class TextFieldViewModelTests: XCTestCase { XCTAssertFalse(self.publishers.font.sinkCalled, "$font should not have been called") } - // MARK: - Enabled() - func test_enabled_false() { - // GIVEN - Inits from setUp() - self.resetUseCases() // Removes execute from init - self.publishers.reset() // Removes publishes from init - - // WHEN - let viewModel = self.viewModel.enabled(false) - - // THEN - XCTAssertIdentical(viewModel, self.viewModel, "Wrong returned viewModel") - XCTAssertFalse(viewModel.isEnabled, "isEnabled should be false") - } - - - func test_enabled_true() { - // GIVEN - Inits from setUp() - self.viewModel.isEnabled = false - self.resetUseCases() // Removes execute from init - self.publishers.reset() // Removes publishes from init - - // WHEN - let viewModel = self.viewModel.enabled(true) - - // THEN - XCTAssertIdentical(viewModel, self.viewModel, "Wrong returned viewModel") - XCTAssertTrue(viewModel.isEnabled, "isEnabled should be true") - } - - // MARK: - Focused() - func test_focused_true() { - // GIVEN - Inits from setUp() - self.resetUseCases() // Removes execute from init - self.publishers.reset() // Removes publishes from init - - // WHEN - let viewModel = self.viewModel.focused(true) - - // THEN - XCTAssertIdentical(viewModel, self.viewModel, "Wrong returned viewModel") - XCTAssertTrue(viewModel.isFocused, "isFocused should be true") - } - - - func test_focused_false() { - // GIVEN - Inits from setUp() - self.viewModel.isFocused = true - self.resetUseCases() // Removes execute from init - self.publishers.reset() // Removes publishes from init - - // WHEN - let viewModel = self.viewModel.focused(false) - - // THEN - XCTAssertIdentical(viewModel, self.viewModel, "Wrong returned viewModel") - XCTAssertFalse(viewModel.isFocused, "isFocused should be false") - } - // MARK: - Utils func setupPublishers() { self.publishers = .init(