Skip to content
Snippets Groups Projects
Select Git revision
  • 88f47a455ea14c72c8507bdb6a2e8d2d976a5eea
  • main default protected
  • dev protected
  • hotfixes-oct-2022
  • refactor/avatar-cell
  • 1.1.5
  • 1.1.4
  • 1.1.3
  • 1.1
  • 1.0.8
  • 1.0.7
  • 1.0.6
12 results

RetrySheetController.swift

Blame
  • user avatar
    Bruno Muniz authored
    48ac2853
    History
    RetrySheetController.swift 1.54 KiB
    import UIKit
    import Combine
    
    public final class RetrySheetController: UIViewController {
        enum Action {
            case retry
            case delete
            case cancel
        }
    
        // MARK: UI
    
        lazy private var screenView = RetrySheetView()
    
        // MARK: Properties
    
        var actionPublisher: AnyPublisher<Action, Never> {
            actionRelay.eraseToAnyPublisher()
        }
    
        private var cancellables = Set<AnyCancellable>()
        private let actionRelay = PassthroughSubject<Action, Never>()
    
        // MARK: Lifecycle
    
        public override func loadView() {
            view = screenView
        }
    
        public override func viewDidLoad() {
            super.viewDidLoad()
            setupBindings()
        }
    
        // MARK: Private
    
        private func setupBindings() {
            screenView.retry
                .publisher(for: .touchUpInside)
                .sink { [unowned self] in
                    dismiss(animated: true) { [weak actionRelay] in
                        actionRelay?.send(.retry)
                    }
                }.store(in: &cancellables)
    
            screenView.delete
                .publisher(for: .touchUpInside)
                .sink { [unowned self] in
                    dismiss(animated: true) { [weak actionRelay] in
                        actionRelay?.send(.delete)
                    }
                }.store(in: &cancellables)
    
            screenView.cancel
                .publisher(for: .touchUpInside)
                .sink { [unowned self] in
                    dismiss(animated: true) { [weak actionRelay] in
                        actionRelay?.send(.cancel)
                    }
                }.store(in: &cancellables)
        }
    }