Skip to content
Snippets Groups Projects
OnboardingSuccessController.swift 1.98 KiB
Newer Older
Bruno Muniz's avatar
Bruno Muniz committed
import UIKit
import Theme
import Models
import Shared
import Combine
import Countries
import DependencyInjection

public struct OnboardingSuccessModel {
    var title: String
    var subtitle: String?
    var nextController: (UIViewController) -> Void
}

public final class OnboardingSuccessController: UIViewController {
Bruno Muniz's avatar
Bruno Muniz committed
    @Dependency private var coordinator: OnboardingCoordinating

    lazy private var screenView = OnboardingSuccessView()
    private var cancellables = Set<AnyCancellable>()

    private var model: OnboardingSuccessModel

    public override func loadView() {
Bruno Muniz's avatar
Bruno Muniz committed
        view = screenView
    }

    public init(_ model: OnboardingSuccessModel) {
        self.model = model
Bruno Muniz's avatar
Bruno Muniz committed
        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder: NSCoder) { nil }

    public override func viewWillAppear(_ animated: Bool) {
Bruno Muniz's avatar
Bruno Muniz committed
        super.viewWillAppear(animated)
        navigationController?.navigationBar.customize(translucent: true)
    }

    public override func viewDidLayoutSubviews() {
Bruno Muniz's avatar
Bruno Muniz committed
        super.viewDidLayoutSubviews()

        let gradient = CAGradientLayer()
        gradient.colors = [
            UIColor(red: 122/255, green: 235/255, blue: 239/255, alpha: 1).cgColor,
            UIColor(red: 56/255, green: 204/255, blue: 232/255, alpha: 1).cgColor,
            UIColor(red: 63/255, green: 186/255, blue: 253/255, alpha: 1).cgColor,
            UIColor(red: 98/255, green: 163/255, blue: 255/255, alpha: 1).cgColor
        ]

        gradient.startPoint = CGPoint(x: 0, y: 0)
        gradient.endPoint = CGPoint(x: 1, y: 1)

        gradient.frame = screenView.bounds
        screenView.layer.insertSublayer(gradient, at: 0)
    }

    public override func viewDidLoad() {
Bruno Muniz's avatar
Bruno Muniz committed
        super.viewDidLoad()

        screenView.setTitle(model.title)
        screenView.setSubtitle(model.subtitle)
Bruno Muniz's avatar
Bruno Muniz committed

        screenView.nextButton
            .publisher(for: .touchUpInside)
            .sink { [unowned self] in model.nextController(self) }
            .store(in: &cancellables)
Bruno Muniz's avatar
Bruno Muniz committed
    }
}