Created
August 29, 2019 12:31
-
-
Save agiguere/ea2e54d09ed15975c4b2589937961a07 to your computer and use it in GitHub Desktop.
SAP Fiori for iOS SDK Code Snippet: ApplicationUIManager
This file contains hidden or 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
import SAPCommon | |
import SAPFiori | |
import SAPFioriFlows | |
import SAPFoundation | |
class SnapshotViewController: UIViewController {} | |
class ApplicationUIManager { | |
/// Save ViewController while splash/onboarding screens are presented | |
private var savedApplicationRootViewController: UIViewController? | |
private var onboardingSplashViewController: (UIViewController & InfoTextSettable)? | |
private var coveringViewController: UIViewController? | |
let window: UIWindow | |
init(window: UIWindow) { | |
self.window = window | |
} | |
func releaseRootFromMemory() { | |
savedApplicationRootViewController = nil | |
} | |
} | |
// MARK: - ApplicationUIManaging | |
extension ApplicationUIManager: ApplicationUIManaging { | |
func hideApplicationScreen(completionHandler: @escaping (Error?) -> Void) { | |
defer { | |
completionHandler(nil) | |
} | |
// Check whether the covering screen is already presented or not | |
guard coveringViewController == nil else { return } | |
saveApplicationScreenIfNecessary() | |
coveringViewController = SnapshotViewController() | |
window.rootViewController = coveringViewController | |
} | |
func showSplashScreenForOnboarding(completionHandler: @escaping (Error?) -> Void) { | |
defer { | |
completionHandler(nil) | |
} | |
// Check if no splash already presented | |
guard onboardingSplashViewController == nil else { return } | |
setupSplashScreen() | |
} | |
func showSplashScreenForUnlock(completionHandler: @escaping (Error?) -> Void) { | |
defer { | |
completionHandler(nil) | |
} | |
// Check if no splash already presented | |
guard onboardingSplashViewController == nil else { return } | |
saveApplicationScreenIfNecessary() | |
setupSplashScreen() | |
} | |
func showApplicationScreen(completionHandler: @escaping (Error?) -> Void) { | |
defer { | |
completionHandler(nil) | |
} | |
// Check if an application screen has already been presented | |
guard isSplashPresented else { return } | |
// Restore the saved application screen or create a new one | |
let appViewController: UIViewController | |
if let savedViewController = savedApplicationRootViewController { | |
appViewController = savedViewController | |
} else { | |
let appDelegate = (UIApplication.shared.delegate as! AppDelegate) | |
let splitViewController = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "MainSplitViewController") as! UISplitViewController | |
splitViewController.delegate = appDelegate | |
splitViewController.modalPresentationStyle = .currentContext | |
splitViewController.preferredDisplayMode = .allVisible | |
appViewController = splitViewController | |
} | |
window.rootViewController = appViewController | |
onboardingSplashViewController = nil | |
savedApplicationRootViewController = nil | |
coveringViewController = nil | |
} | |
} | |
// MARK: - Private API | |
private extension ApplicationUIManager { | |
var isSplashPresented: Bool { | |
return window.rootViewController is FUIInfoViewController || window.rootViewController is SnapshotViewController | |
} | |
func saveApplicationScreenIfNecessary() { | |
if savedApplicationRootViewController == nil, !isSplashPresented { | |
savedApplicationRootViewController = window.rootViewController | |
} | |
} | |
func setupSplashScreen() { | |
onboardingSplashViewController = FUIInfoViewController.createSplashScreenInstanceFromStoryboard() | |
window.rootViewController = onboardingSplashViewController | |
// Set the splash screen for the specific presenter | |
let modalPresenter = OnboardingFlowProvider.modalUIViewControllerPresenter | |
modalPresenter.setSplashScreen(onboardingSplashViewController!) | |
modalPresenter.animated = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment