1 // Copyright (c) 2018, Applidium. All rights reserved 2 // OverlayContainerViewControllerDelegateWrapper.swift 3 // OverlayContainer 4 // 5 // Created by Gaétan Zanella on 20/11/2018. 6 // 7 8 import UIKit 9 10 protocol OverlayContainerConfiguration { 11 numberOfNotchesnull12 func numberOfNotches() -> Int 13 func heightForNotch(at index: Int) -> CGFloat 14 15 func canReachNotch(at index: Int, for overlayViewController: UIViewController) -> Bool 16 func animationController(forOverlay overlay: UIViewController) -> OverlayAnimatedTransitioning 17 func overlayTargetNotchPolicy(forOverlay overlay: UIViewController) -> OverlayTranslationTargetNotchPolicy 18 19 func scrollView(drivingOverlay controller: UIViewController) -> UIScrollView? 20 21 func shouldStartDraggingOverlay(_ viewController: UIViewController, 22 at point: CGPoint, 23 in coordinateSpace: UICoordinateSpace) -> Bool 24 func overlayTranslationFunction(using context: OverlayTranslationParameters, 25 for overlayViewController: UIViewController) -> OverlayTranslationFunction 26 } 27 28 protocol OverlayContainerConfigurationInvalidating: OverlayContainerConfiguration { 29 func invalidateOverlayMetrics() 30 func requestOverlayMetricsIfNeeded() 31 } 32 33 extension OverlayContainerConfiguration { 34 var maximumNotchIndex: Int { 35 return max(numberOfNotches() - 1, 0) 36 } 37 38 var minimumNotchIndex: Int { 39 return 0 40 } 41 42 var maximumNotchHeight: CGFloat { 43 return heightForNotch(at: maximumNotchIndex) 44 } 45 46 var minimumNotchHeight: CGFloat { 47 return heightForNotch(at: minimumNotchIndex) 48 } 49 50 var notchHeightByIndex: [Int: CGFloat] { 51 return Dictionary( 52 uniqueKeysWithValues: (0..<numberOfNotches()).map { ($0, heightForNotch(at: $0)) } 53 ) 54 } 55 sortedHeightsnull56 func sortedHeights() -> [CGFloat] { 57 return Array(notchHeightByIndex.values.sorted()) 58 } 59 enabledNotchIndexesnull60 func enabledNotchIndexes(for overlayContainer: UIViewController) -> [Int] { 61 return (0..<numberOfNotches()).filter { canReachNotch(at: $0, for: overlayContainer) } 62 } 63 } 64