Skip to content

Commit

Permalink
Small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Guretzki committed Sep 9, 2024
1 parent 4116d6d commit f4a589c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Adyen/UI/Form/Items/Toggle/FormToggleItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,7 @@ public final class FormToggleItemView: FormItemView<FormToggleItem> {
accessibilityTraits = switchControl.accessibilityTraits
accessibilityValue = switchControl.accessibilityValue

observe(item.$title) { [weak self] value in
self?.label.text = value
self?.accessibilityLabel = value
}

observe(item.publisher) { [weak self] value in
self?.switchControl.isOn = value
}

setupObservation()
addSubviews()
}

Expand All @@ -92,6 +84,17 @@ private extension FormToggleItemView {
[label, switchControl].forEach(stackView.addArrangedSubview)
stackView.adyen.anchor(inside: layoutMarginsGuide)
}

func setupObservation() {
observe(item.$title) { [weak self] value in
self?.label.text = value
self?.accessibilityLabel = value
}

observe(item.publisher) { [weak self] value in
self?.switchControl.isOn = value
}
}

@objc func switchControlValueChanged() {
accessibilityValue = switchControl.accessibilityValue
Expand Down

0 comments on commit f4a589c

Please sign in to comment.