 	
 	private var lastCollectionViewSize: CGSize = CGSize.zero
 	private var lastScrollDirection: UICollectionViewScrollDirection!
+    var pageWidth: CGFloat {
+        switch scrollDirection {
+        case .horizontal:
+            return itemSize.width + minimumLineSpacing
+        case .vertical:
+            return itemSize.height + minimumLineSpacing
+        }
+    }
+    
+    /// Calculates the current centered page.
+    public var currentCenteredPage: Int? {
+        guard let collectionView = collectionView else { return nil }
+        let currentCenteredPoint = CGPoint(x: collectionView.contentOffset.x + collectionView.bounds.width/2, y: collectionView.contentOffset.y + collectionView.bounds.height/2)
+        
+        return collectionView.indexPathForItem(at: currentCenteredPoint)?.row
+    }
 	
 	public override init() {
 		super.init()

	public func scrollToPage(index: Int, animated: Bool) {
		guard let collectionView = collectionView else { return }
		
		let pageOffset: CGFloat
		let proposedContentOffset: CGPoint
		let shouldAnimate: Bool
		switch scrollDirection {
		case .horizontal:
			pageOffset = CGFloat(index) * pageWidth - collectionView.contentInset.left
			proposedContentOffset = CGPoint(x: pageOffset, y: 0)
			shouldAnimate = fabs(collectionView.contentOffset.x - pageOffset) > 1 ? animated : false
		case .vertical:
			pageOffset = CGFloat(index) * pageWidth - collectionView.contentInset.top
			proposedContentOffset = CGPoint(x: 0, y: pageOffset)
			shouldAnimate = fabs(collectionView.contentOffset.y - pageOffset) > 1 ? animated : false
		}
		collectionView.setContentOffset(proposedContentOffset, animated: shouldAnimate)
	}
	
	/// Calculates the current centered page.
	public var currentCenteredPage: Int? {
		guard let collectionView = collectionView else { return nil }
		let currentCenteredPoint = CGPoint(x: collectionView.contentOffset.x + collectionView.bounds.width/2, y: collectionView.contentOffset.y + collectionView.bounds.height/2)
		let indexPath = collectionView.indexPathForItem(at: currentCenteredPoint)
		return indexPath?.row
	}
}

		// invalidate layout to center first and last
		let currentCollectionViewSize = collectionView.bounds.size
		if !currentCollectionViewSize.equalTo(lastCollectionViewSize) || lastScrollDirection != scrollDirection {
			switch scrollDirection {
			case .horizontal:
				let inset = (currentCollectionViewSize.width - itemSize.width) / 2
				collectionView.contentInset = UIEdgeInsets(top: 0, left: inset, bottom: 0, right: inset)
				collectionView.contentOffset = CGPoint(x: -inset, y: 0)
			case .vertical:
				let inset = (currentCollectionViewSize.height - itemSize.height) / 2
				collectionView.contentInset = UIEdgeInsets(top: inset, left: 0, bottom: inset, right: 0)
				collectionView.contentOffset = CGPoint(x: 0, y: -inset)
			}
			lastCollectionViewSize = currentCollectionViewSize
			lastScrollDirection = scrollDirection
		}
	}
	
	// swiftlint:disable line_length
