Skip to content

Commit 4cfd08e

Browse files
committed
AddANoteViewController: Wiring SwitchTableViewCell
1 parent f884969 commit 4cfd08e

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/AddNote/AddANoteViewController.swift

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@ private extension AddANoteViewController {
118118
sections = [writeNoteSection, emailCustomerSection]
119119
}
120120

121-
/// Switch between a private note and a customer note
122-
///
123-
func toggleNoteType() {
124-
isCustomerNote = !isCustomerNote
125-
}
126-
127121
/// Cell Configuration
128122
///
129123
private func setup(cell: UITableViewCell, for row: Row) {
@@ -155,22 +149,23 @@ private extension AddANoteViewController {
155149
fatalError()
156150
}
157151

158-
cell.topLabel.text = NSLocalizedString("Email note to customer", comment: "Label for yes/no switch - emailing the note to customer.")
159-
cell.bottomLabel.text = NSLocalizedString("If disabled will add the note as private.", comment: "Detail label for yes/no switch.")
152+
cell.title = NSLocalizedString("Email note to customer", comment: "Label for yes/no switch - emailing the note to customer.")
153+
cell.subtitle = NSLocalizedString("If disabled will add the note as private.", comment: "Detail label for yes/no switch.")
160154
cell.accessibilityTraits = .button
161155
cell.accessibilityLabel = String.localizedStringWithFormat(NSLocalizedString("Email note to customer %@", comment: ""), isCustomerNote ? NSLocalizedString("On", comment: "Spoken label to indicate switch control is turned on") : NSLocalizedString("Off", comment: "Spoken label to indicate switch control is turned off."))
162156
cell.accessibilityHint = NSLocalizedString("Double tap to toggle setting.", comment: "VoiceOver accessibility hint, informing the user that double-tapping will toggle the switch off and on.")
163157

164-
cell.onToggleSwitchTouchUp = { [weak self] in
158+
cell.onChange = { [weak self] newValue in
165159
guard let `self` = self else {
166160
return
167161
}
168162

169-
self.toggleNoteType()
163+
self.isCustomerNote = newValue
170164
self.refreshTextViewCell()
171-
cell.accessibilityLabel = String.localizedStringWithFormat(NSLocalizedString("Email note to customer %@", comment: ""), self.isCustomerNote ? NSLocalizedString("On", comment: "Spoken label to indicate switch control is turned on") : NSLocalizedString("Off", comment: "Spoken label to indicate switch control is turned off."))
172-
cell.accessibilityHint = NSLocalizedString("Double tap to toggle setting.", comment: "VoiceOver accessibility hint, informing the user that double-tapping will toggle the switch off and on.")
173-
let stateValue = self.isCustomerNote ? "on" : "off"
165+
166+
cell.accessibilityLabel = String.localizedStringWithFormat(NSLocalizedString("Email note to customer %@", comment: ""), newValue ? NSLocalizedString("On", comment: "Spoken label to indicate switch control is turned on") : NSLocalizedString("Off", comment: "Spoken label to indicate switch control is turned off."))
167+
168+
let stateValue = newValue ? "on" : "off"
174169
WooAnalytics.shared.track(.orderNoteEmailCustomerToggled, withProperties: ["state": stateValue])
175170
}
176171
}

0 commit comments

Comments
 (0)