Compare commits

..

No commits in common. "master" and "1.2.3" have entirely different histories.

23 changed files with 131 additions and 388 deletions

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

View File

@ -1,22 +0,0 @@
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "PanModal",
platforms: [.iOS(.v10)],
products: [
.library(
name: "PanModal",
targets: ["PanModal"]),
],
dependencies: [],
targets: [
.target(
name: "PanModal",
dependencies: [],
path: "PanModal")
],
swiftLanguageVersions: [.version("5.0")]
)

View File

@ -8,7 +8,7 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'PanModal' s.name = 'PanModal'
s.version = '1.3.1' s.version = '1.2.3'
s.summary = 'PanModal is an elegant and highly customizable presentation API for constructing bottom sheet modals on iOS.' s.summary = 'PanModal is an elegant and highly customizable presentation API for constructing bottom sheet modals on iOS.'
# This description is used to generate tags and improve search results. # This description is used to generate tags and improve search results.
@ -18,12 +18,12 @@ Pod::Spec.new do |s|
# * Finally, don't worry about the indent, CocoaPods strips it! # * Finally, don't worry about the indent, CocoaPods strips it!
s.description = 'PanModal is an elegant and highly customizable presentation API for constructing bottom sheet modals on iOS.' s.description = 'PanModal is an elegant and highly customizable presentation API for constructing bottom sheet modals on iOS.'
s.homepage = 'https://git.svc.touchin.ru/TouchInstinct/PanModal' s.homepage = 'https://github.com/slackhq/PanModal'
s.license = { :type => 'MIT', :file => 'LICENSE' } s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'slack' => 'opensource@slack.com' } s.author = { 'slack' => 'opensource@slack.com' }
s.source = { :git => 'https://git.svc.touchin.ru/TouchInstinct/PanModal.git', :tag => s.version.to_s } s.source = { :git => 'https://github.com/slackhq/PanModal.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/slackhq' s.social_media_url = 'https://twitter.com/slackhq'
s.ios.deployment_target = '10.0' s.ios.deployment_target = '10.0'
s.swift_version = '5.0' s.swift_version = '4.2'
s.source_files = 'PanModal/**/*.{swift,h,m}' s.source_files = 'PanModal/**/*.{swift,h,m}'
end end

View File

@ -5,7 +5,6 @@
// Copyright © 2019 Tiny Speck, Inc. All rights reserved. // Copyright © 2019 Tiny Speck, Inc. All rights reserved.
// //
#if os(iOS)
import UIKit import UIKit
/** /**
@ -37,4 +36,3 @@ struct PanModalAnimator {
completion: completion) completion: completion)
} }
} }
#endif

View File

@ -5,7 +5,6 @@
// Copyright © 2019 Tiny Speck, Inc. All rights reserved. // Copyright © 2019 Tiny Speck, Inc. All rights reserved.
// //
#if os(iOS)
import UIKit import UIKit
/** /**
@ -73,6 +72,7 @@ public class PanModalPresentationAnimator: NSObject {
// Calls viewWillAppear and viewWillDisappear // Calls viewWillAppear and viewWillDisappear
fromVC.beginAppearanceTransition(false, animated: true) fromVC.beginAppearanceTransition(false, animated: true)
toVC.beginAppearanceTransition(true, animated: true)
// Presents the view in shortForm position, initially // Presents the view in shortForm position, initially
let yPos: CGFloat = presentable?.shortFormYPos ?? 0.0 let yPos: CGFloat = presentable?.shortFormYPos ?? 0.0
@ -94,6 +94,7 @@ public class PanModalPresentationAnimator: NSObject {
}, config: presentable) { [weak self] didComplete in }, config: presentable) { [weak self] didComplete in
// Calls viewDidAppear and viewDidDisappear // Calls viewDidAppear and viewDidDisappear
fromVC.endAppearanceTransition() fromVC.endAppearanceTransition()
toVC.endAppearanceTransition()
transitionContext.completeTransition(didComplete) transitionContext.completeTransition(didComplete)
self?.feedbackGenerator = nil self?.feedbackGenerator = nil
} }
@ -110,6 +111,7 @@ public class PanModalPresentationAnimator: NSObject {
else { return } else { return }
// Calls viewWillAppear and viewWillDisappear // Calls viewWillAppear and viewWillDisappear
fromVC.beginAppearanceTransition(false, animated: true)
toVC.beginAppearanceTransition(true, animated: true) toVC.beginAppearanceTransition(true, animated: true)
let presentable = panModalLayoutType(from: transitionContext) let presentable = panModalLayoutType(from: transitionContext)
@ -120,6 +122,7 @@ public class PanModalPresentationAnimator: NSObject {
}, config: presentable) { didComplete in }, config: presentable) { didComplete in
fromVC.view.removeFromSuperview() fromVC.view.removeFromSuperview()
// Calls viewDidAppear and viewDidDisappear // Calls viewDidAppear and viewDidDisappear
fromVC.endAppearanceTransition()
toVC.endAppearanceTransition() toVC.endAppearanceTransition()
transitionContext.completeTransition(didComplete) transitionContext.completeTransition(didComplete)
} }
@ -169,4 +172,3 @@ extension PanModalPresentationAnimator: UIViewControllerAnimatedTransitioning {
} }
} }
#endif

View File

@ -5,7 +5,6 @@
// Copyright © 2019 Tiny Speck, Inc. All rights reserved. // Copyright © 2019 Tiny Speck, Inc. All rights reserved.
// //
#if os(iOS)
import UIKit import UIKit
/** /**
@ -23,14 +22,13 @@ import UIKit
By conforming to the PanModalPresentable protocol & overriding values By conforming to the PanModalPresentable protocol & overriding values
the presented view can define its layout configuration & presentation. the presented view can define its layout configuration & presentation.
*/ */
open class PanModalPresentationController: UIPresentationController { public class PanModalPresentationController: UIPresentationController {
/** /**
Enum representing the possible presentation states Enum representing the possible presentation states
*/ */
public enum PresentationState { public enum PresentationState {
case shortForm case shortForm
case mediumForm
case longForm case longForm
} }
@ -80,17 +78,11 @@ open class PanModalPresentationController: UIPresentationController {
*/ */
private var shortFormYPosition: CGFloat = 0 private var shortFormYPosition: CGFloat = 0
private var mediumFormYPosition: CGFloat = 0
/** /**
The y value for the long form presentation state The y value for the long form presentation state
*/ */
private var longFormYPosition: CGFloat = 0 private var longFormYPosition: CGFloat = 0
private var allowsDragToDismiss: Bool {
presentable?.onDragToDismiss != nil
}
/** /**
Determine anchored Y postion based on the `anchorModalToLongForm` flag Determine anchored Y postion based on the `anchorModalToLongForm` flag
*/ */
@ -112,14 +104,14 @@ open class PanModalPresentationController: UIPresentationController {
Background view used as an overlay over the presenting view Background view used as an overlay over the presenting view
*/ */
private lazy var backgroundView: DimmedView = { private lazy var backgroundView: DimmedView = {
let view: DimmedView = presentable?.dimmedView ?? DimmedView() let view: DimmedView
if let color = presentable?.panModalBackgroundColor { if let alpha = presentable?.backgroundAlpha {
view.backgroundColor = color view = DimmedView(dimAlpha: alpha)
} else {
view = DimmedView()
} }
view.didTap = { [weak self] _ in view.didTap = { [weak self] _ in
if self?.presentable?.allowsTapToDismiss == true { self?.dismissPresentedViewController()
self?.presentable?.onTapToDismiss?()
}
} }
return view return view
}() }()
@ -139,7 +131,7 @@ open class PanModalPresentationController: UIPresentationController {
*/ */
private lazy var dragIndicatorView: UIView = { private lazy var dragIndicatorView: UIView = {
let view = UIView() let view = UIView()
view.backgroundColor = presentable?.dragIndicatorBackgroundColor view.backgroundColor = .lightGray
view.layer.cornerRadius = Constants.dragIndicatorSize.height / 2.0 view.layer.cornerRadius = Constants.dragIndicatorSize.height / 2.0
return view return view
}() }()
@ -192,21 +184,12 @@ open class PanModalPresentationController: UIPresentationController {
} }
coordinator.animate(alongsideTransition: { [weak self] _ in coordinator.animate(alongsideTransition: { [weak self] _ in
if let yPos = self?.shortFormYPosition { self?.backgroundView.dimState = .max
self?.adjust(toYPosition: yPos)
}
self?.presentedViewController.setNeedsStatusBarAppearanceUpdate() self?.presentedViewController.setNeedsStatusBarAppearanceUpdate()
}) })
} }
override public func presentationTransitionDidEnd(_ completed: Bool) {
if completed { return }
backgroundView.removeFromSuperview()
}
override public func dismissalTransitionWillBegin() { override public func dismissalTransitionWillBegin() {
presentable?.panModalWillDismiss()
guard let coordinator = presentedViewController.transitionCoordinator else { guard let coordinator = presentedViewController.transitionCoordinator else {
backgroundView.dimState = .off backgroundView.dimState = .off
@ -224,10 +207,10 @@ open class PanModalPresentationController: UIPresentationController {
}) })
} }
override public func dismissalTransitionDidEnd(_ completed: Bool) { override public func presentationTransitionDidEnd(_ completed: Bool) {
if !completed { return } if completed { return }
presentable?.panModalDidDismiss() backgroundView.removeFromSuperview()
} }
/** /**
@ -243,6 +226,7 @@ open class PanModalPresentationController: UIPresentationController {
else { return } else { return }
self.adjustPresentedViewFrame() self.adjustPresentedViewFrame()
if presentable.shouldRoundTopCorners { if presentable.shouldRoundTopCorners {
self.addRoundedCorners(to: self.presentedView) self.addRoundedCorners(to: self.presentedView)
} }
@ -269,37 +253,41 @@ public extension PanModalPresentationController {
switch state { switch state {
case .shortForm: case .shortForm:
snap(toYPosition: shortFormYPosition) snap(toYPosition: shortFormYPosition)
case .mediumForm:
snap(toYPosition: mediumFormYPosition)
case .longForm: case .longForm:
snap(toYPosition: longFormYPosition) snap(toYPosition: longFormYPosition)
} }
} }
/** /**
Operations on the scroll view, such as content height changes, Set the content offset of the scroll view
or when inserting/deleting rows can cause the pan modal to jump,
caused by the pan modal responding to content offset changes.
To avoid this, you can call this method to perform scroll view updates, Due to content offset observation, its not possible to programmatically
with scroll observation temporarily disabled. set the content offset directly on the scroll view while in the short form.
This method pauses the content offset KVO, performs the content offset change
and then resumes content offset observation.
*/ */
func performUpdates(_ updates: () -> Void) { func setContentOffset(offset: CGPoint) {
guard let scrollView = presentable?.panScrollable guard let scrollView = presentable?.panScrollable
else { return } else { return }
// Pause scroll observer /**
Invalidate scroll view observer
to prevent its overriding the content offset change
*/
scrollObserver?.invalidate() scrollObserver?.invalidate()
scrollObserver = nil scrollObserver = nil
// Perform updates /**
updates() Set scroll view offset & track scrolling
*/
// Resume scroll observer scrollView.setContentOffset(offset, animated:false)
trackScrolling(scrollView) trackScrolling(scrollView)
/**
Add the scroll view observer
*/
observe(scrollView: scrollView) observe(scrollView: scrollView)
} }
@ -329,7 +317,7 @@ private extension PanModalPresentationController {
var isPresentedViewAnchored: Bool { var isPresentedViewAnchored: Bool {
if !isPresentedViewAnimating if !isPresentedViewAnimating
&& extendsPanScrolling && extendsPanScrolling
&& presentedView.frame.minY.rounded() <= anchoredYPosition.rounded() { && presentedView.frame.minY <= anchoredYPosition {
return true return true
} }
@ -379,18 +367,7 @@ private extension PanModalPresentationController {
else { return } else { return }
let adjustedSize = CGSize(width: frame.size.width, height: frame.size.height - anchoredYPosition) let adjustedSize = CGSize(width: frame.size.width, height: frame.size.height - anchoredYPosition)
let panFrame = panContainerView.frame
panContainerView.frame.size = frame.size panContainerView.frame.size = frame.size
let positions = [shortFormYPosition, mediumFormYPosition, longFormYPosition]
if !positions.contains(panFrame.origin.y) {
// if the container is already in the correct position, no need to adjust positioning
// (rotations & size changes cause positioning to be out of sync)
let yPosition = panFrame.origin.y - panFrame.height + frame.height
presentedView.frame.origin.y = max(yPosition, anchoredYPosition)
}
panContainerView.frame.origin.x = frame.origin.x
presentedViewController.view.frame = CGRect(origin: .zero, size: adjustedSize) presentedViewController.view.frame = CGRect(origin: .zero, size: adjustedSize)
} }
@ -439,7 +416,6 @@ private extension PanModalPresentationController {
else { return } else { return }
shortFormYPosition = layoutPresentable.shortFormYPos shortFormYPosition = layoutPresentable.shortFormYPos
mediumFormYPosition = layoutPresentable.mediumFormYPos
longFormYPosition = layoutPresentable.longFormYPos longFormYPosition = layoutPresentable.longFormYPos
anchorModalToLongForm = layoutPresentable.anchorModalToLongForm anchorModalToLongForm = layoutPresentable.anchorModalToLongForm
extendsPanScrolling = layoutPresentable.allowsExtendedPanScrolling extendsPanScrolling = layoutPresentable.allowsExtendedPanScrolling
@ -468,15 +444,7 @@ private extension PanModalPresentationController {
Set the appropriate contentInset as the configuration within this class Set the appropriate contentInset as the configuration within this class
offsets it offsets it
*/ */
let bottomInset: CGFloat scrollView.contentInset.bottom = presentingViewController.bottomLayoutGuide.length
if #available(iOS 11.0, *) {
bottomInset = presentingViewController.view.safeAreaInsets.bottom
} else {
bottomInset = presentingViewController.bottomLayoutGuide.length
}
scrollView.contentInset.bottom = bottomInset
/** /**
As we adjust the bounds during `handleScrollViewTopBounce` As we adjust the bounds during `handleScrollViewTopBounce`
@ -540,18 +508,12 @@ private extension PanModalPresentationController {
if velocity.y < 0 { if velocity.y < 0 {
transition(to: .longForm) transition(to: .longForm)
} else if nearest(to: presentedView.frame.minY, } else if (nearest(to: presentedView.frame.minY, inValues: [longFormYPosition, containerView.bounds.height]) == longFormYPosition
inValues: [mediumFormYPosition, containerView.bounds.height]) == mediumFormYPosition && presentedView.frame.minY < shortFormYPosition) || presentable?.allowsDragToDismiss == false {
&& presentedView.frame.minY < mediumFormYPosition {
transition(to: .mediumForm)
} else if (nearest(to: presentedView.frame.minY,
inValues: [longFormYPosition, containerView.bounds.height]) == longFormYPosition
&& presentedView.frame.minY < shortFormYPosition) || allowsDragToDismiss == false {
transition(to: .shortForm) transition(to: .shortForm)
} else { } else {
presentable?.onDragToDismiss?() dismissPresentedViewController()
} }
} else { } else {
@ -560,23 +522,16 @@ private extension PanModalPresentationController {
The `containerView.bounds.height` is used to determine The `containerView.bounds.height` is used to determine
how close the presented view is to the bottom of the screen how close the presented view is to the bottom of the screen
*/ */
let position = nearest(to: presentedView.frame.minY, let position = nearest(to: presentedView.frame.minY, inValues: [containerView.bounds.height, shortFormYPosition, longFormYPosition])
inValues: [containerView.bounds.height,
shortFormYPosition,
mediumFormYPosition,
longFormYPosition])
if position == longFormYPosition { if position == longFormYPosition {
transition(to: .longForm) transition(to: .longForm)
} else if position == mediumFormYPosition {
transition(to: .mediumForm)
} else if position == shortFormYPosition || allowsDragToDismiss == false { } else if position == shortFormYPosition || presentable?.allowsDragToDismiss == false {
transition(to: .shortForm) transition(to: .shortForm)
} else { } else {
presentable?.onDragToDismiss?() dismissPresentedViewController()
} }
} }
} }
@ -688,10 +643,19 @@ private extension PanModalPresentationController {
*/ */
func adjust(toYPosition yPos: CGFloat) { func adjust(toYPosition yPos: CGFloat) {
presentedView.frame.origin.y = max(yPos, anchoredYPosition) presentedView.frame.origin.y = max(yPos, anchoredYPosition)
guard presentedView.frame.origin.y > shortFormYPosition else {
backgroundView.dimState = .max
return
}
let maxHeight = UIScreen.main.bounds.height - longFormYPosition let yDisplacementFromShortForm = presentedView.frame.origin.y - shortFormYPosition
backgroundView.dimState = .percent(1.0 - presentedView.frame.origin.y / maxHeight) /**
Once presentedView is translated below shortForm, calculate yPos relative to bottom of screen
and apply percentage to backgroundView alpha
*/
backgroundView.dimState = .percent(1.0 - (yDisplacementFromShortForm / presentedView.frame.height))
} }
/** /**
@ -706,6 +670,14 @@ private extension PanModalPresentationController {
else { return number } else { return number }
return nearestVal return nearestVal
} }
/**
Dismiss presented view
*/
func dismissPresentedViewController() {
presentable?.panModalWillDismiss()
presentedViewController.dismiss(animated: true, completion: nil)
}
} }
// MARK: - UIScrollView Observer // MARK: - UIScrollView Observer
@ -810,7 +782,7 @@ private extension PanModalPresentationController {
*/ */
func handleScrollViewTopBounce(scrollView: UIScrollView, change: NSKeyValueObservedChange<CGPoint>) { func handleScrollViewTopBounce(scrollView: UIScrollView, change: NSKeyValueObservedChange<CGPoint>) {
guard let oldYValue = change.oldValue?.y, scrollView.isDecelerating guard let oldYValue = change.oldValue?.y
else { return } else { return }
let yOffset = scrollView.contentOffset.y let yOffset = scrollView.contentOffset.y
@ -850,11 +822,11 @@ extension PanModalPresentationController: UIGestureRecognizerDelegate {
} }
/** /**
Allow simultaneous gesture recognizers only when the other gesture recognizer's view Allow simultaneous gesture recognizers only when the other gesture recognizer
is the pan scrollable view is a pan gesture recognizer
*/ */
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return otherGestureRecognizer.view == presentable?.panScrollable return otherGestureRecognizer == panGestureRecognizer
} }
} }
@ -915,4 +887,3 @@ private extension UIScrollView {
return isDragging && !isDecelerating || isTracking return isDragging && !isDecelerating || isTracking
} }
} }
#endif

