Files
divkit/client/ios/DivKit/Actions/TimerActionHandler.swift
pkurchatov 93113c7bb3 Added download action handler
commit_hash:356512da68f2ed46479425dd365d06a9ca266514
2025-01-24 19:48:07 +03:00

48 lines
1.0 KiB
Swift

import Foundation
import LayoutKit
import VGSL
final class TimerActionHandler {
private let performer: DivActionHandler.PerformTimerAction
init(performer: @escaping DivActionHandler.PerformTimerAction) {
self.performer = performer
}
func handle(
_ action: DivActionTimer,
context: DivActionHandlingContext
) {
let expressionResolver = context.expressionResolver
guard let id = action.resolveId(expressionResolver),
let command = action.resolveAction(expressionResolver) else {
return
}
handle(cardId: context.cardId, timerId: id, action: command.toDivTimerAction())
}
func handle(cardId: DivCardID, timerId: String, action: DivTimerAction) {
performer(cardId, timerId, action)
}
}
extension DivActionTimer.Action {
func toDivTimerAction() -> DivTimerAction {
switch self {
case .start:
.start
case .stop:
.stop
case .pause:
.pause
case .resume:
.resume
case .cancel:
.cancel
case .reset:
.reset
}
}
}