Animate toggle-switch (IOS-14)

This commit is contained in:
Nathan Mattes 2023-09-27 14:48:36 +02:00
parent 0e964de0df
commit b6a7126eb1
1 changed files with 24 additions and 19 deletions

View File

@ -128,16 +128,24 @@ extension GeneralSettingsViewController: UITableViewDelegate {
switch section {
case .appearance(let appearanceOption):
viewModel.selectedAppearence = appearanceOption
case .design(_):
break
case .openLinksIn(let openLinksInOption):
viewModel.selectedOpenLinks = openLinksInOption
}
if let snapshot = tableViewDataSource?.snapshot() {
tableViewDataSource?.applySnapshotUsingReloadData(snapshot)
}
case .design(let design):
guard let cell = tableView.cellForRow(at: indexPath) as? GeneralSettingToggleTableViewCell else { return}
let newValue = (cell.toggle.isOn == false)
cell.toggle.setOn(newValue, animated: true)
toggle(cell, setting: .design(design), isOn: newValue)
case .openLinksIn(let openLinksInOption):
viewModel.selectedOpenLinks = openLinksInOption
if let snapshot = tableViewDataSource?.snapshot() {
tableViewDataSource?.applySnapshotUsingReloadData(snapshot)
}
}
tableView.deselectRow(at: indexPath, animated: true)
delegate?.save(self, setting: setting, viewModel: viewModel)
@ -156,9 +164,6 @@ extension GeneralSettingsViewController: GeneralSettingToggleTableViewCellDelega
}
}
if let snapshot = tableViewDataSource?.snapshot() {
tableViewDataSource?.applySnapshotUsingReloadData(snapshot)
}
delegate?.save(self, setting: self.setting, viewModel: viewModel)
}
}