Fix crash when subscribe for activities is too early #4420

pull/4421/head
Krypto Pank 3 years ago
parent fa258a56f0
commit 8eb7f7f11a
  1. 20
      AlphaWallet/Activities/Coordinators/ActivitiesCoordinator.swift
  2. 15
      AlphaWallet/Activities/ViewControllers/ActivitiesViewController.swift

@ -10,7 +10,7 @@ protocol ActivitiesCoordinatorDelegate: AnyObject {
class ActivitiesCoordinator: NSObject, Coordinator {
private let sessions: ServerDictionary<WalletSession>
private let activitiesService: ActivitiesServiceType
private var subscriptionKey: Subscribable<ActivitiesViewModel>.SubscribableKey!
private var subscriptionKey: Subscribable<ActivitiesViewModel>.SubscribableKey?
private let keystore: Keystore
private let wallet: Wallet
private let analyticsCoordinator: AnalyticsCoordinator
@ -38,16 +38,11 @@ class ActivitiesCoordinator: NSObject, Coordinator {
self.keystore = keystore
self.wallet = wallet
super.init()
subscriptionKey = activitiesService.subscribableViewModel.subscribe { [weak self] viewModel in
guard let strongSelf = self, let viewModel = viewModel else { return }
strongSelf.rootViewController.configure(viewModel: viewModel)
}
}
func start() {
navigationController.viewControllers = [rootViewController]
subscribeForActivitiesUpdates()
}
private func makeActivitiesViewController() -> ActivitiesViewController {
@ -68,6 +63,17 @@ class ActivitiesCoordinator: NSObject, Coordinator {
}
extension ActivitiesCoordinator: ActivitiesViewControllerDelegate {
func subscribeForActivitiesUpdates() {
subscriptionKey.flatMap { activitiesService.subscribableViewModel.unsubscribe($0) }
subscriptionKey = activitiesService.subscribableViewModel.subscribe { [weak rootViewController] viewModel in
guard let viewController = rootViewController, let viewModel = viewModel else { return }
viewController.configure(viewModel: viewModel)
}
}
func didPressActivity(activity: Activity, in viewController: ActivitiesViewController) {
delegate?.didPressActivity(activity: activity, in: viewController)
}

@ -13,7 +13,9 @@ class ActivitiesViewController: UIViewController {
private var viewModel: ActivitiesViewModel
private let searchController: UISearchController
private var isSearchBarConfigured = false
private var bottomConstraint: NSLayoutConstraint!
private lazy var bottomConstraint: NSLayoutConstraint = {
return activitiesView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
}()
private lazy var keyboardChecker = KeyboardChecker(self, resetHeightDefaultValue: 0, ignoreBottomSafeArea: true)
private var activitiesView: ActivitiesView
weak var delegate: ActivitiesViewControllerDelegate?
@ -24,11 +26,7 @@ class ActivitiesViewController: UIViewController {
activitiesView = ActivitiesView(analyticsCoordinator: analyticsCoordinator, keystore: keystore, wallet: wallet, viewModel: viewModel, sessions: sessions)
super.init(nibName: nil, bundle: nil)
title = R.string.localizable.activityTabbarItemTitle()
activitiesView.delegate = self
view.backgroundColor = viewModel.backgroundColor
bottomConstraint = activitiesView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
keyboardChecker.constraints = [bottomConstraint]
view.addSubview(activitiesView)
@ -41,6 +39,11 @@ class ActivitiesViewController: UIViewController {
])
setupFilteringWithKeyword()
}
override func viewDidLoad() {
super.viewDidLoad()
configure(viewModel: viewModel)
}
@ -70,6 +73,8 @@ class ActivitiesViewController: UIViewController {
func configure(viewModel: ActivitiesViewModel) {
self.viewModel = viewModel
title = R.string.localizable.activityTabbarItemTitle()
view.backgroundColor = viewModel.backgroundColor
activitiesView.configure(viewModel: viewModel)
activitiesView.applySearch(keyword: searchController.searchBar.text)

Loading…
Cancel
Save