From afc3d3c7fb9c5ecd40f7147180af35e0cd1c3a6b Mon Sep 17 00:00:00 2001 From: Gabriel Hernandez Ontiveros Date: Thu, 5 Aug 2021 16:20:30 -0400 Subject: [PATCH] enable horizontal scroll actions. --- ListableUI/Sources/ListView/ListView.swift | 2 +- ListableUI/Sources/ScrollPosition.swift | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ListableUI/Sources/ListView/ListView.swift b/ListableUI/Sources/ListView/ListView.swift index 7fd0134a5..0175c3a2f 100644 --- a/ListableUI/Sources/ListView/ListView.swift +++ b/ListableUI/Sources/ListView/ListView.swift @@ -457,7 +457,7 @@ public final class ListView : UIView, KeyboardObserverDelegate } else { self.collectionView.scrollToItem( at: toIndexPath, - at: position.position.UICollectionViewScrollPosition, + at: position.position.toUICollectionViewScrollPosition(for: self.collectionViewLayout.layout.direction), animated: false ) } diff --git a/ListableUI/Sources/ScrollPosition.swift b/ListableUI/Sources/ScrollPosition.swift index 586788ac0..046e6b1fe 100644 --- a/ListableUI/Sources/ScrollPosition.swift +++ b/ListableUI/Sources/ScrollPosition.swift @@ -49,11 +49,20 @@ extension ScrollPosition /// Scroll the item to the bottom of the list. case bottom - var UICollectionViewScrollPosition : UICollectionView.ScrollPosition { - switch self { - case .top: return .top - case .centered: return .centeredVertically - case .bottom: return .bottom + func toUICollectionViewScrollPosition(for direction : LayoutDirection) -> UICollectionView.ScrollPosition { + switch direction { + case .vertical: + switch self { + case .top: return .top + case .centered: return .centeredVertically + case .bottom: return .bottom + } + case .horizontal: + switch self { + case .top: return .left + case .centered: return .centeredHorizontally + case .bottom: return .right + } } } }