State restoration

This commit is contained in:
Shadowfacts 2022-03-13 21:18:28 -04:00
parent b7a4f369f6
commit 7d4f5ccba3
2 changed files with 26 additions and 1 deletions

View File

@ -27,7 +27,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
window = UIWindow(windowScene: windowScene)
window!.tintColor = .appTintColor
var activity = connectionOptions.userActivities.first
var activity = connectionOptions.userActivities.first ?? session.stateRestorationActivity
var account = LocalData.mostRecentAccount()
@ -108,6 +108,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// to restore the scene back to its current state.
}
func stateRestorationActivity(for scene: UIScene) -> NSUserActivity? {
return (window!.rootViewController as! AppSplitViewController).stateRestorationActivity()
}
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
Task { @MainActor in
await setupUI(from: userActivity)

View File

@ -54,6 +54,27 @@ class AppSplitViewController: UISplitViewController {
setViewController(nav, for: .compact)
}
func stateRestorationActivity() -> NSUserActivity? {
if traitCollection.horizontalSizeClass == .compact {
let nav = viewController(for: .compact) as! UINavigationController
let top = nav.topViewController!
if top is ReadViewController || top is ItemsViewController {
print(top.userActivity?.activityType)
return top.userActivity
}
} else {
if let read = secondaryNav.topViewController {
return read.userActivity
} else {
let homeNav = viewController(for: .primary) as! UINavigationController
if homeNav.topViewController is ItemsViewController {
return homeNav.topViewController!.userActivity
}
}
}
return nil
}
func showItemList(_ type: ItemListType) {
let column: Column
if traitCollection.horizontalSizeClass == .compact {