       let to = layoutAttributes[upcomingIndexPath] else { return 0 }
     
     let toWidth = sizeCache.itemWidthSelected(for: upcomingPagingItem)
-    let currentPosition = to.frame.origin.x + to.frame.width
+    let currentPosition = to.center.x + (to.bounds.width / 2)
     let width = view.contentOffset.x + view.bounds.width
     var distance = currentPosition - width
     

      
      if sizeCache.implementsWidthDelegate {
        let toWidth = sizeCache.itemWidthSelected(for: upcomingPagingItem)
        distance += toWidth - to.frame.width
        
        if let currentIndexPath = dataStructure.indexPathForPagingItem(currentPagingItem),
          let from = layoutAttributes[currentIndexPath] {
          let fromWidth = sizeCache.itemWidth(for: currentPagingItem)
          distance -= from.frame.width - fromWidth
        }
        
        // If the selected cells grows so much that it will move

      let to = layoutAttributes[upcomingIndexPath] else { return 0 }
    
    let toWidth = sizeCache.itemWidthSelected(for: upcomingPagingItem)
    var distance = to.center.x - view.bounds.midX
    
    if let currentIndexPath = dataStructure.indexPathForPagingItem(currentPagingItem),
      let from = layoutAttributes[currentIndexPath] {
      
      let distanceToCenter = view.bounds.midX - from.center.x
      let distanceBetweenCells = to.center.x - from.center.x
      distance = distanceBetweenCells - distanceToCenter
      
      if sizeCache.implementsWidthDelegate {
        let fromWidth = sizeCache.itemWidth(for: currentPagingItem)
        
        if upcomingPagingItem < currentPagingItem {
          distance = -(to.bounds.width + (from.center.x - (to.center.x + (to.bounds.width / 2))) - (toWidth / 2)) - distanceToCenter
        } else {
          let toDiff = (toWidth - to.bounds.width) / 2
          distance = fromWidth + (to.center.x - (from.center.x + (from.bounds.width / 2))) + toDiff - (from.bounds.width / 2) - distanceToCenter
        }
      }
    } else if sizeCache.implementsWidthDelegate {
      let toDiff = toWidth - to.bounds.width
      distance += toDiff / 2
    }
    
