Skip to content

Commit

Permalink
Activity Indicator Demo: Update start/stop activity button title base…
Browse files Browse the repository at this point in the history
…d on state
  • Loading branch information
imthath-m committed Feb 3, 2024
1 parent 4669412 commit 16c3f5b
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ActivityIndicatorDemoController: DemoTableViewController {
return UITableViewCell()
}

cell.setup(action1Title: row.title)
cell.setup(action1Title: isAnimating ? "Stop Activity" : "Start Activity")
cell.action1Button.addTarget(self,
action: #selector(startStopActivity),
for: .touchUpInside)
Expand Down Expand Up @@ -191,7 +191,7 @@ class ActivityIndicatorDemoController: DemoTableViewController {
case .hidesWhenStopped:
return "Hides when stopped"
case .startStopActivity:
return "Start / Stop activity"
return ""
case .demoOfSize:
return ""
}
Expand Down Expand Up @@ -235,6 +235,13 @@ class ActivityIndicatorDemoController: DemoTableViewController {

@objc private func startStopActivity() {
isAnimating.toggle()

guard let section: Int = ActivityIndicatorDemoSection.allCases.firstIndex(of: .settings),
let row: Int = ActivityIndicatorDemoSection.settings.rows.firstIndex(of: .startStopActivity) else {
return
}
// Reloading row to update the button title
tableView.reloadRows(at: [.init(row: row, section: section)], with: .automatic)
}
}

Expand Down

0 comments on commit 16c3f5b

Please sign in to comment.