Skip to content

Commit

Permalink
Fix deep linking preventing subsequent event/news screen from being d…
Browse files Browse the repository at this point in the history
…isplayed
  • Loading branch information
matax87 committed Dec 6, 2024
1 parent 691fd84 commit 24be6e8
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ class BaseCoordinator: NSObject, CoordinatorType {
var childCoordinators: [CoordinatorType] = []

var dependencyContainer: DependencyRepresentable


var topViewController: UIViewController? {
guard let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as? UIWindowSceneDelegate
else { return nil }

return sceneDelegate.window??.topViewController
}

@available(*, unavailable)
override init() {
fatalError("\(#function) not available")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class AppCoordinator: BaseNavigationCoordinator {
private var pendingDeepLinkIntent: DeepLinkIntent?

private weak var tabCoordinator: TabCoordinator!

override func start(animated: Bool) {
NotificationCenter
.default
Expand Down Expand Up @@ -202,6 +202,9 @@ private extension AppCoordinator {
}

func showNewsDetails(newsId: String, sender: Any?) {
guard let topViewController
else { return }

func configureBindings(
viewModel: NewsDetailsViewModel,
pageViewController: NewsPageViewController
Expand Down Expand Up @@ -243,10 +246,9 @@ private extension AppCoordinator {
pageVC.navigationItem.largeTitleDisplayMode = .never
pageVC.navigationItem.leftBarButtonItem = UIBarButtonItem(
image: UIImage(systemName: "xmark.circle.fill"),
style: .plain,
target: self,
action: #selector(closeModal(sender:))
)
primaryAction: UIAction { [weak pageVC] _ in
pageVC?.dismiss(animated: true)
})
pageVC.modalPresentationStyle = .fullScreen

return pageVC
Expand All @@ -256,8 +258,8 @@ private extension AppCoordinator {
viewModel: viewModel,
pageViewController: pageVC
)
navigationController.present(

topViewController.present(
NavigationController(rootViewController: pageVC),
animated: true
)
Expand Down Expand Up @@ -309,6 +311,9 @@ private extension AppCoordinator {
}

func showEventDetails(eventId: String, sender: Any?) {
guard let topViewController
else { return }

func configureBindings(
viewModel: EventDetailsViewModel,
pageViewController: EventPageViewController
Expand Down Expand Up @@ -354,27 +359,22 @@ private extension AppCoordinator {
pageVC.navigationItem.largeTitleDisplayMode = .never
pageVC.navigationItem.leftBarButtonItem = UIBarButtonItem(
image: UIImage(systemName: "xmark.circle.fill"),
style: .plain,
target: self,
action: #selector(closeModal(sender:))
)
primaryAction: UIAction { [weak pageVC] _ in
pageVC?.dismiss(animated: true)
})
pageVC.modalPresentationStyle = .fullScreen

return pageVC
}()

configureBindings(viewModel: viewModel, pageViewController: pageVC)

navigationController.present(
topViewController.present(
NavigationController(rootViewController: pageVC),
animated: true
)
}

@objc func closeModal(sender: Any?) {
navigationController.dismiss(animated: true)
}

func showAccessNotGrantedCoordinator(animated: Bool) {
let accessNotGrantedCoordinator = AccessNotGrantedCoordinator(
navigationController: navigationController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,25 @@ final class EventPageViewController: BasePageViewController<EventDetailsViewMode

var locateActionHandler: ((Event) -> Void)? {
didSet {
eventDetailsViewController?.locateActionHandler = locateActionHandler
eventDetailsViewController?.locateActionHandler = { [weak self] in
self?.locateActionHandler?($0)
}
}
}

var addToCalendarActionHandler: ((Event) -> Void)? {
didSet {
eventDetailsViewController?.addToCalendarActionHandler = addToCalendarActionHandler
eventDetailsViewController?.addToCalendarActionHandler = { [weak self] in
self?.addToCalendarActionHandler?($0)
}
}
}

var signupActionHandler: ((Event) -> Void)? {
didSet {
eventDetailsViewController?.signupActionHandler = signupActionHandler
eventDetailsViewController?.signupActionHandler = { [weak self] in
self?.signupActionHandler?($0)
}
}
}

Expand Down Expand Up @@ -93,9 +99,15 @@ private extension EventPageViewController {

func makeResultContent(for event: Event) -> EventDetailsViewController {
let result = EventDetailsViewController(for: event)
result.locateActionHandler = locateActionHandler
result.addToCalendarActionHandler = addToCalendarActionHandler
result.signupActionHandler = signupActionHandler
result.locateActionHandler = { [weak self] in
self?.locateActionHandler?($0)
}
result.addToCalendarActionHandler = { [weak self] in
self?.addToCalendarActionHandler?($0)
}
result.signupActionHandler = { [weak self] in
self?.signupActionHandler?($0)
}
return result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ final class NewsPageViewController: BasePageViewController<NewsDetailsViewModel>

var externalLinkActionHandler: ((Article) -> Void)? {
didSet {
newsDetailsViewController?.externalLinkActionHandler = externalLinkActionHandler
newsDetailsViewController?.externalLinkActionHandler = { [weak self] in
self?.externalLinkActionHandler?($0)
}
}
}

var askQuestionActionHandler: ((Article) -> Void)? {
didSet {
newsDetailsViewController?.askQuestionActionHandler = askQuestionActionHandler
newsDetailsViewController?.askQuestionActionHandler = { [weak self] in
self?.askQuestionActionHandler?($0)
}
}
}

Expand Down Expand Up @@ -89,8 +93,12 @@ private extension NewsPageViewController {

func makeResultContent(for news: Article) -> NewsDetailsViewController {
let result = NewsDetailsViewController(for: news)
result.externalLinkActionHandler = externalLinkActionHandler
result.askQuestionActionHandler = askQuestionActionHandler
result.externalLinkActionHandler = { [weak self] in
self?.externalLinkActionHandler?($0)
}
result.askQuestionActionHandler = { [weak self] in
self?.askQuestionActionHandler?($0)
}
return result
}

Expand Down
39 changes: 39 additions & 0 deletions NOICommunityLib/Sources/CoreUI/UIWindow+topViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: NOI Techpark <[email protected]>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

//
// UIWindow+topViewController.swift
// NOICommunityLib
//
// Created by Matteo Matassoni on 06/12/24.
//

import UIKit

public extension UIWindow {

var topViewController: UIViewController? {
topMostViewController(from: rootViewController)
}

}

private extension UIWindow {

func topMostViewController(
from viewController: UIViewController?
) -> UIViewController? {
if let presentedViewController = viewController?.presentedViewController {
topMostViewController(from: presentedViewController)
} else if let tabBarController = viewController as? UITabBarController {
topMostViewController(from: tabBarController.selectedViewController)
} else if let navigationController = viewController as? UINavigationController,
let topViewController = navigationController.topViewController {
topMostViewController(from: topViewController)
} else {
viewController
}
}

}

0 comments on commit 24be6e8

Please sign in to comment.