Compare commits

...

1 Commits

Author SHA1 Message Date
Shin Yamamoto ccabb1914a Opt-in the dismissSwizzling call as needed 2023-12-02 09:46:51 +09:00
6 changed files with 44 additions and 13 deletions
@@ -82,7 +82,10 @@ struct FloatingPanelView<Content: View, FloatingPanelContent: View>: UIViewContr
/// Responsible to setup the view hierarchy and floating panel.
final class Coordinator {
private let parent: FloatingPanelView<Content, FloatingPanelContent>
private lazy var fpc = FloatingPanelController()
private lazy var fpc = {
FloatingPanelController.enableDismissToRemove()
return FloatingPanelController()
}()
init(parent: FloatingPanelView<Content, FloatingPanelContent>) {
self.parent = parent
+6 -1
View File
@@ -1,9 +1,14 @@
// Copyright 2018 the FloatingPanel authors. All rights reserved. MIT license.
import UIKit
import FloatingPanel
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FloatingPanelController.enableDismissToRemove()
return true
}
}
+1 -1
View File
@@ -124,7 +124,7 @@ extension MainViewController: UISearchBarDelegate {
searchBar.showsCancelButton = true
searchVC.showHeader(animated: true)
searchVC.tableView.alpha = 1.0
detailVC.dismiss(animated: true, completion: nil)
detailFpc.removePanelFromParent(animated: true)
}
func deactivate(searchBar: UISearchBar) {
searchBar.resignFirstResponder()
@@ -1,8 +1,13 @@
// Copyright 2018 the FloatingPanel authors. All rights reserved. MIT license.
import UIKit
import FloatingPanel
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FloatingPanelController.enableDismissToRemove()
return true
}
}
@@ -1,9 +1,15 @@
// Copyright 2018 the FloatingPanel authors. All rights reserved. MIT license.
#import "AppDelegate.h"
@import FloatingPanel;
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions
{
[FloatingPanelController enableDismissToRemove];
return YES;
}
@end
+22 -10
View File
@@ -288,8 +288,6 @@ open class FloatingPanelController: UIViewController {
}
private func setUp() {
_ = FloatingPanelController.dismissSwizzling
modalPresentationStyle = .custom
transitioningDelegate = modalTransition
@@ -310,7 +308,7 @@ open class FloatingPanelController: UIViewController {
}
}
// MARK:- Overrides
// MARK: - Overrides
/// Creates the view that the controller manages.
open override func loadView() {
@@ -381,7 +379,8 @@ open class FloatingPanelController: UIViewController {
safeAreaInsetsObservation = nil
}
// MARK:- Child view controller to consult
// MARK: - Child view controller to consult
open override var childForStatusBarStyle: UIViewController? {
return contentViewController
}
@@ -398,19 +397,19 @@ open class FloatingPanelController: UIViewController {
return contentViewController
}
// MARK:- Privates
// MARK: - Privates
private func shouldUpdateLayout(from previous: UITraitCollection, to new: UITraitCollection) -> Bool {
return previous.horizontalSizeClass != new.horizontalSizeClass
|| previous.verticalSizeClass != new.verticalSizeClass
|| previous.preferredContentSizeCategory != new.preferredContentSizeCategory
|| previous.layoutDirection != new.layoutDirection
|| previous.verticalSizeClass != new.verticalSizeClass
|| previous.preferredContentSizeCategory != new.preferredContentSizeCategory
|| previous.layoutDirection != new.layoutDirection
}
private func update(safeAreaInsets: UIEdgeInsets) {
guard
preSafeAreaInsets != safeAreaInsets
else { return }
else { return }
os_log(msg, log: devLog, type: .debug, "Update safeAreaInsets = \(safeAreaInsets)")
@@ -540,7 +539,7 @@ open class FloatingPanelController: UIViewController {
self.view.leftAnchor.constraint(equalTo: parent.view.leftAnchor, constant: 0.0),
self.view.rightAnchor.constraint(equalTo: parent.view.rightAnchor, constant: 0.0),
self.view.bottomAnchor.constraint(equalTo: parent.view.bottomAnchor, constant: 0.0),
])
])
show(animated: animated) { [weak self] in
guard let self = self else { return }
@@ -694,6 +693,18 @@ open class FloatingPanelController: UIViewController {
get { floatingPanel.layoutAdapter.surfaceLocation }
set { floatingPanel.layoutAdapter.surfaceLocation = newValue }
}
/// Calling this will allow to invoke `removePanelFromParent(animated:completion:)` as needed by
/// calling UIViewController's `dismiss` method
///
/// Previously, until v2.8, this was the default behavior. However, from v2.9 onwards, due to
/// identified issues when used in conjunction with other libraries, it has been made an opt-in
/// feature.
@objc
public static func enableDismissToRemove() {
_ = FloatingPanelController.dismissSwizzling
}
}
extension FloatingPanelController {
@@ -732,6 +743,7 @@ private var originalDismissImp: IMP?
private typealias DismissFunction = @convention(c) (AnyObject, Selector, Bool, (() -> Void)?) -> Void
extension FloatingPanelController {
private static let dismissSwizzling: Void = {
guard originalDismissImp == nil else { return }
let aClass: AnyClass! = UIViewController.self //object_getClass(vc)
if let originalMethod = class_getInstanceMethod(aClass, #selector(dismiss(animated:completion:))),
let swizzledImp = class_getMethodImplementation(aClass, #selector(__swizzled_dismiss(animated:completion:))) {