View File

@ -5,7 +5,6 @@
// Copyright © 2019 Tiny Speck, Inc. All rights reserved. // Copyright © 2019 Tiny Speck, Inc. All rights reserved.
// //
#if os(iOS)
import UIKit import UIKit
/** /**
@ -78,4 +77,3 @@ extension PanModalPresentationDelegate: UIAdaptivePresentationControllerDelegate
} }
} }
#endif

View File

@ -1,66 +0,0 @@
//
// Copyright (c) 2022 Touch Instinct
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the Software), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
import Foundation
public struct ModalViewPresentationDetent: Hashable {
// MARK: - Default Values
public static var headerOnly: ModalViewPresentationDetent {
ModalViewPresentationDetent(height: CGFloat(Int.min))
}
public static func height(_ height: CGFloat) -> ModalViewPresentationDetent {
ModalViewPresentationDetent(height: height)
}
public static var maxHeight: ModalViewPresentationDetent {
ModalViewPresentationDetent(height: CGFloat(Int.max))
}
// MARK: - Public Properties
public var height: CGFloat
// MARK: - Internal Methods
func panModalHeight(headerHeight: CGFloat = .zero) -> PanModalHeight {
if self == .headerOnly {
return .contentHeight(headerHeight)
}
if self == .maxHeight {
return .maxHeight
}
return .contentHeight(height)
}
}
// MARK: - Comparable
extension ModalViewPresentationDetent: Comparable {
public static func < (lhs: ModalViewPresentationDetent, rhs: ModalViewPresentationDetent) -> Bool {
lhs.height < rhs.height
}
}

View File

@ -5,7 +5,6 @@
// Copyright © 2019 Tiny Speck, Inc. All rights reserved. // Copyright © 2019 Tiny Speck, Inc. All rights reserved.
// //
#if os(iOS)
import UIKit import UIKit
/** /**
@ -41,4 +40,3 @@ public enum PanModalHeight: Equatable {
*/ */
case intrinsicHeight case intrinsicHeight
} }
#endif

