ios – ProgressView not displaying in SwiftUI Checklist after first time


I’ve a paginated checklist that has a ProgressView as its final subview. When reaching the underside of the checklist the ProgressView triggers a activity that masses extra outcomes from the distant server and the person can proceed scrolling. This works effective the primary time (and typically the second time), nonetheless, after this, the progress view isn’t seen anymore.

struct SomeView : View {
    @ObservedObject var viewModel : ViewModel = ViewModel ()
    var physique : some View {
        Checklist {
            Part {
                ForEach (0...10)
                {
                    i in Textual content ("(i)")
                    .body (maxWidth: .infinity, alignment: .heart)
                }
            }
            if viewModel.hasMoreToLoad {
                Part {
                    ProgressView ()
                    .body (maxWidth: .infinity, alignment: .heart)
                    .activity { await viewModel.loadMore() }
                }
            }
        }
    }
}

class ViewModel : ObservableObject {
    @Printed var hasMoreToLoad : Bool = true
    @Printed var isLoading : Bool = false
    
    func loadMore ()
        isLoading = true
        async { await Process.sleep(for: Period.milliseconds(100)) }
        isLoading = false
        hasMoreToLoad = true
    }
}

The identical may be noticed with a conditional ProgressView inside a Checklist

Checklist {
    if viewModel.isLoading {
        Part {
            ProgressView()
              .body(maxWidth: .infinity, alignment: .heart)
        }
    } else {
        Part {
            ForEach(0...10) { i in
                Textual content("(i)")
                  .body(maxWidth: .infinity, alignment: .heart)
            }
        }
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles