Skip to content

Commit

Permalink
Fix InputField tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroruizponce committed Nov 19, 2024
1 parent 07abbcb commit febfca2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
27 changes: 12 additions & 15 deletions Sources/Mistica/Components/InputField/InputField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation

import UIKit
import Combine

public class InputField: UIView {
private typealias TextInputView = UIView & TextInput
Expand Down Expand Up @@ -377,20 +378,24 @@ public class InputField: UIView {
updateAssistiveLabelAlpha()
updateStyle()

subscribeToPlaceholdeLabelBoundsChanges()
subscribeToPlaceholderChanges()
}

deinit {
DispatchQueue.main.async { [weak self] in
self?.unsubscribeToPlaceholdeLabelBoundsChanges()
self?.cancellables.forEach { $0.cancel() }
}
}

override public func observeValue(forKeyPath _: String?, of _: Any?, change _: [NSKeyValueChangeKey: Any]?, context _: UnsafeMutableRawPointer?) {
Task { @MainActor in
updatePlaceholderLayerPosition()
updatePlaceholderLayerSize()
}
private var cancellables = Set<AnyCancellable>()

private func subscribeToPlaceholderChanges() {
backingPlaceholderLabel.publisher(for: \.bounds)
.sink { newBounds in
self.updatePlaceholderLayerPosition()
self.updatePlaceholderLayerSize()
}
.store(in: &cancellables)
}

override public var intrinsicContentSize: CGSize {
Expand Down Expand Up @@ -710,14 +715,6 @@ private extension InputField {
return validationStrategy?.validate(text: text) ?? .success
}
}

func subscribeToPlaceholdeLabelBoundsChanges() {
backingPlaceholderLabel.addObserver(self, forKeyPath: #keyPath(UIView.bounds), options: .new, context: nil)
}

func unsubscribeToPlaceholdeLabelBoundsChanges() {
backingPlaceholderLabel.removeObserver(self, forKeyPath: #keyPath(UIView.bounds))
}
}

// MARK: Animations
Expand Down
5 changes: 4 additions & 1 deletion Tests/MisticaTests/Utils/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ func assertSnapshotForAllBrandsAndStyles<View: UserInterfaceStyling, Format>(
for brand in BrandStyle.allCases {
MisticaConfig.brandStyle = brand

var lightView = viewBuilder()
lightView.overrideUserInterfaceStyle = .light

assertSnapshot(
of: viewBuilder(),
of: lightView,
as: snapshotting,
named: "with-\(brand)-style",
file: file,
Expand Down

0 comments on commit febfca2

Please sign in to comment.