View File

@ -5,7 +5,6 @@
// Copyright © 2018 Tiny Speck, Inc. All rights reserved. // Copyright © 2018 Tiny Speck, Inc. All rights reserved.
// //
#if os(iOS)
import UIKit import UIKit
/** /**
@ -13,30 +12,14 @@ import UIKit
*/ */
public extension PanModalPresentable where Self: UIViewController { public extension PanModalPresentable where Self: UIViewController {
var onTapToDismiss: (() -> Void)? {
{ [weak self] in
self?.dismiss(animated: true)
}
}
var onDragToDismiss: (() -> Void)? {
{ [weak self] in
self?.dismiss(animated: true)
}
}
var topOffset: CGFloat { var topOffset: CGFloat {
topLayoutOffset return topLayoutOffset + 21.0
} }
var shortFormHeight: PanModalHeight { var shortFormHeight: PanModalHeight {
return longFormHeight return longFormHeight
} }
var mediumFormHeight: PanModalHeight {
longFormHeight
}
var longFormHeight: PanModalHeight { var longFormHeight: PanModalHeight {
guard let scrollView = panScrollable guard let scrollView = panScrollable
@ -47,10 +30,6 @@ public extension PanModalPresentable where Self: UIViewController {
return .contentHeight(scrollView.contentSize.height) return .contentHeight(scrollView.contentSize.height)
} }
var dimmedView: DimmedView? {
DimmedView()
}
var cornerRadius: CGFloat { var cornerRadius: CGFloat {
return 8.0 return 8.0
} }
@ -67,12 +46,8 @@ public extension PanModalPresentable where Self: UIViewController {
return [.curveEaseInOut, .allowUserInteraction, .beginFromCurrentState] return [.curveEaseInOut, .allowUserInteraction, .beginFromCurrentState]
} }
var panModalBackgroundColor: UIColor { var backgroundAlpha: CGFloat {
return UIColor.black.withAlphaComponent(0.7) return 0.7
}
var dragIndicatorBackgroundColor: UIColor {
return UIColor.lightGray
} }
var scrollIndicatorInsets: UIEdgeInsets { var scrollIndicatorInsets: UIEdgeInsets {
@ -97,10 +72,6 @@ public extension PanModalPresentable where Self: UIViewController {
return true return true
} }
var allowsTapToDismiss: Bool {
return true
}
var isUserInteractionEnabled: Bool { var isUserInteractionEnabled: Bool {
return true return true
} }
@ -141,8 +112,4 @@ public extension PanModalPresentable where Self: UIViewController {
} }
func panModalDidDismiss() {
}
} }
#endif

