Skip to content

Commit

Permalink
Fix existential-any for Swift6 (#639)
Browse files Browse the repository at this point in the history
* Fixed existential any
* Added upcoming feature flag
  • Loading branch information
kitwtnb authored Aug 5, 2024
1 parent 5fa37b4 commit da31639
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 37 deletions.
3 changes: 3 additions & 0 deletions FloatingPanel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
OTHER_SWIFT_FLAGS = "-enable-upcoming-feature ExistentialAny";
PRODUCT_BUNDLE_IDENTIFIER = com.scenee.FloatingPanel;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -513,6 +514,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
OTHER_SWIFT_FLAGS = "-enable-upcoming-feature ExistentialAny";
PRODUCT_BUNDLE_IDENTIFIER = com.scenee.FloatingPanel;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -662,6 +664,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
OTHER_SWIFT_FLAGS = "-enable-upcoming-feature ExistentialAny";
PRODUCT_BUNDLE_IDENTIFIER = com.scenee.FloatingPanel;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down
6 changes: 3 additions & 3 deletions Sources/Behavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ open class FloatingPanelDefaultBehavior: FloatingPanelBehavior {

class BehaviorAdapter {
unowned let vc: FloatingPanelController
fileprivate var behavior: FloatingPanelBehavior
fileprivate var behavior: any FloatingPanelBehavior

init(vc: FloatingPanelController, behavior: FloatingPanelBehavior) {
init(vc: FloatingPanelController, behavior: any FloatingPanelBehavior) {
self.vc = vc
self.behavior = behavior
}
Expand Down Expand Up @@ -123,7 +123,7 @@ class BehaviorAdapter {
}

extension FloatingPanelController {
var _behavior: FloatingPanelBehavior {
var _behavior: any FloatingPanelBehavior {
get { floatingPanel.behaviorAdapter.behavior }
set { floatingPanel.behaviorAdapter.behavior = newValue}
}
Expand Down
18 changes: 9 additions & 9 deletions Sources/Controller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import os.log
@objc public protocol FloatingPanelControllerDelegate {
/// Returns a FloatingPanelLayout object. If you use the default one, you can use a `FloatingPanelBottomLayout` object.
@objc(floatingPanel:layoutForTraitCollection:) optional
func floatingPanel(_ fpc: FloatingPanelController, layoutFor newCollection: UITraitCollection) -> FloatingPanelLayout
func floatingPanel(_ fpc: FloatingPanelController, layoutFor newCollection: UITraitCollection) -> any FloatingPanelLayout

/// Returns a FloatingPanelLayout object. If you use the default one, you can use a `FloatingPanelBottomLayout` object.
@objc(floatingPanel:layoutForSize:) optional
func floatingPanel(_ fpc: FloatingPanelController, layoutFor size: CGSize) -> FloatingPanelLayout
func floatingPanel(_ fpc: FloatingPanelController, layoutFor size: CGSize) -> any FloatingPanelLayout

/// Returns a UIViewPropertyAnimator object to add/present the panel to a position.
///
Expand Down Expand Up @@ -151,7 +151,7 @@ open class FloatingPanelController: UIViewController {

/// The delegate of a panel controller object.
@objc
public weak var delegate: FloatingPanelControllerDelegate?{
public weak var delegate: (any FloatingPanelControllerDelegate)?{
didSet{
didUpdateDelegate()
}
Expand Down Expand Up @@ -199,7 +199,7 @@ open class FloatingPanelController: UIViewController {
/// You need to call ``invalidateLayout()`` if you want to apply a new layout object into the panel
/// immediately.
@objc
public var layout: FloatingPanelLayout {
public var layout: any FloatingPanelLayout {
get { _layout }
set {
_layout = newValue
Expand All @@ -212,7 +212,7 @@ open class FloatingPanelController: UIViewController {

/// The behavior object that the controller manages
@objc
public var behavior: FloatingPanelBehavior {
public var behavior: any FloatingPanelBehavior {
get { _behavior }
set {
_behavior = newValue
Expand Down Expand Up @@ -283,7 +283,7 @@ open class FloatingPanelController: UIViewController {

/// Initialize a newly created panel controller.
@objc
public init(delegate: FloatingPanelControllerDelegate? = nil) {
public init(delegate: (any FloatingPanelControllerDelegate)? = nil) {
super.init(nibName: nil, bundle: nil)
self.delegate = delegate
setUp()
Expand All @@ -295,7 +295,7 @@ open class FloatingPanelController: UIViewController {
modalPresentationStyle = .custom
transitioningDelegate = modalTransition

let initialLayout: FloatingPanelLayout
let initialLayout: any FloatingPanelLayout
if let layout = delegate?.floatingPanel?(self, layoutFor: traitCollection) {
initialLayout = layout
} else {
Expand Down Expand Up @@ -345,7 +345,7 @@ open class FloatingPanelController: UIViewController {
floatingPanel.adjustScrollContentInsetIfNeeded()
}

open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
open override func viewWillTransition(to size: CGSize, with coordinator: any UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)

if self.view.bounds.size == size {
Expand All @@ -364,7 +364,7 @@ open class FloatingPanelController: UIViewController {
}
}

open override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
open override func willTransition(to newCollection: UITraitCollection, with coordinator: any UIViewControllerTransitionCoordinator) {
super.willTransition(to: newCollection, with: coordinator)

if shouldUpdateLayout(from: traitCollection, to: newCollection) == false {
Expand Down
8 changes: 4 additions & 4 deletions Sources/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Core: NSObject, UIGestureRecognizerDelegate {

// MARK: - Interface

init(_ vc: FloatingPanelController, layout: FloatingPanelLayout, behavior: FloatingPanelBehavior) {
init(_ vc: FloatingPanelController, layout: any FloatingPanelLayout, behavior: any FloatingPanelBehavior) {
ownerVC = vc

surfaceView = SurfaceView()
Expand Down Expand Up @@ -1245,7 +1245,7 @@ public final class FloatingPanelPanGestureRecognizer: UIPanGestureRecognizer {
///
/// - Note: The delegate is used by FloatingPanel itself. If you set your own delegate object, an
/// exception is raised. If you want to handle the methods of UIGestureRecognizerDelegate, you can use `delegateProxy`.
public override weak var delegate: UIGestureRecognizerDelegate? {
public override weak var delegate: (any UIGestureRecognizerDelegate)? {
get {
return super.delegate
}
Expand All @@ -1266,15 +1266,15 @@ public final class FloatingPanelPanGestureRecognizer: UIPanGestureRecognizer {
/// The default object implementing a set methods of the delegate of the gesture recognizer.
///
/// Use this property with ``delegateProxy`` when you need to use the default gesture behaviors in a proxy implementation.
public var delegateOrigin: UIGestureRecognizerDelegate {
public var delegateOrigin: any UIGestureRecognizerDelegate {
return floatingPanel
}

/// A proxy object to intercept the default behavior of the gesture recognizer.
///
/// `UIGestureRecognizerDelegate` methods implementing by this object are called instead of the default delegate,
/// ``delegateOrigin``.
public weak var delegateProxy: UIGestureRecognizerDelegate? {
public weak var delegateProxy: (any UIGestureRecognizerDelegate)? {
didSet {
self.delegate = floatingPanel?.panGestureDelegateRouter // Update the cached IMP
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import os.log
@objc var initialState: FloatingPanelState { get }

/// Returns the layout anchors to specify the snapping locations for each state.
@objc var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] { get }
@objc var anchors: [FloatingPanelState: any FloatingPanelLayoutAnchoring] { get }

/// Returns layout constraints to determine the cross dimension of a panel.
@objc optional func prepareLayout(surfaceView: UIView, in view: UIView) -> [NSLayoutConstraint]
Expand All @@ -32,7 +32,7 @@ open class FloatingPanelBottomLayout: NSObject, FloatingPanelLayout {
return .half
}

open var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] {
open var anchors: [FloatingPanelState: any FloatingPanelLayoutAnchoring] {
return [
.full: FloatingPanelLayoutAnchor(absoluteInset: 18.0, edge: .top, referenceGuide: .safeArea),
.half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea),
Expand Down Expand Up @@ -66,7 +66,7 @@ class LayoutAdapter {
private unowned var vc: FloatingPanelController
private let defaultLayout = FloatingPanelBottomLayout()

fileprivate var layout: FloatingPanelLayout {
fileprivate var layout: any FloatingPanelLayout {
didSet {
surfaceView.position = position
}
Expand Down Expand Up @@ -289,7 +289,7 @@ class LayoutAdapter {
return offset.rounded(by: surfaceView.fp_displayScale)
}

private var hiddenAnchor: FloatingPanelLayoutAnchoring {
private var hiddenAnchor: any FloatingPanelLayoutAnchoring {
switch position {
case .top:
return FloatingPanelLayoutAnchor(absoluteInset: -100, edge: .top, referenceGuide: .superview)
Expand All @@ -302,7 +302,7 @@ class LayoutAdapter {
}
}

init(vc: FloatingPanelController, layout: FloatingPanelLayout) {
init(vc: FloatingPanelController, layout: any FloatingPanelLayout) {
self.vc = vc
self.layout = layout
}
Expand Down Expand Up @@ -406,7 +406,7 @@ class LayoutAdapter {
}
}

private func referenceEdge(of anchor: FloatingPanelLayoutAnchoring) -> FloatingPanelReferenceEdge {
private func referenceEdge(of anchor: any FloatingPanelLayoutAnchoring) -> FloatingPanelReferenceEdge {
switch anchor {
case is FloatingPanelIntrinsicLayoutAnchor,
is FloatingPanelAdaptiveLayoutAnchor:
Expand Down Expand Up @@ -548,7 +548,7 @@ class LayoutAdapter {
NSLayoutConstraint.deactivate(constraint: interactionConstraint)
interactionConstraint = nil

let layoutGuideProvider: LayoutGuideProvider
let layoutGuideProvider: any LayoutGuideProvider
switch anchor.referenceGuide {
case .safeArea:
layoutGuideProvider = vc.view.safeAreaLayoutGuide
Expand Down Expand Up @@ -856,7 +856,7 @@ extension LayoutAdapter {
}

extension FloatingPanelController {
var _layout: FloatingPanelLayout {
var _layout: any FloatingPanelLayout {
get {
floatingPanel.layoutAdapter.layout
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/LayoutAnchoring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public extension FloatingPanelLayoutAnchor {
}
}

private func layoutConstraints(_ layoutGuide: LayoutGuideProvider, for edgeAnchor: NSLayoutYAxisAnchor) -> [NSLayoutConstraint] {
private func layoutConstraints(_ layoutGuide: any LayoutGuideProvider, for edgeAnchor: NSLayoutYAxisAnchor) -> [NSLayoutConstraint] {
switch referenceEdge {
case .top:
if isAbsolute {
Expand All @@ -85,7 +85,7 @@ public extension FloatingPanelLayoutAnchor {
}
}

private func layoutConstraints(_ layoutGuide: LayoutGuideProvider, for edgeAnchor: NSLayoutXAxisAnchor) -> [NSLayoutConstraint] {
private func layoutConstraints(_ layoutGuide: any LayoutGuideProvider, for edgeAnchor: NSLayoutXAxisAnchor) -> [NSLayoutConstraint] {
switch referenceEdge {
case .left:
if isAbsolute {
Expand Down
4 changes: 2 additions & 2 deletions Sources/LayoutProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension FloatingPanelReferenceEdge {
}

extension FloatingPanelLayoutReferenceGuide {
func layoutGuide(vc: UIViewController) -> LayoutGuideProvider {
func layoutGuide(vc: UIViewController) -> any LayoutGuideProvider {
switch self {
case .safeArea:
return vc.view.safeAreaLayoutGuide
Expand All @@ -55,7 +55,7 @@ extension FloatingPanelLayoutReferenceGuide {
}

extension FloatingPanelLayoutContentBoundingGuide {
func layoutGuide(_ fpc: FloatingPanelController) -> LayoutGuideProvider? {
func layoutGuide(_ fpc: FloatingPanelController) -> (any LayoutGuideProvider)? {
switch self {
case .superview:
return fpc.view
Expand Down
2 changes: 1 addition & 1 deletion Sources/Position.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension FloatingPanelPosition {
}
}

func mainDimensionAnchor(_ layoutGuide: LayoutGuideProvider) -> NSLayoutDimension {
func mainDimensionAnchor(_ layoutGuide: any LayoutGuideProvider) -> NSLayoutDimension {
switch self {
case .top, .bottom: return layoutGuide.heightAnchor
case .left, .right: return layoutGuide.widthAnchor
Expand Down
16 changes: 8 additions & 8 deletions Sources/Transitioning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import UIKit
class ModalTransition: NSObject, UIViewControllerTransitioningDelegate {
func animationController(forPresented presented: UIViewController,
presenting: UIViewController,
source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
source: UIViewController) -> (any UIViewControllerAnimatedTransitioning)? {
return ModalPresentTransition()
}

func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
func animationController(forDismissed dismissed: UIViewController) -> (any UIViewControllerAnimatedTransitioning)? {
return ModalDismissTransition()
}

Expand Down Expand Up @@ -81,7 +81,7 @@ class PresentationController: UIPresentationController {
}

class ModalPresentTransition: NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
func transitionDuration(using transitionContext: (any UIViewControllerContextTransitioning)?) -> TimeInterval {
guard
let fpc = transitionContext?.viewController(forKey: .to) as? FloatingPanelController
else { fatalError()}
Expand All @@ -90,7 +90,7 @@ class ModalPresentTransition: NSObject, UIViewControllerAnimatedTransitioning {
return TimeInterval(animator.duration)
}

func interruptibleAnimator(using transitionContext: UIViewControllerContextTransitioning) -> UIViewImplicitlyAnimating {
func interruptibleAnimator(using transitionContext: any UIViewControllerContextTransitioning) -> any UIViewImplicitlyAnimating {
guard
let fpc = transitionContext.viewController(forKey: .to) as? FloatingPanelController
else { fatalError() }
Expand All @@ -110,13 +110,13 @@ class ModalPresentTransition: NSObject, UIViewControllerAnimatedTransitioning {
return transitionAnimator
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
func animateTransition(using transitionContext: any UIViewControllerContextTransitioning) {
self.interruptibleAnimator(using: transitionContext).startAnimation()
}
}

class ModalDismissTransition: NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
func transitionDuration(using transitionContext: (any UIViewControllerContextTransitioning)?) -> TimeInterval {
guard
let fpc = transitionContext?.viewController(forKey: .from) as? FloatingPanelController
else { fatalError()}
Expand All @@ -125,7 +125,7 @@ class ModalDismissTransition: NSObject, UIViewControllerAnimatedTransitioning {
return TimeInterval(animator.duration)
}

func interruptibleAnimator(using transitionContext: UIViewControllerContextTransitioning) -> UIViewImplicitlyAnimating {
func interruptibleAnimator(using transitionContext: any UIViewControllerContextTransitioning) -> any UIViewImplicitlyAnimating {
guard
let fpc = transitionContext.viewController(forKey: .from) as? FloatingPanelController
else { fatalError() }
Expand All @@ -142,7 +142,7 @@ class ModalDismissTransition: NSObject, UIViewControllerAnimatedTransitioning {
return fpc.transitionAnimator!
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
func animateTransition(using transitionContext: any UIViewControllerContextTransitioning) {
self.interruptibleAnimator(using: transitionContext).startAnimation()
}
}
Expand Down

0 comments on commit da31639

Please sign in to comment.