@@ -12,36 +12,42 @@ extension CocoaList {
12
12
_ data: Data ,
13
13
sectionHeader: @escaping ( SectionType ) -> SectionHeader ,
14
14
sectionFooter: @escaping ( SectionType ) -> SectionFooter ,
15
- rowContent: @escaping ( _Item ) -> RowContent
15
+ rowContent: @escaping ( _Item ) -> RowContent ,
16
+ scrollPosition: Binding < ListScrollPosition > = Binding . constant ( ListScrollPosition ( ) )
16
17
) where ItemType == _HashIdentifiableValue < _Item > {
17
18
self . data = data
18
19
self . sectionHeader = sectionHeader
19
20
self . sectionFooter = sectionFooter
20
21
self . rowContent = { rowContent ( $0. value) }
22
+ self . scrollPosition = scrollPosition
21
23
}
22
24
23
25
public init < _SectionType: Hashable , _Item: Hashable > (
24
26
_ data: Data ,
25
27
sectionHeader: @escaping ( _SectionType ) -> SectionHeader ,
26
28
sectionFooter: @escaping ( _SectionType ) -> SectionFooter ,
27
- rowContent: @escaping ( _Item ) -> RowContent
29
+ rowContent: @escaping ( _Item ) -> RowContent ,
30
+ scrollPosition: Binding < ListScrollPosition > = Binding . constant ( ListScrollPosition ( ) )
28
31
) where SectionType == _HashIdentifiableValue < _SectionType > , ItemType == _HashIdentifiableValue < _Item > {
29
32
self . data = data
30
33
self . sectionHeader = { sectionHeader ( $0. value) }
31
34
self . sectionFooter = { sectionFooter ( $0. value) }
32
35
self . rowContent = { rowContent ( $0. value) }
36
+ self . scrollPosition = scrollPosition
33
37
}
34
38
35
39
public init < _SectionType: Hashable , _Item: Hashable > (
36
40
_ data: [ ListSection < _SectionType , _Item > ] ,
37
41
sectionHeader: @escaping ( _SectionType ) -> SectionHeader ,
38
42
sectionFooter: @escaping ( _SectionType ) -> SectionFooter ,
39
- rowContent: @escaping ( _Item ) -> RowContent
43
+ rowContent: @escaping ( _Item ) -> RowContent ,
44
+ scrollPosition: Binding < ListScrollPosition > = Binding . constant ( ListScrollPosition ( ) )
40
45
) where Data == Array < ListSection < SectionType , ItemType > > , SectionType == _HashIdentifiableValue < _SectionType > , ItemType == _HashIdentifiableValue < _Item > {
41
46
self . data = data. map ( { . init( model: . init( $0. model) , items: $0. items. map ( _HashIdentifiableValue. init) ) } )
42
47
self . sectionHeader = { sectionHeader ( $0. value) }
43
48
self . sectionFooter = { sectionFooter ( $0. value) }
44
49
self . rowContent = { rowContent ( $0. value) }
50
+ self . scrollPosition = scrollPosition
45
51
}
46
52
}
47
53
@@ -53,21 +59,24 @@ extension CocoaList where SectionType == _KeyPathHashIdentifiableValue<Int, Int>
53
59
> (
54
60
_ items: Items ,
55
61
id: KeyPath < _ItemType , _ItemID > ,
56
- @ViewBuilder rowContent: @escaping ( _ItemType ) -> RowContent
62
+ @ViewBuilder rowContent: @escaping ( _ItemType ) -> RowContent ,
63
+ scrollPosition: Binding < ListScrollPosition > = Binding . constant ( ListScrollPosition ( ) )
57
64
) where Data == AnyRandomAccessCollection < ListSection < SectionType , ItemType > > , Items. Element == _ItemType , ItemType == _KeyPathHashIdentifiableValue < _ItemType , _ItemID > {
58
65
self . init (
59
66
AnyRandomAccessCollection ( [ ListSection ( _KeyPathHashIdentifiableValue ( value: 0 , keyPath: \. self) , items: items. elements ( identifiedBy: id) ) ] ) ,
60
67
sectionHeader: Never . _SwiftUIX_produce,
61
68
sectionFooter: Never . _SwiftUIX_produce,
62
- rowContent: { rowContent ( $0. value) }
69
+ rowContent: { rowContent ( $0. value) } ,
70
+ scrollPosition: scrollPosition
63
71
)
64
72
}
65
73
}
66
74
67
75
extension CocoaList where Data: RangeReplaceableCollection , SectionType == _KeyPathHashIdentifiableValue < Int , Int > , SectionHeader == Never , SectionFooter == Never {
68
76
public init < Items: RandomAccessCollection > (
69
77
_ items: Items ,
70
- @ViewBuilder rowContent: @escaping ( ItemType ) -> RowContent
78
+ @ViewBuilder rowContent: @escaping ( ItemType ) -> RowContent ,
79
+ scrollPosition: Binding < ListScrollPosition > = Binding . constant ( ListScrollPosition ( ) )
71
80
) where Items. Element == ItemType {
72
81
var data = Data ( )
73
82
@@ -77,12 +86,14 @@ extension CocoaList where Data: RangeReplaceableCollection, SectionType == _KeyP
77
86
data,
78
87
sectionHeader: Never . _SwiftUIX_produce,
79
88
sectionFooter: Never . _SwiftUIX_produce,
80
- rowContent: rowContent
89
+ rowContent: rowContent,
90
+ scrollPosition: scrollPosition
81
91
)
82
92
}
83
93
84
94
public init < Items: RandomAccessCollection > (
85
- @ViewBuilder content: @escaping ( ) -> ForEach < Items , ItemType . ID , RowContent >
95
+ @ViewBuilder content: @escaping ( ) -> ForEach < Items , ItemType . ID , RowContent > ,
96
+ scrollPosition: Binding < ListScrollPosition > = Binding . constant ( ListScrollPosition ( ) )
86
97
) where Items. Element == ItemType , Data == Array < ListSection < SectionType , ItemType > > {
87
98
var data = Data ( )
88
99
@@ -94,7 +105,8 @@ extension CocoaList where Data: RangeReplaceableCollection, SectionType == _KeyP
94
105
data,
95
106
sectionHeader: Never . _SwiftUIX_produce,
96
107
sectionFooter: Never . _SwiftUIX_produce,
97
- rowContent: content. content
108
+ rowContent: content. content,
109
+ scrollPosition: scrollPosition
98
110
)
99
111
}
100
112
}
@@ -103,13 +115,15 @@ extension CocoaList where Data == Array<ListSection<SectionType, ItemType>>, Sec
103
115
{
104
116
public init < Items: RandomAccessCollection > (
105
117
_ items: Items ,
106
- @ViewBuilder rowContent: @escaping ( ItemType ) -> RowContent
118
+ @ViewBuilder rowContent: @escaping ( ItemType ) -> RowContent ,
119
+ scrollPosition: Binding < ListScrollPosition > = Binding . constant ( ListScrollPosition ( ) )
107
120
) where Items. Element == ItemType {
108
121
self . init (
109
122
[ . init( _KeyPathHashIdentifiableValue ( value: 0 , keyPath: \. self) , items: items) ] ,
110
123
sectionHeader: Never . _SwiftUIX_produce,
111
124
sectionFooter: Never . _SwiftUIX_produce,
112
- rowContent: rowContent
125
+ rowContent: rowContent,
126
+ scrollPosition: scrollPosition
113
127
)
114
128
}
115
129
}
0 commit comments