View File

@ -5,7 +5,6 @@
// Copyright © 2018 Tiny Speck, Inc. All rights reserved. // Copyright © 2018 Tiny Speck, Inc. All rights reserved.
// //
#if os(iOS)
import UIKit import UIKit
/** /**
@ -27,11 +26,7 @@ extension PanModalPresentable where Self: UIViewController {
Gives us the safe area inset from the top. Gives us the safe area inset from the top.
*/ */
var topLayoutOffset: CGFloat { var topLayoutOffset: CGFloat {
return UIApplication.shared.keyWindow?.rootViewController?.topLayoutGuide.length ?? 0
guard let rootVC = rootViewController
else { return 0}
if #available(iOS 11.0, *) { return rootVC.view.safeAreaInsets.top } else { return rootVC.topLayoutGuide.length }
} }
/** /**
@ -39,11 +34,7 @@ extension PanModalPresentable where Self: UIViewController {
Gives us the safe area inset from the bottom. Gives us the safe area inset from the bottom.
*/ */
var bottomLayoutOffset: CGFloat { var bottomLayoutOffset: CGFloat {
return UIApplication.shared.keyWindow?.rootViewController?.bottomLayoutGuide.length ?? 0
guard let rootVC = rootViewController
else { return 0}
if #available(iOS 11.0, *) { return rootVC.view.safeAreaInsets.bottom } else { return rootVC.bottomLayoutGuide.length }
} }
/** /**
@ -63,12 +54,6 @@ extension PanModalPresentable where Self: UIViewController {
return max(shortFormYPos, longFormYPos) return max(shortFormYPos, longFormYPos)
} }
var mediumFormYPos: CGFloat {
let mediumFormYPos = topMargin(from: mediumFormHeight)
return max(mediumFormYPos, longFormYPos)
}
/** /**
Returns the long form Y position Returns the long form Y position
@ -114,13 +99,4 @@ extension PanModalPresentable where Self: UIViewController {
} }
} }
private var rootViewController: UIViewController? {
guard let application = UIApplication.value(forKeyPath: #keyPath(UIApplication.shared)) as? UIApplication
else { return nil }
return application.keyWindow?.rootViewController
}
} }
#endif

View File

@ -5,7 +5,6 @@
// Copyright © 2018 Tiny Speck, Inc. All rights reserved. // Copyright © 2018 Tiny Speck, Inc. All rights reserved.
// //
#if os(iOS)
import UIKit import UIKit
/** /**
@ -30,6 +29,16 @@ public extension PanModalPresentable where Self: UIViewController {
presentedVC?.transition(to: state) presentedVC?.transition(to: state)
} }
/**
Programmatically set the content offset of the pan scrollable.
This is required to use while in the short form presentation state,
as due to content offset observation, setting the content offset directly would fail
*/
func panModalSetContentOffset(offset: CGPoint) {
presentedVC?.setContentOffset(offset: offset)
}
/** /**
A function wrapper over the `setNeedsLayoutUpdate()` A function wrapper over the `setNeedsLayoutUpdate()`
function in the PanModalPresentationController. function in the PanModalPresentationController.
@ -40,16 +49,6 @@ public extension PanModalPresentable where Self: UIViewController {
presentedVC?.setNeedsLayoutUpdate() presentedVC?.setNeedsLayoutUpdate()
} }
/**
Operations on the scroll view, such as content height changes, or when inserting/deleting rows can cause the pan modal to jump,
caused by the pan modal responding to content offset changes.
To avoid this, you can call this method to perform scroll view updates, with scroll observation temporarily disabled.
*/
func panModalPerformUpdates(_ updates: () -> Void) {
presentedVC?.performUpdates(updates)
}
/** /**
A function wrapper over the animate function in PanModalAnimator. A function wrapper over the animate function in PanModalAnimator.
@ -60,4 +59,3 @@ public extension PanModalPresentable where Self: UIViewController {
} }
} }
#endif

View File

@ -5,7 +5,6 @@
// Copyright © 2017 Tiny Speck, Inc. All rights reserved. // Copyright © 2017 Tiny Speck, Inc. All rights reserved.
// //
#if os(iOS)
import UIKit import UIKit
/** /**
@ -45,8 +44,6 @@ public protocol PanModalPresentable: AnyObject {
*/ */
var shortFormHeight: PanModalHeight { get } var shortFormHeight: PanModalHeight { get }
var mediumFormHeight: PanModalHeight { get }
/** /**
The height of the pan modal container view The height of the pan modal container view
when in the longForm presentation state. when in the longForm presentation state.
@ -57,7 +54,6 @@ public protocol PanModalPresentable: AnyObject {
*/ */
var longFormHeight: PanModalHeight { get } var longFormHeight: PanModalHeight { get }
var dimmedView: DimmedView? { get }
/** /**
The corner radius used when `shouldRoundTopCorners` is enabled. The corner radius used when `shouldRoundTopCorners` is enabled.
@ -90,20 +86,13 @@ public protocol PanModalPresentable: AnyObject {
var transitionAnimationOptions: UIView.AnimationOptions { get } var transitionAnimationOptions: UIView.AnimationOptions { get }
/** /**
The background view color. The background view alpha.
- Note: This is only utilized at the very start of the transition. - Note: This is only utilized at the very start of the transition.
Default Value is black with alpha component 0.7. Default Value is 0.7.
*/ */
var panModalBackgroundColor: UIColor { get } var backgroundAlpha: CGFloat { get }
/**
The drag indicator view color.
Default value is light gray.
*/
var dragIndicatorBackgroundColor: UIColor { get }
/** /**
We configure the panScrollable's scrollIndicatorInsets interally so override this value We configure the panScrollable's scrollIndicatorInsets interally so override this value
@ -138,17 +127,6 @@ public protocol PanModalPresentable: AnyObject {
*/ */
var allowsDragToDismiss: Bool { get } var allowsDragToDismiss: Bool { get }
var onTapToDismiss: (() -> Void)? { get }
var onDragToDismiss: (() -> Void)? { get }
/**
A flag to determine if dismissal should be initiated when tapping on the dimmed background view.
Default value is true.
*/
var allowsTapToDismiss: Bool { get }
/** /**
A flag to toggle user interactions on the container view. A flag to toggle user interactions on the container view.
@ -234,11 +212,4 @@ public protocol PanModalPresentable: AnyObject {
*/ */
func panModalWillDismiss() func panModalWillDismiss()
/**
Notifies the delegate after the pan modal is dismissed.
Default value is an empty implementation.
*/
func panModalDidDismiss()
} }
#endif

View File

@ -5,7 +5,6 @@
// Copyright © 2019 Tiny Speck, Inc. All rights reserved. // Copyright © 2019 Tiny Speck, Inc. All rights reserved.
// //
#if os(iOS)
import UIKit import UIKit
/** /**
@ -29,10 +28,6 @@ protocol PanModalPresenter: AnyObject {
/** /**
Presents a view controller that conforms to the PanModalPresentable protocol Presents a view controller that conforms to the PanModalPresentable protocol
*/ */
func presentPanModal(_ viewControllerToPresent: PanModalPresentable.LayoutType, func presentPanModal(_ viewControllerToPresent: PanModalPresentable.LayoutType, sourceView: UIView?, sourceRect: CGRect)
sourceView: UIView?,
sourceRect: CGRect,
completion: (() -> Void)?)
} }
#endif

View File

@ -5,7 +5,6 @@
// Copyright © 2019 Tiny Speck, Inc. All rights reserved. // Copyright © 2019 Tiny Speck, Inc. All rights reserved.
// //
#if os(iOS)
import UIKit import UIKit
/** /**
@ -35,14 +34,10 @@ extension UIViewController: PanModalPresenter {
- viewControllerToPresent: The view controller to be presented - viewControllerToPresent: The view controller to be presented
- sourceView: The view containing the anchor rectangle for the popover. - sourceView: The view containing the anchor rectangle for the popover.
- sourceRect: The rectangle in the specified view in which to anchor the popover. - sourceRect: The rectangle in the specified view in which to anchor the popover.
- completion: The block to execute after the presentation finishes. You may specify nil for this parameter.
- Note: sourceView & sourceRect are only required for presentation on an iPad. - Note: sourceView & sourceRect are only required for presentation on an iPad.
*/ */
public func presentPanModal(_ viewControllerToPresent: PanModalPresentable.LayoutType, public func presentPanModal(_ viewControllerToPresent: PanModalPresentable.LayoutType, sourceView: UIView? = nil, sourceRect: CGRect = .zero) {
sourceView: UIView? = nil,
sourceRect: CGRect = .zero,
completion: (() -> Void)? = nil) {
/** /**
Here, we deliberately do not check for size classes. More info in `PanModalPresentationDelegate` Here, we deliberately do not check for size classes. More info in `PanModalPresentationDelegate`
@ -59,8 +54,7 @@ extension UIViewController: PanModalPresenter {
viewControllerToPresent.transitioningDelegate = PanModalPresentationDelegate.default viewControllerToPresent.transitioningDelegate = PanModalPresentationDelegate.default
} }
present(viewControllerToPresent, animated: true, completion: completion) present(viewControllerToPresent, animated: true, completion: nil)
} }
} }
#endif

View File

@ -5,19 +5,18 @@
// Copyright © 2017 Tiny Speck, Inc. All rights reserved. // Copyright © 2017 Tiny Speck, Inc. All rights reserved.
// //
#if os(iOS)
import UIKit import UIKit
/** /**
A dim view for use as an overlay over content you want dimmed. A dim view for use as an overlay over content you want dimmed.
*/ */
open class DimmedView: UIView { public class DimmedView: UIView {
/** /**
Represents the possible states of the dimmed view. Represents the possible states of the dimmed view.
max, off or a percentage of dimAlpha. max, off or a percentage of dimAlpha.
*/ */
public enum DimState { enum DimState {
case max case max
case off case off
case percent(CGFloat) case percent(CGFloat)
@ -30,14 +29,22 @@ open class DimmedView: UIView {
*/ */
var dimState: DimState = .off { var dimState: DimState = .off {
didSet { didSet {
onChange(dimState: dimState) switch dimState {
case .max:
alpha = dimAlpha
case .off:
alpha = 0.0
case .percent(let percentage):
let val = max(0.0, min(1.0, percentage))
alpha = dimAlpha * val
}
} }
} }
/** /**
The closure to be executed when a tap occurs The closure to be executed when a tap occurs
*/ */
var didTap: ((_ recognizer: UITapGestureRecognizer) -> Void)? var didTap: ((_ recognizer: UIGestureRecognizer) -> Void)?
/** /**
Tap gesture recognizer Tap gesture recognizer
@ -46,11 +53,15 @@ open class DimmedView: UIView {
return UITapGestureRecognizer(target: self, action: #selector(didTapView)) return UITapGestureRecognizer(target: self, action: #selector(didTapView))
}() }()
private let dimAlpha: CGFloat
// MARK: - Initializers // MARK: - Initializers
public init() { init(dimAlpha: CGFloat = 0.7) {
self.dimAlpha = dimAlpha
super.init(frame: .zero) super.init(frame: .zero)
alpha = 0.0 alpha = 0.0
backgroundColor = .black
addGestureRecognizer(tapGesture) addGestureRecognizer(tapGesture)
} }
@ -60,22 +71,8 @@ open class DimmedView: UIView {
// MARK: - Event Handlers // MARK: - Event Handlers
@objc private func didTapView(sender: UITapGestureRecognizer) { @objc private func didTapView() {
didTap?(sender) didTap?(tapGesture)
}
// MARK: - Subclass override
open func onChange(dimState: DimState) {
switch dimState {
case .max:
alpha = 1.0
case .off:
alpha = 0.0
case .percent(let percentage):
alpha = max(0.0, min(1.0, percentage))
}
} }
} }
#endif

View File

@ -5,7 +5,6 @@
// Copyright © 2018 Tiny Speck, Inc. All rights reserved. // Copyright © 2018 Tiny Speck, Inc. All rights reserved.
// //
#if os(iOS)
import UIKit import UIKit
/** /**
@ -41,4 +40,3 @@ extension UIView {
} }
} }
#endif

View File

@ -629,7 +629,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.slack.PanModal; PRODUCT_BUNDLE_IDENTIFIER = com.slack.PanModal;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = ""; VERSION_INFO_PREFIX = "";
@ -658,7 +658,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.slack.PanModal; PRODUCT_BUNDLE_IDENTIFIER = com.slack.PanModal;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = ""; VERSION_INFO_PREFIX = "";
@ -679,7 +679,7 @@
); );
PRODUCT_BUNDLE_IDENTIFIER = slack.PanModalTests; PRODUCT_BUNDLE_IDENTIFIER = slack.PanModalTests;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PanModalDemo.app/PanModalDemo"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PanModalDemo.app/PanModalDemo";
}; };
@ -699,7 +699,7 @@
); );
PRODUCT_BUNDLE_IDENTIFIER = slack.PanModalTests; PRODUCT_BUNDLE_IDENTIFIER = slack.PanModalTests;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PanModalDemo.app/PanModalDemo"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PanModalDemo.app/PanModalDemo";
}; };
@ -763,7 +763,6 @@
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
}; };
name = Debug; name = Debug;
}; };
@ -818,7 +817,6 @@
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule; SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O"; SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
VALIDATE_PRODUCT = YES; VALIDATE_PRODUCT = YES;
}; };
name = Release; name = Release;
@ -839,7 +837,7 @@
); );
PRODUCT_BUNDLE_IDENTIFIER = com.PanModal; PRODUCT_BUNDLE_IDENTIFIER = com.PanModal;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
}; };
name = Debug; name = Debug;
@ -860,7 +858,7 @@
); );
PRODUCT_BUNDLE_IDENTIFIER = com.PanModal; PRODUCT_BUNDLE_IDENTIFIER = com.PanModal;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
}; };
name = Release; name = Release;

View File

@ -1,13 +1,10 @@
### PanModal is an elegant and highly customizable presentation API for constructing bottom sheet modals on iOS.
<p align="center"> <p align="center">
<img src="https://github.com/slackhq/PanModal/raw/master/Screenshots/panModal.gif" width="30%" height="30%" alt="Screenshot Preview" /> <img src="https://github.com/slackhq/PanModal/raw/master/Screenshots/panModal.gif" width="30%" height="30%" alt="Screenshot Preview" />
</p> </p>
<p align="center"> <p align="center">
<img src="https://img.shields.io/badge/Platform-iOS_10+-green.svg" alt="Platform: iOS 10.0+" /> <img src="https://img.shields.io/badge/Platform-iOS_10+-green.svg" alt="Platform: iOS 10.0+" />
<a href="https://developer.apple.com/swift" target="_blank"><img src="https://img.shields.io/badge/Language-Swift_5-blueviolet.svg" alt="Language: Swift 5" /></a> <a href="https://developer.apple.com/swift" target="_blank"><img src="https://img.shields.io/badge/Language-Swift_4-blueviolet.svg" alt="Language: Swift 4" /></a>
<a href="https://cocoapods.org/pods/PanModal" target="_blank"><img src="https://img.shields.io/badge/CocoaPods-v1.0-red.svg" alt="CocoaPods compatible" /></a> <a href="https://cocoapods.org/pods/PanModal" target="_blank"><img src="https://img.shields.io/badge/CocoaPods-v1.0-red.svg" alt="CocoaPods compatible" /></a>
<a href="https://github.com/Carthage/Carthage" target="_blank"><img src="https://img.shields.io/badge/Carthage-compatible-blue.svg" alt="Carthage compatible" /></a> <a href="https://github.com/Carthage/Carthage" target="_blank"><img src="https://img.shields.io/badge/Carthage-compatible-blue.svg" alt="Carthage compatible" /></a>
<img src="https://img.shields.io/badge/License-MIT-green.svg" alt="License: MIT" /> <img src="https://img.shields.io/badge/License-MIT-green.svg" alt="License: MIT" />
@ -24,12 +21,6 @@
<a href="#license">License</a> <a href="#license">License</a>
</p> </p>
<p align="center">
Read our <a href="https://slack.engineering/panmodal-better-support-for-thumb-accessibility-on-slack-mobile-52b2a7596031" target="_blank">blog</a> on how Slack is getting more :thumbsup: with PanModal
Swift 4.2 support can be found on the `Swift4.2` branch.
</p>
## Features ## Features
* Supports any type of `UIViewController` * Supports any type of `UIViewController`
@ -54,14 +45,6 @@ pod 'PanModal'
github "slackhq/PanModal" github "slackhq/PanModal"
``` ```
* <a href="https://swift.org/package-manager/" target="_blank">Swift Package Manager</a>:
```swift
dependencies: [
.package(url: "https://github.com/slackhq/PanModal.git", .exact("1.2.6")),
],
```
## Usage ## Usage
PanModal was designed to be used effortlessly. Simply call `presentPanModal` in the same way you would expect to present a `UIViewController` PanModal was designed to be used effortlessly. Simply call `presentPanModal` in the same way you would expect to present a `UIViewController`
@ -147,7 +130,7 @@ We will only be fixing critical bugs, thus, for any non-critical issues or featu
## Authors ## Authors
[Stephen Sowole](https://github.com/ste57) • [Tosin Afolabi](https://github.com/tosinaf) [Stephen Sowole](https://github.com/tun57) • [Tosin Afolabi](https://github.com/tosinaf)
## License ## License

View File

@ -59,8 +59,8 @@ class TransientAlertViewController: AlertViewController {
return true return true
} }
override var panModalBackgroundColor: UIColor { override var backgroundAlpha: CGFloat {
return .clear return 0.0
} }
override var isUserInteractionEnabled: Bool { override var isUserInteractionEnabled: Bool {

View File

@ -46,8 +46,8 @@ class AlertViewController: UIViewController, PanModalPresentable {
return shortFormHeight return shortFormHeight
} }
var panModalBackgroundColor: UIColor { var backgroundAlpha: CGFloat {
return UIColor.black.withAlphaComponent(0.1) return 0.1
} }
var shouldRoundTopCorners: Bool { var shouldRoundTopCorners: Bool {

View File

@ -12,19 +12,15 @@ class NavigationController: UINavigationController, PanModalPresentable {
private let navGroups = NavUserGroups() private let navGroups = NavUserGroups()
init() {
super.init(nibName: nil, bundle: nil)
viewControllers = [navGroups]
}
required init?(coder aDecoder: NSCoder) {
fatalError()
}
override var preferredStatusBarStyle: UIStatusBarStyle { override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent return .lightContent
} }
override func viewDidLoad() {
super.viewDidLoad()
pushViewController(navGroups, animated: false)
}
override func popViewController(animated: Bool) -> UIViewController? { override func popViewController(animated: Bool) -> UIViewController? {
let vc = super.popViewController(animated: animated) let vc = super.popViewController(animated: animated)
panModalSetNeedsLayoutUpdate() panModalSetNeedsLayoutUpdate()

View File

@ -48,13 +48,11 @@ class PanModalTests: XCTestCase {
XCTAssertEqual(vc.shortFormHeight, PanModalHeight.maxHeight) XCTAssertEqual(vc.shortFormHeight, PanModalHeight.maxHeight)
XCTAssertEqual(vc.longFormHeight, PanModalHeight.maxHeight) XCTAssertEqual(vc.longFormHeight, PanModalHeight.maxHeight)
XCTAssertEqual(vc.springDamping, 0.8) XCTAssertEqual(vc.springDamping, 0.8)
XCTAssertEqual(vc.panModalBackgroundColor, UIColor.black.withAlphaComponent(0.7)) XCTAssertEqual(vc.backgroundAlpha, 0.7)
XCTAssertEqual(vc.dragIndicatorBackgroundColor, UIColor.lightGray)
XCTAssertEqual(vc.scrollIndicatorInsets, .zero) XCTAssertEqual(vc.scrollIndicatorInsets, .zero)
XCTAssertEqual(vc.anchorModalToLongForm, true) XCTAssertEqual(vc.anchorModalToLongForm, true)
XCTAssertEqual(vc.allowsExtendedPanScrolling, false) XCTAssertEqual(vc.allowsExtendedPanScrolling, false)
XCTAssertEqual(vc.allowsDragToDismiss, true) XCTAssertEqual(vc.allowsDragToDismiss, true)
XCTAssertEqual(vc.allowsTapToDismiss, true)
XCTAssertEqual(vc.isUserInteractionEnabled, true) XCTAssertEqual(vc.isUserInteractionEnabled, true)
XCTAssertEqual(vc.isHapticFeedbackEnabled, true) XCTAssertEqual(vc.isHapticFeedbackEnabled, true)
XCTAssertEqual(vc.shouldRoundTopCorners, false) XCTAssertEqual(vc.shouldRoundTopCorners, false)