Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
534 views
in Technique[技术] by (71.8m points)

swift - ScrollView Pagination with SwiftUI

Is there is a way to do pagination without using List in swiftUI. I found a couple solution but most of them are using list . In my code I don't have list so Im looking for a solution how can I use pagination without using List.

    ZStack{
        
        ActivityIndicator(isAnimating: $isAnimating)
        
        ScrollView(.vertical, showsIndicators : true){
            
            if isSelected == false {
                
                ProductListSortFilterView()
                
            }
            
            LazyVGrid(columns: Array(repeating: GridItem(.flexible(),spacing: 5), count:2), spacing:10 ) {
                
                ForEach(productListArray , id:.uid) { item in // MARK: Optinal typed changed 
                    
                    ZStack{
                        
                        CatalogBackgroundView()
                        
                        WebImage(url: URL(string: item.image?.medium ?? ""))
                            .resizable()
                            .aspectRatio(CGFloat(item.imageRatio ?? 0.6),contentMode: .fit)
                            .frame(width:UIScreen.main.bounds.width / 2.5,height:UIScreen.main.bounds.height / 6)
                            .padding(EdgeInsets(top: 0, leading: 0, bottom: UIScreen.main.bounds.height * 0.083, trailing: 0))
                        
                        
                        if item.isDiscountActive == 0 || item.isDiscountActive == nil || item.isDiscountDisplay == 0 {
                            
                            Text("(item.priceSell ?? 0 , specifier: "%.2f" ) (item.targetCurrency ?? "") +VAT")
                                .font(.system(size: 12))
                                .bold()
                                .foregroundColor(.black)
                                .padding(EdgeInsets(top: UIScreen.main.bounds.height * 0.24, leading: 0, bottom: 0, trailing: 0))
                            
                            
                        } 
        
    }.onAppear {
        
        if isFinish{
            
            getProductList()
            
        }
        
    }
    .onDisappear {
        
        isFinish = false
        
        productViewModel.currentPage = 0
        
    }
    
}
question from:https://stackoverflow.com/questions/65938311/scrollview-pagination-with-swiftui

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Can you check this link, this uses ScrollView and LazyVStack, and uses a dataSource to manage data. I havent tried though but seem to work.

LazyVStack


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...