Compare commits
3 Commits
203c1852d4
...
473ef018c9
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 473ef018c9 | |
Shadowfacts | 9a734565b0 | |
Shadowfacts | 2eda9657ac |
|
@ -8,8 +8,6 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public protocol DuckableViewController: UIViewController {
|
public protocol DuckableViewController: UIViewController {
|
||||||
var duckableDelegate: DuckableViewControllerDelegate? { get set }
|
|
||||||
|
|
||||||
func duckableViewControllerShouldDuck() -> DuckAttemptAction
|
func duckableViewControllerShouldDuck() -> DuckAttemptAction
|
||||||
|
|
||||||
func duckableViewControllerMayAttemptToDuck()
|
func duckableViewControllerMayAttemptToDuck()
|
||||||
|
@ -26,10 +24,6 @@ extension DuckableViewController {
|
||||||
public func duckableViewControllerDidFinishAnimatingDuck() {}
|
public func duckableViewControllerDidFinishAnimatingDuck() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public protocol DuckableViewControllerDelegate: AnyObject {
|
|
||||||
func duckableViewControllerWillDismiss(animated: Bool)
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum DuckAttemptAction {
|
public enum DuckAttemptAction {
|
||||||
case duck
|
case duck
|
||||||
case dismiss
|
case dismiss
|
||||||
|
|
|
@ -11,7 +11,7 @@ let duckedCornerRadius: CGFloat = 10
|
||||||
let detentHeight: CGFloat = 44
|
let detentHeight: CGFloat = 44
|
||||||
|
|
||||||
@available(iOS 16.0, *)
|
@available(iOS 16.0, *)
|
||||||
public class DuckableContainerViewController: UIViewController, DuckableViewControllerDelegate {
|
public class DuckableContainerViewController: UIViewController {
|
||||||
|
|
||||||
public let child: UIViewController
|
public let child: UIViewController
|
||||||
private var bottomConstraint: NSLayoutConstraint!
|
private var bottomConstraint: NSLayoutConstraint!
|
||||||
|
@ -87,7 +87,6 @@ public class DuckableContainerViewController: UIViewController, DuckableViewCont
|
||||||
}
|
}
|
||||||
|
|
||||||
private func doPresentDuckable(_ viewController: DuckableViewController, animated: Bool, completion: (() -> Void)?) {
|
private func doPresentDuckable(_ viewController: DuckableViewController, animated: Bool, completion: (() -> Void)?) {
|
||||||
viewController.duckableDelegate = self
|
|
||||||
viewController.modalPresentationStyle = .custom
|
viewController.modalPresentationStyle = .custom
|
||||||
viewController.transitioningDelegate = self
|
viewController.transitioningDelegate = self
|
||||||
present(viewController, animated: animated) {
|
present(viewController, animated: animated) {
|
||||||
|
@ -96,7 +95,10 @@ public class DuckableContainerViewController: UIViewController, DuckableViewCont
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func duckableViewControllerWillDismiss(animated: Bool) {
|
func dismissalTransitionWillBegin() {
|
||||||
|
guard case .presentingDucked(_, _) = state else {
|
||||||
|
return
|
||||||
|
}
|
||||||
state = .idle
|
state = .idle
|
||||||
bottomConstraint.isActive = false
|
bottomConstraint.isActive = false
|
||||||
bottomConstraint = child.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
bottomConstraint = child.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
||||||
|
@ -144,7 +146,7 @@ public class DuckableContainerViewController: UIViewController, DuckableViewCont
|
||||||
case .block:
|
case .block:
|
||||||
viewController.sheetPresentationController!.selectedDetentIdentifier = .large
|
viewController.sheetPresentationController!.selectedDetentIdentifier = .large
|
||||||
case .dismiss:
|
case .dismiss:
|
||||||
duckableViewControllerWillDismiss(animated: true)
|
// duckableViewControllerWillDismiss()
|
||||||
dismiss(animated: true)
|
dismiss(animated: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -189,7 +191,7 @@ public class DuckableContainerViewController: UIViewController, DuckableViewCont
|
||||||
@available(iOS 16.0, *)
|
@available(iOS 16.0, *)
|
||||||
extension DuckableContainerViewController: UIViewControllerTransitioningDelegate {
|
extension DuckableContainerViewController: UIViewControllerTransitioningDelegate {
|
||||||
public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
|
public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
|
||||||
let controller = UISheetPresentationController(presentedViewController: presented, presenting: presenting)
|
let controller = DuckableSheetPresentationController(presentedViewController: presented, presenting: presenting)
|
||||||
controller.delegate = self
|
controller.delegate = self
|
||||||
controller.prefersGrabberVisible = true
|
controller.prefersGrabberVisible = true
|
||||||
controller.selectedDetentIdentifier = .large
|
controller.selectedDetentIdentifier = .large
|
||||||
|
@ -215,6 +217,14 @@ extension DuckableContainerViewController: UIViewControllerTransitioningDelegate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
class DuckableSheetPresentationController: UISheetPresentationController {
|
||||||
|
override func dismissalTransitionWillBegin() {
|
||||||
|
super.dismissalTransitionWillBegin()
|
||||||
|
(self.delegate as! DuckableContainerViewController).dismissalTransitionWillBegin()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@available(iOS 16.0, *)
|
@available(iOS 16.0, *)
|
||||||
extension DuckableContainerViewController: UISheetPresentationControllerDelegate {
|
extension DuckableContainerViewController: UISheetPresentationControllerDelegate {
|
||||||
public func presentationController(_ presentationController: UIPresentationController, willPresentWithAdaptiveStyle style: UIModalPresentationStyle, transitionCoordinator: UIViewControllerTransitionCoordinator?) {
|
public func presentationController(_ presentationController: UIPresentationController, willPresentWithAdaptiveStyle style: UIModalPresentationStyle, transitionCoordinator: UIViewControllerTransitionCoordinator?) {
|
||||||
|
|
|
@ -23,7 +23,6 @@ protocol ComposeHostingControllerDelegate: AnyObject {
|
||||||
class ComposeHostingController: UIHostingController<ComposeHostingController.View>, DuckableViewController {
|
class ComposeHostingController: UIHostingController<ComposeHostingController.View>, DuckableViewController {
|
||||||
|
|
||||||
weak var delegate: ComposeHostingControllerDelegate?
|
weak var delegate: ComposeHostingControllerDelegate?
|
||||||
weak var duckableDelegate: DuckableViewControllerDelegate?
|
|
||||||
|
|
||||||
let controller: ComposeController
|
let controller: ComposeController
|
||||||
let mastodonController: MastodonController
|
let mastodonController: MastodonController
|
||||||
|
@ -107,7 +106,6 @@ class ComposeHostingController: UIHostingController<ComposeHostingController.Vie
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
dismiss(animated: true)
|
dismiss(animated: true)
|
||||||
duckableDelegate?.duckableViewControllerWillDismiss(animated: true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -225,7 +225,7 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
|
||||||
|
|
||||||
case let .tab(tab):
|
case let .tab(tab):
|
||||||
// sidebar items that map 1 <-> 1 can be transferred directly
|
// sidebar items that map 1 <-> 1 can be transferred directly
|
||||||
tabBarViewController.select(tab: tab)
|
tabBarViewController.select(tab: tab, dismissPresented: false)
|
||||||
|
|
||||||
case .explore:
|
case .explore:
|
||||||
// Search sidebar item maps to the Explore tab with the search controller/results visible
|
// Search sidebar item maps to the Explore tab with the search controller/results visible
|
||||||
|
@ -268,10 +268,10 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
|
||||||
// Transfer the navigation stack, dropping the search VC, to keep anything the user has opened
|
// Transfer the navigation stack, dropping the search VC, to keep anything the user has opened
|
||||||
transferNavigationStack(from: .explore, to: exploreNav, dropFirst: true, append: true)
|
transferNavigationStack(from: .explore, to: exploreNav, dropFirst: true, append: true)
|
||||||
|
|
||||||
tabBarViewController.select(tab: .explore)
|
tabBarViewController.select(tab: .explore, dismissPresented: false)
|
||||||
|
|
||||||
case .bookmarks, .favorites, .list(_), .savedHashtag(_), .savedInstance(_):
|
case .bookmarks, .favorites, .list(_), .savedHashtag(_), .savedInstance(_):
|
||||||
tabBarViewController.select(tab: .explore)
|
tabBarViewController.select(tab: .explore, dismissPresented: false)
|
||||||
// Make sure the Explore VC doesn't show its search bar when it appears, in case the user was previously
|
// Make sure the Explore VC doesn't show its search bar when it appears, in case the user was previously
|
||||||
// in compact mode and performing a search.
|
// in compact mode and performing a search.
|
||||||
let exploreNav = tabBarViewController.viewController(for: .explore) as! UINavigationController
|
let exploreNav = tabBarViewController.viewController(for: .explore) as! UINavigationController
|
||||||
|
|
|
@ -111,13 +111,13 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
||||||
repositionFastSwitcherIndicator()
|
repositionFastSwitcherIndicator()
|
||||||
}
|
}
|
||||||
|
|
||||||
func select(tab: Tab) {
|
func select(tab: Tab, dismissPresented: Bool) {
|
||||||
if tab == .compose {
|
if tab == .compose {
|
||||||
compose(editing: nil)
|
compose(editing: nil)
|
||||||
} else {
|
} else {
|
||||||
// when switching tabs, dismiss the currently presented VC
|
// when switching tabs, dismiss the currently presented VC
|
||||||
// otherwise the selected tab changes behind the presented VC
|
// otherwise the selected tab changes behind the presented VC
|
||||||
if presentedViewController != nil {
|
if presentedViewController != nil && dismissPresented {
|
||||||
dismiss(animated: true) {
|
dismiss(animated: true) {
|
||||||
self.selectedIndex = tab.rawValue
|
self.selectedIndex = tab.rawValue
|
||||||
}
|
}
|
||||||
|
@ -141,8 +141,8 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
NSLayoutConstraint.deactivate(fastSwitcherConstraints)
|
NSLayoutConstraint.deactivate(fastSwitcherConstraints)
|
||||||
// using interfaceOrientation isn't ideal, but UITabBar buttons may lay out horizontally even in the compact size class
|
let isPortrait = view.bounds.width < view.bounds.height
|
||||||
if traitCollection.horizontalSizeClass == .compact && interfaceOrientation.isPortrait {
|
if traitCollection.horizontalSizeClass == .compact && isPortrait {
|
||||||
fastSwitcherConstraints = [
|
fastSwitcherConstraints = [
|
||||||
fastSwitcherIndicator.centerYAnchor.constraint(equalTo: myProfileButton.centerYAnchor, constant: -4),
|
fastSwitcherIndicator.centerYAnchor.constraint(equalTo: myProfileButton.centerYAnchor, constant: -4),
|
||||||
// tab bar button image width is 30
|
// tab bar button image width is 30
|
||||||
|
@ -291,18 +291,18 @@ extension MainTabBarViewController: TuskerRootViewController {
|
||||||
func select(route: TuskerRoute, animated: Bool) {
|
func select(route: TuskerRoute, animated: Bool) {
|
||||||
switch route {
|
switch route {
|
||||||
case .timelines:
|
case .timelines:
|
||||||
select(tab: .timelines)
|
select(tab: .timelines, dismissPresented: true)
|
||||||
case .notifications:
|
case .notifications:
|
||||||
select(tab: .notifications)
|
select(tab: .notifications, dismissPresented: true)
|
||||||
case .myProfile:
|
case .myProfile:
|
||||||
select(tab: .myProfile)
|
select(tab: .myProfile, dismissPresented: true)
|
||||||
case .explore:
|
case .explore:
|
||||||
select(tab: .explore)
|
select(tab: .explore, dismissPresented: true)
|
||||||
case .bookmarks:
|
case .bookmarks:
|
||||||
select(tab: .explore)
|
select(tab: .explore, dismissPresented: true)
|
||||||
getNavigationController().pushViewController(BookmarksViewController(mastodonController: mastodonController), animated: animated)
|
getNavigationController().pushViewController(BookmarksViewController(mastodonController: mastodonController), animated: animated)
|
||||||
case .list(id: let id):
|
case .list(id: let id):
|
||||||
select(tab: .explore)
|
select(tab: .explore, dismissPresented: true)
|
||||||
if let list = mastodonController.getCachedList(id: id) {
|
if let list = mastodonController.getCachedList(id: id) {
|
||||||
let nav = getNavigationController()
|
let nav = getNavigationController()
|
||||||
_ = nav.popToRootViewController(animated: animated)
|
_ = nav.popToRootViewController(animated: animated)
|
||||||
|
@ -325,7 +325,7 @@ extension MainTabBarViewController: TuskerRootViewController {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
select(tab: .explore)
|
select(tab: .explore, dismissPresented: true)
|
||||||
exploreNavController.popToRootViewController(animated: false)
|
exploreNavController.popToRootViewController(animated: false)
|
||||||
|
|
||||||
// setting searchController.isActive directly doesn't work until the view has loaded/appeared for the first time
|
// setting searchController.isActive directly doesn't work until the view has loaded/appeared for the first time
|
||||||
|
|
Loading…
Reference in New Issue