Present compose screen in new window on iOS 15 and iPad/Mac

This commit is contained in:
Shadowfacts 2021-06-11 10:50:31 -04:00
parent 66e8fce488
commit 3413dff8f9
5 changed files with 59 additions and 19 deletions

View File

@ -17,21 +17,39 @@ class ComposeSceneDelegate: UIResponder, UIWindowSceneDelegate {
return return
} }
guard LocalData.shared.onboardingComplete else {
UIApplication.shared.requestSceneSessionDestruction(session, options: nil, errorHandler: nil)
return
}
let account: LocalData.UserAccountInfo let account: LocalData.UserAccountInfo
let controller: MastodonController
let draft: Draft? let draft: Draft?
if let activity = connectionOptions.userActivities.first ?? session.stateRestorationActivity, if let activity = connectionOptions.userActivities.first ?? session.stateRestorationActivity {
let activityAccount = UserActivityManager.getAccount(from: activity) { if let activityAccount = UserActivityManager.getAccount(from: activity) {
account = activityAccount account = activityAccount
draft = UserActivityManager.getDraft(from: activity) } else {
// todo: this potentially changes the account for the draft, should show the same warning to user as in the drafts selection screen
account = LocalData.shared.getMostRecentAccount()!
}
controller = MastodonController.getForAccount(account)
if let activityDraft = UserActivityManager.getDraft(from: activity) {
draft = activityDraft
} else if let mentioning = activity.userInfo?["mentioning"] as? String {
draft = controller.createDraft(inReplyToID: nil, mentioningAcct: mentioning)
} else {
draft = nil
}
} else { } else {
account = LocalData.shared.getMostRecentAccount()! account = LocalData.shared.getMostRecentAccount()!
controller = MastodonController.getForAccount(account)
draft = nil draft = nil
} }
let controller = MastodonController.getForAccount(account)
session.mastodonController = controller session.mastodonController = controller
controller.getOwnAccount() controller.getOwnAccount()
controller.getOwnInstance() controller.getOwnInstance()

View File

@ -353,11 +353,18 @@ fileprivate extension MainSidebarViewController.Item {
extension MainSplitViewController: TuskerRootViewController { extension MainSplitViewController: TuskerRootViewController {
@objc func presentCompose() { @objc func presentCompose() {
if #available(iOS 15.0, *), UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac {
let compose = UserActivityManager.newPostActivity(mentioning: nil, accountID: mastodonController.accountInfo!.id)
let options = UIWindowScene.ActivationRequestOptions()
options.preferredPresentationStyle = .prominent
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: compose, options: options, errorHandler: nil)
} else {
let vc = ComposeHostingController(mastodonController: mastodonController) let vc = ComposeHostingController(mastodonController: mastodonController)
let nav = EnhancedNavigationViewController(rootViewController: vc) let nav = EnhancedNavigationViewController(rootViewController: vc)
nav.presentationController?.delegate = vc nav.presentationController?.delegate = vc
present(nav, animated: true) present(nav, animated: true)
} }
}
func select(tab: MainTabBarViewController.Tab) { func select(tab: MainTabBarViewController.Tab) {
if traitCollection.horizontalSizeClass == .compact { if traitCollection.horizontalSizeClass == .compact {

View File

@ -212,11 +212,18 @@ extension MainTabBarViewController: FastAccountSwitcherViewControllerDelegate {
extension MainTabBarViewController: TuskerRootViewController { extension MainTabBarViewController: TuskerRootViewController {
@objc func presentCompose() { @objc func presentCompose() {
if #available(iOS 15.0, *), UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac {
let compose = UserActivityManager.newPostActivity(mentioning: nil, accountID: mastodonController.accountInfo!.id)
let options = UIWindowScene.ActivationRequestOptions()
options.preferredPresentationStyle = .prominent
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: compose, options: options, errorHandler: nil)
} else {
let vc = ComposeHostingController(mastodonController: mastodonController) let vc = ComposeHostingController(mastodonController: mastodonController)
let nav = EnhancedNavigationViewController(rootViewController: vc) let nav = EnhancedNavigationViewController(rootViewController: vc)
nav.presentationController?.delegate = vc nav.presentationController?.delegate = vc
present(nav, animated: true) present(nav, animated: true)
} }
}
func select(tab: Tab) { func select(tab: Tab) {
if tab == .compose { if tab == .compose {

View File

@ -70,6 +70,7 @@ class UserActivityManager {
// TODO: check not currently showing compose screen // TODO: check not currently showing compose screen
let mentioning = activity.userInfo?["mentioning"] as? String let mentioning = activity.userInfo?["mentioning"] as? String
let draft = mastodonController.createDraft(mentioningAcct: mentioning) let draft = mastodonController.createDraft(mentioningAcct: mentioning)
// todo: this shouldn't use self.mastodonController, it should get the right one based on the userInfo accountID
let composeVC = ComposeHostingController(draft: draft, mastodonController: mastodonController) let composeVC = ComposeHostingController(draft: draft, mastodonController: mastodonController)
present(UINavigationController(rootViewController: composeVC)) present(UINavigationController(rootViewController: composeVC))
} }

View File

@ -89,15 +89,22 @@ extension TuskerNavigationDelegate {
} }
func compose(editing draft: Draft) { func compose(editing draft: Draft) {
if #available(iOS 15.0, *), UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac {
let compose = UserActivityManager.editDraftActivity(id: draft.id, accountID: apiController.accountInfo!.id)
let options = UIWindowScene.ActivationRequestOptions()
options.preferredPresentationStyle = .prominent
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: compose, options: options, errorHandler: nil)
} else {
let compose = ComposeHostingController(draft: draft, mastodonController: apiController) let compose = ComposeHostingController(draft: draft, mastodonController: apiController)
let nav = UINavigationController(rootViewController: compose)
let vc = UINavigationController(rootViewController: compose) nav.presentationController?.delegate = compose
vc.presentationController?.delegate = compose present(nav, animated: true)
present(vc, animated: true) }
} }
func compose(inReplyToID: String? = nil, mentioningAcct: String? = nil) { func compose(inReplyToID: String? = nil, mentioningAcct: String? = nil) {
let draft = apiController.createDraft(inReplyToID: inReplyToID, mentioningAcct: mentioningAcct) let draft = apiController.createDraft(inReplyToID: inReplyToID, mentioningAcct: mentioningAcct)
DraftsManager.shared.add(draft)
compose(editing: draft) compose(editing: draft)
} }