@@ -8,10 +8,10 @@ struct PagingView<T: AnyObject, EmptyContent: View, ErrorContent: View, LoadingC
88 @ViewBuilder
99 let errorContent : ( KotlinThrowable , @escaping ( ) -> Void ) -> ErrorContent
1010 @ViewBuilder
11- let loadingContent : ( ) -> LoadingContent
11+ let loadingContent : ( Int , Int ) -> LoadingContent
1212 let loadingCount = 5
1313 @ViewBuilder
14- let successContent : ( T ) -> SuccessContent
14+ let successContent : ( T , Int , Int ) -> SuccessContent
1515 var body : some View {
1616 switch onEnum ( of: data) {
1717 case . empty: emptyContent ( )
@@ -20,20 +20,19 @@ struct PagingView<T: AnyObject, EmptyContent: View, ErrorContent: View, LoadingC
2020 }
2121 . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . center)
2222 case . loading: ForEach ( 0 ..< loadingCount, id: \. self) { index in
23- loadingContent ( )
23+ loadingContent ( index , loadingCount )
2424 }
2525 case . success( let success) :
2626 ForEach ( 0 ..< success. itemCount, id: \. self) { index in
27- if let item = success. peek ( index: index) {
28- successContent ( item)
29- . onAppear {
30- _ = success. get ( index: index)
31- }
32- } else {
33- loadingContent ( )
34- . onAppear {
35- _ = success. get ( index: index)
36- }
27+ ZStack {
28+ if let item = success. peek ( index: index) {
29+ successContent ( item, Int ( index) , Int ( success. itemCount) )
30+ } else {
31+ loadingContent ( Int ( index) , Int ( success. itemCount) )
32+ }
33+ }
34+ . onAppear {
35+ _ = success. get ( index: index)
3736 }
3837 }
3938
@@ -70,7 +69,13 @@ extension PagingView {
7069 retry ( )
7170 }
7271 } ,
73- loadingContent: loadingContent, successContent: successContent)
72+ loadingContent: { index, loadingCount in
73+ loadingContent ( )
74+ } ,
75+ successContent: { item, index, itemCount in
76+ successContent ( item)
77+ }
78+ )
7479 }
7580}
7681
0 commit comments