@@ -8,6 +8,25 @@ public enum Selection<Data: Hashable> {
8
8
9
9
public struct DynamicList < Section: Hashable , Item: Hashable > : UIViewRepresentable {
10
10
11
+ public struct ScrollTarget {
12
+ public let item : Item
13
+ public let position : UICollectionView . ScrollPosition
14
+ public let animated : Bool
15
+ public let skipsWhileTracking : Bool
16
+
17
+ public init (
18
+ item: Item ,
19
+ position: UICollectionView . ScrollPosition = . centeredVertically,
20
+ skipsWhileTracking: Bool = false ,
21
+ animated: Bool
22
+ ) {
23
+ self . item = item
24
+ self . position = position
25
+ self . animated = animated
26
+ self . skipsWhileTracking = skipsWhileTracking
27
+ }
28
+ }
29
+
11
30
private var selection : Binding < Selection < Item > ? > ?
12
31
13
32
public typealias SelectionAction = DynamicListView < Section , Item > . SelectionAction
@@ -26,7 +45,7 @@ public struct DynamicList<Section: Hashable, Item: Hashable>: UIViewRepresentabl
26
45
private let contentInsetAdjustmentBehavior : UIScrollView . ContentInsetAdjustmentBehavior
27
46
private let cellStates : [ Item : CellState ]
28
47
29
- private var scrollingTarget : Item ?
48
+ private var scrollingTarget : ScrollTarget ?
30
49
31
50
public init (
32
51
snapshot: NSDiffableDataSourceSnapshot < Section , Item > ,
@@ -48,7 +67,7 @@ public struct DynamicList<Section: Hashable, Item: Hashable>: UIViewRepresentabl
48
67
self . cellStates = cellStates
49
68
}
50
69
51
- public func scrolling( to item: Item ? ) -> Self {
70
+ public func scrolling( to item: ScrollTarget ? ) -> Self {
52
71
var modified = self
53
72
modified. scrollingTarget = item
54
73
return modified
@@ -75,10 +94,12 @@ public struct DynamicList<Section: Hashable, Item: Hashable>: UIViewRepresentabl
75
94
listView. setContents ( snapshot: snapshot)
76
95
77
96
if let scrollingTarget {
97
+
78
98
listView. scroll (
79
- to: scrollingTarget,
80
- at: . centeredVertically,
81
- animated: false
99
+ to: scrollingTarget. item,
100
+ at: scrollingTarget. position,
101
+ skipsWhileTracking: scrollingTarget. skipsWhileTracking,
102
+ animated: scrollingTarget. animated
82
103
)
83
104
}
84
105
@@ -117,12 +138,12 @@ public struct DynamicList<Section: Hashable, Item: Hashable>: UIViewRepresentabl
117
138
118
139
if let scrollingTarget {
119
140
listView. scroll (
120
- to: scrollingTarget,
121
- at: . centeredVertically,
122
- animated: true
141
+ to: scrollingTarget. item,
142
+ at: scrollingTarget. position,
143
+ skipsWhileTracking: scrollingTarget. skipsWhileTracking,
144
+ animated: scrollingTarget. animated
123
145
)
124
146
}
125
-
126
147
}
127
148
128
149
public func selectionHandler(
0 commit comments