metatext-app-ios-iphone-ipad/View Controllers/ProfileViewController.swift

57 lines
1.8 KiB
Swift
Raw Normal View History

2020-09-27 07:54:06 +02:00
// Copyright © 2020 Metabolist. All rights reserved.
import Combine
import UIKit
import ViewModels
final class ProfileViewController: TableViewController {
private let viewModel: ProfileViewModel
private var cancellables = Set<AnyCancellable>()
2020-10-07 02:31:29 +02:00
required init(viewModel: ProfileViewModel, identification: Identification) {
2020-09-27 07:54:06 +02:00
self.viewModel = viewModel
2020-10-07 02:31:29 +02:00
super.init(viewModel: viewModel, identification: identification)
2020-09-27 07:54:06 +02:00
}
override func viewDidLoad() {
super.viewDidLoad()
// Initial size is to avoid unsatisfiable constraint warning
let accountHeaderView = AccountHeaderView(frame: .init(origin: .zero, size: .init(width: 100, height: 100)))
accountHeaderView.viewModel = viewModel
viewModel.$accountViewModel
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
accountHeaderView.viewModel = self?.viewModel
self?.sizeTableHeaderFooterViews()
}
.store(in: &cancellables)
2020-10-23 00:16:06 +02:00
viewModel.imagePresentations.sink { [weak self] in
guard let self = self else { return }
let imagePageViewController = ImagePageViewController(imageURL: $0)
let imageNavigationController = ImageNavigationController(imagePageViewController: imagePageViewController)
imageNavigationController.transitionController.fromDelegate = self
self.transitionViewTag = $0.hashValue
self.present(imageNavigationController, animated: true)
}
.store(in: &cancellables)
2020-09-27 07:54:06 +02:00
tableView.tableHeaderView = accountHeaderView
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.fetchProfile()
.sink { _ in }
.store(in: &cancellables)
}
2020-09-27 07:54:06 +02:00
}