From 71be1f2ed56d5d331c5e0886eefe7a965f2ad124 Mon Sep 17 00:00:00 2001 From: Shin Yamamoto Date: Sat, 27 Oct 2018 10:21:44 +0900 Subject: [PATCH] Change the type of 'supportedPositions' from Array to Set --- Examples/Samples/Sources/ViewController.swift | 4 ++-- Framework/Sources/FloatingPanel.swift | 8 ++++---- Framework/Sources/FloatingPanelController.swift | 2 +- Framework/Sources/FloatingPanelLayout.swift | 10 +++++----- README.md | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Examples/Samples/Sources/ViewController.swift b/Examples/Samples/Sources/ViewController.swift index 109673f..0f17c69 100644 --- a/Examples/Samples/Sources/ViewController.swift +++ b/Examples/Samples/Sources/ViewController.swift @@ -373,7 +373,7 @@ class OneTabBarPanelLayout: FloatingPanelLayout { var initialPosition: FloatingPanelPosition { return .tip } - var supportedPositions: [FloatingPanelPosition] { + var supportedPositions: Set { return [.full, .tip] } @@ -390,7 +390,7 @@ class TwoTabBarPanel2Layout: FloatingPanelLayout { var initialPosition: FloatingPanelPosition { return .half } - var supportedPositions: [FloatingPanelPosition] { + var supportedPositions: Set { return [.full, .half] } var bottomInteractionBuffer: CGFloat { diff --git a/Framework/Sources/FloatingPanel.swift b/Framework/Sources/FloatingPanel.swift index 930ed44..83e06fa 100644 --- a/Framework/Sources/FloatingPanel.swift +++ b/Framework/Sources/FloatingPanel.swift @@ -373,16 +373,16 @@ class FloatingPanel: NSObject, UIGestureRecognizerDelegate, UIScrollViewDelegate private func targetPosition(with translation: CGPoint, velocity: CGPoint) -> (FloatingPanelPosition) { let currentY = getCurrentY(from: initialFrame, with: translation) - let supportedPositions = Set(layoutAdapter.layout.supportedPositions) + let supportedPositions: Set = layoutAdapter.layout.supportedPositions assert(supportedPositions.count > 1) switch supportedPositions { - case Set([.full, .half]): + case [.full, .half]: return targetPosition(from: [.full, .half], at: currentY, velocity: velocity) - case Set([.half, .tip]): + case [.half, .tip]: return targetPosition(from: [.half, .tip], at: currentY, velocity: velocity) - case Set([.full, .tip]): + case [.full, .tip]: return targetPosition(from: [.full, .tip], at: currentY, velocity: velocity) default: /* diff --git a/Framework/Sources/FloatingPanelController.swift b/Framework/Sources/FloatingPanelController.swift index c053144..8d1e1ad 100644 --- a/Framework/Sources/FloatingPanelController.swift +++ b/Framework/Sources/FloatingPanelController.swift @@ -36,7 +36,7 @@ public extension FloatingPanelControllerDelegate { func floatingPanelDidEndDecelerating(_ vc: FloatingPanelController) {} } -public enum FloatingPanelPosition: Int { +public enum FloatingPanelPosition: Int, CaseIterable { case full case half case tip diff --git a/Framework/Sources/FloatingPanelLayout.swift b/Framework/Sources/FloatingPanelLayout.swift index 413f7df..4b317e0 100644 --- a/Framework/Sources/FloatingPanelLayout.swift +++ b/Framework/Sources/FloatingPanelLayout.swift @@ -9,8 +9,8 @@ public protocol FloatingPanelLayout: class { /// Returns the initial position of a floating panel. var initialPosition: FloatingPanelPosition { get } - /// Returns an array of FloatingPanelPosition objects to tell the applicable positions of the floating panel controller. Default is all of them. - var supportedPositions: [FloatingPanelPosition] { get } + /// Returns a set of FloatingPanelPosition objects to tell the applicable positions of the floating panel controller. Default is all of them. + var supportedPositions: Set { get } /// Return the interaction buffer to the top from the top position. Default is 6.0. var topInteractionBuffer: CGFloat { get } @@ -39,8 +39,8 @@ public extension FloatingPanelLayout { var topInteractionBuffer: CGFloat { return 6.0 } var bottomInteractionBuffer: CGFloat { return 6.0 } - public var supportedPositions: [FloatingPanelPosition] { - return [.full, .half, .tip] + public var supportedPositions: Set { + return Set(FloatingPanelPosition.allCases) } func prepareLayout(surfaceView: UIView, in view: UIView) -> [NSLayoutConstraint] { @@ -69,7 +69,7 @@ public class FloatingPanelDefaultLandscapeLayout: FloatingPanelLayout { public var initialPosition: FloatingPanelPosition { return .tip } - public var supportedPositions: [FloatingPanelPosition] { + public var supportedPositions: Set { return [.full, .tip] } diff --git a/README.md b/README.md index f4d6d55..5aba646 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ class FloatingPanelLandscapeLayout: FloatingPanelLayout { public var initialPosition: FloatingPanelPosition { return .tip } - public var supportedPositions: [FloatingPanelPosition] { + public var supportedPositions: Set { return [.full, .tip] }