-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* IOS-10309: Force crouton on exact screen * IOS-10309: Unify show functions * Run swiftformat * Remove comments and added assert * Fix autoclosure on tests --------- Co-authored-by: WanaldinoTelefonica <WanaldinoTelefonica@users.noreply.github.com>
- Loading branch information
1 parent
bee78df
commit 8e1bd80
Showing
3 changed files
with
94 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
Sources/Mistica/Components/Crouton/Presentation/OngoingCrouton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// OngoingCrouton.swift | ||
// | ||
// Made with ❤️ by Novum | ||
// | ||
// Copyright © Telefonica. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension CroutonController { | ||
struct OngoingCrouton { | ||
let token: Token | ||
let croutonView: CroutonView | ||
private weak var exactViewController: UIViewController? | ||
private let rootViewController: RootViewController.Closure | ||
|
||
init( | ||
token: Token, | ||
croutonView: CroutonView, | ||
exactViewController: UIViewController? = nil, | ||
rootViewController: RootViewController.Closure? = nil | ||
) { | ||
self.token = token | ||
self.croutonView = croutonView | ||
self.exactViewController = exactViewController | ||
self.rootViewController = rootViewController ?? RootViewController.default | ||
} | ||
|
||
func view() -> UIView? { | ||
guard let viewController = viewController() else { return nil } | ||
|
||
if let viewController = viewController as? CustomCroutonContainer { | ||
return viewController.customCroutonContainerView | ||
} else { | ||
return viewController.view | ||
} | ||
} | ||
|
||
private func viewController() -> UIViewController? { | ||
if let exactViewController { | ||
return exactViewController | ||
} else if let rootViewController = rootViewController() { | ||
return visibleViewController(from: rootViewController) | ||
} else { | ||
assertionFailure("Root view controller not found!") | ||
return nil | ||
} | ||
} | ||
|
||
private func visibleViewController(from viewController: UIViewController) -> UIViewController { | ||
if let presentedViewController = viewController.presentedViewController { | ||
if presentedViewController is UIAlertController { | ||
return viewController | ||
} else { | ||
return visibleViewController(from: presentedViewController) | ||
} | ||
} else if let viewController = viewController as? UINavigationController { | ||
if let topViewController = viewController.topViewController { | ||
return visibleViewController(from: topViewController) | ||
} else { | ||
return viewController | ||
} | ||
} else if let tabViewController = viewController as? UITabBarController { | ||
if let selectedTab = tabViewController.selectedViewController { | ||
return selectedTab | ||
} else { | ||
return viewController | ||
} | ||
} | ||
|
||
return viewController | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters