Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions Source/SPStorkController/SPStorkController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@
import UIKit

public enum SPStorkController {

static public func scrollViewDidScroll(_ scrollView: UIScrollView) {
if let controller = self.controller(for: scrollView) {
if let presentationController = controller.presentationController as? SPStorkPresentationController {
if let presentationController = self.presentationController(for: controller) {
let translation = -(scrollView.contentOffset.y + scrollView.contentInset.top)
if translation >= 0 {
if controller.isBeingPresented { return }
scrollView.subviews.forEach {
$0.transform = CGAffineTransform(translationX: 0, y: -translation)
}
scrollView.transform = CGAffineTransform(translationX: 0, y: -translation)
presentationController.setIndicator(style: scrollView.isTracking ? .line : .arrow)
if translation >= presentationController.translateForDismiss * 0.4 {
if !scrollView.isTracking && !scrollView.isDragging {
Expand Down Expand Up @@ -74,6 +71,18 @@ public enum SPStorkController {
}
}

static private func presentationController(for controller: UIViewController) -> SPStorkPresentationController? {
if let presentationController = controller.presentationController as? SPStorkPresentationController {
return presentationController
}

if let presentationController = controller.parent?.presentationController as? SPStorkPresentationController {
return presentationController
}

return nil
}

static private func controller(for view: UIView) -> UIViewController? {
var nextResponder = view.next
while nextResponder != nil && !(nextResponder! is UIViewController) {
Expand Down