Skip to content

Commit 430b00a

Browse files
committed
Implement scroll indicator methods for Collection, List, StaticList
1 parent f6e295c commit 430b00a

File tree

3 files changed

+146
-17
lines changed

3 files changed

+146
-17
lines changed

Classes/Views/Collection.swift

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,38 @@ public class Collection: View, UICollectionViewDataSource {
7777
reversed = value
7878
return self
7979
}
80+
}
81+
82+
extension Collection: UICollectionViewDelegate {
83+
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {}
84+
public func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool { false }
85+
}
86+
87+
extension Collection: UIScrollViewDelegate {
88+
@discardableResult
89+
public func contentOffset(_ position: CGPoint, animated: Bool = true) -> Self {
90+
collectionView.setContentOffset(position, animated: animated)
91+
return self
92+
}
8093

94+
@discardableResult
95+
public func scrollPosition(_ binding: UIKitPlus.State<CGPoint>) -> Self {
96+
scrollPosition = binding
97+
return self
98+
}
99+
100+
@discardableResult
101+
public func scrollPosition<V>(_ expressable: ExpressableState<V, CGPoint>) -> Self {
102+
scrollPosition = expressable.unwrap()
103+
return self
104+
}
105+
106+
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
107+
scrollPosition?.wrappedValue = scrollView.contentOffset
108+
}
109+
}
110+
111+
extension Collection {
81112
// MARK: Indicators
82113

83114
@discardableResult
@@ -99,33 +130,31 @@ public class Collection: View, UICollectionViewDataSource {
99130
collectionView.showsVerticalScrollIndicator = false
100131
return self
101132
}
102-
}
103-
104-
extension Collection: UICollectionViewDelegate {
105-
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {}
106-
public func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool { false }
107-
}
108-
109-
extension Collection: UIScrollViewDelegate {
133+
134+
// MARK: Content Inset
135+
110136
@discardableResult
111-
public func contentOffset(_ position: CGPoint, animated: Bool = true) -> Self {
112-
collectionView.setContentOffset(position, animated: animated)
137+
public func contentInset(_ insets: UIEdgeInsets) -> Self {
138+
collectionView.contentInset = insets
113139
return self
114140
}
115141

116142
@discardableResult
117-
public func scrollPosition(_ binding: UIKitPlus.State<CGPoint>) -> Self {
118-
scrollPosition = binding
119-
return self
143+
public func contentInset(top: CGFloat = 0, left: CGFloat = 0, right: CGFloat = 0, bottom: CGFloat = 0) -> Self {
144+
contentInset(.init(top: top, left: left, bottom: bottom, right: right))
120145
}
121146

147+
// MARK: Scroll Indicator Inset
148+
122149
@discardableResult
123-
public func scrollPosition<V>(_ expressable: ExpressableState<V, CGPoint>) -> Self {
124-
scrollPosition = expressable.unwrap()
150+
public func scrollIndicatorInsets(_ insets: UIEdgeInsets) -> Self {
151+
collectionView.scrollIndicatorInsets = insets
125152
return self
126153
}
127154

128-
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
129-
scrollPosition?.wrappedValue = scrollView.contentOffset
155+
@discardableResult
156+
public func scrollIndicatorInsets(top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0) -> Self {
157+
scrollIndicatorInsets(.init(top: top, left: left, bottom: bottom, right: right))
130158
}
131159
}
160+

Classes/Views/List.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,53 @@ extension List: UITableViewDelegate {
168168
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {}
169169
public func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool { false }
170170
}
171+
172+
extension List {
173+
// MARK: Indicators
174+
175+
@discardableResult
176+
public func hideIndicator(_ indicators: NSLayoutConstraint.Axis...) -> Self {
177+
if indicators.contains(.horizontal) {
178+
tableView.showsHorizontalScrollIndicator = false
179+
}
180+
if indicators.contains(.vertical) {
181+
tableView.showsVerticalScrollIndicator = false
182+
}
183+
return self
184+
}
185+
186+
// MARK: Indicators
187+
188+
@discardableResult
189+
public func hideAllIndicators() -> Self {
190+
tableView.showsHorizontalScrollIndicator = false
191+
tableView.showsVerticalScrollIndicator = false
192+
return self
193+
}
194+
195+
// MARK: Content Inset
196+
197+
@discardableResult
198+
public func contentInset(_ insets: UIEdgeInsets) -> Self {
199+
tableView.contentInset = insets
200+
return self
201+
}
202+
203+
@discardableResult
204+
public func contentInset(top: CGFloat = 0, left: CGFloat = 0, right: CGFloat = 0, bottom: CGFloat = 0) -> Self {
205+
contentInset(.init(top: top, left: left, bottom: bottom, right: right))
206+
}
207+
208+
// MARK: Scroll Indicator Inset
209+
210+
@discardableResult
211+
public func scrollIndicatorInsets(_ insets: UIEdgeInsets) -> Self {
212+
tableView.scrollIndicatorInsets = insets
213+
return self
214+
}
215+
216+
@discardableResult
217+
public func scrollIndicatorInsets(top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0) -> Self {
218+
scrollIndicatorInsets(.init(top: top, left: left, bottom: bottom, right: right))
219+
}
220+
}

Classes/Views/StaticList.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,53 @@ extension StaticList: UIScrollViewDelegate {
136136
scrollPosition?.wrappedValue = scrollView.contentOffset
137137
}
138138
}
139+
140+
extension StaticList {
141+
// MARK: Indicators
142+
143+
@discardableResult
144+
public func hideIndicator(_ indicators: NSLayoutConstraint.Axis...) -> Self {
145+
if indicators.contains(.horizontal) {
146+
tableView.showsHorizontalScrollIndicator = false
147+
}
148+
if indicators.contains(.vertical) {
149+
tableView.showsVerticalScrollIndicator = false
150+
}
151+
return self
152+
}
153+
154+
// MARK: Indicators
155+
156+
@discardableResult
157+
public func hideAllIndicators() -> Self {
158+
tableView.showsHorizontalScrollIndicator = false
159+
tableView.showsVerticalScrollIndicator = false
160+
return self
161+
}
162+
163+
// MARK: Content Inset
164+
165+
@discardableResult
166+
public func contentInset(_ insets: UIEdgeInsets) -> Self {
167+
tableView.contentInset = insets
168+
return self
169+
}
170+
171+
@discardableResult
172+
public func contentInset(top: CGFloat = 0, left: CGFloat = 0, right: CGFloat = 0, bottom: CGFloat = 0) -> Self {
173+
contentInset(.init(top: top, left: left, bottom: bottom, right: right))
174+
}
175+
176+
// MARK: Scroll Indicator Inset
177+
178+
@discardableResult
179+
public func scrollIndicatorInsets(_ insets: UIEdgeInsets) -> Self {
180+
tableView.scrollIndicatorInsets = insets
181+
return self
182+
}
183+
184+
@discardableResult
185+
public func scrollIndicatorInsets(top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0) -> Self {
186+
scrollIndicatorInsets(.init(top: top, left: left, bottom: bottom, right: right))
187+
}
188+
}

0 commit comments

Comments
 (0)