  *  View controllers in the drawer can implement this to receive changes in state or provide values for the different drawer positions.
  */
 @objc public protocol BottomSheetDrawerViewControllerDelegate: BottomSheetDelegate {
-    
+
     /**
      *  Provide the collapsed drawer height for BottomSheet. BottomSheet does NOT automatically handle safe areas for you, however: bottom safe area is provided for your convenience in computing a value to return.
      */
     @objc optional func collapsedDrawerHeight(bottomSafeArea: CGFloat) -> CGFloat
-    
+
     /**
      *  Provide the partialReveal drawer height for BottomSheet. BottomSheet does NOT automatically handle safe areas for you, however: bottom safe area is provided for your convenience in computing a value to return.
      */
     @objc optional func partialRevealDrawerHeight(bottomSafeArea: CGFloat) -> CGFloat
-    
+
     /**
      *  Return the support drawer positions for your drawer.
      */

            {
                return drawerContentViewController.view
            }
            
            return primaryContentContainer
        }
    }
}

extension BottomSheetViewController: UIScrollViewDelegate {
    
    public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
        
        if scrollView == drawerScrollView
        {
            // Find the closest anchor point and snap there.
            var collapsedHeight:CGFloat = kBottomSheetDefaultCollapsedHeight
            var partialRevealHeight:CGFloat = kBottomSheetDefaultPartialRevealHeight
            
            if let drawerVCCompliant = drawerContentViewController as? BottomSheetDrawerViewControllerDelegate
            {
                collapsedHeight = drawerVCCompliant.collapsedDrawerHeight?(bottomSafeArea: BottomSheetSafeAreaInsets.bottom) ?? kBottomSheetDefaultCollapsedHeight
                partialRevealHeight = drawerVCCompliant.partialRevealDrawerHeight?(bottomSafeArea: BottomSheetSafeAreaInsets.bottom) ?? kBottomSheetDefaultPartialRevealHeight
            }
            
            var drawerStops: [CGFloat] = [CGFloat]()
            var currentDrawerPositionStop: CGFloat = 0.0
            
            if supportedPositions.contains(.open)
            {
                drawerStops.append(heightOfOpenDrawer)
                
                if drawerPosition == .open
                {
                    currentDrawerPositionStop = drawerStops.last!
                }
            }
            
            if supportedPositions.contains(.partiallyRevealed)
            {
                drawerStops.append(partialRevealHeight)
                
                if drawerPosition == .partiallyRevealed
                {
                    currentDrawerPositionStop = drawerStops.last!
                }
            }
            
            if supportedPositions.contains(.collapsed)
            {
                drawerStops.append(collapsedHeight)
                
                if drawerPosition == .collapsed
                {
                    currentDrawerPositionStop = drawerStops.last!
                }
            }
            
            let lowestStop = drawerStops.min() ?? 0
            
            let distanceFromBottomOfView = lowestStop + lastDragTargetContentOffset.y
            
            var currentClosestStop = lowestStop
            
            for currentStop in drawerStops
            {
                if abs(currentStop - distanceFromBottomOfView) < abs(currentClosestStop - distanceFromBottomOfView)

        // Account for transition issue in iOS 11
        controller.view.frame = drawerContentContainer.bounds
        controller.view.layoutIfNeeded()

        if animated
        {
            UIView.transition(with: drawerContentContainer, duration: 0.5, options: .transitionCrossDissolve, animations: { [weak self] () -> Void in

                self?.drawerContentViewController = controller
                self?.setDrawerPosition(position: self?.drawerPosition ?? .collapsed, animated: false)

                }, completion: { (completed) in

                    completion?(completed)
            })
        }
