SwiftUI PageView iOS 13 - Navigation link not working as expected

422 Views Asked by At

My project is target for iOS 13 onwards hence could not use PageTabViewStyle(). I tried with Mr. John suggestion from this link

SwiftUI create image slider with dots as indicators

Now I need to open the detail view on clicking the image in the slideshow. But now when I try to move the images the detail view is opening and could not move the images as in Pageview. I implemented the below code. Please let me know the solution to fix this. Thanks in advance.

                PagingView(index: $index.animation(), maxIndex: images.count - 1){
                    ForEach(articles, id: \.self) { article in
                        
                        NavigationLink(destination: ArticleDetailUIView(article: articles[self.index], isBookmark: false) , isActive: $areYouGoingToArticleView)
                        {
                            
                            
                            Image(article.image)
                                .resizable()
                                .scaledToFill()
                                .accessibility(identifier: "articleImage")
                            
                            
                        }
                        
                    }
                }
                .aspectRatio(4/3, contentMode: .fit)
                .clipShape(RoundedRectangle(cornerRadius: 15))
1

There are 1 best solutions below

0
On

After few browsing, the workaround was using the stepper to move around the slide show instead of scrolling the images. I added the below lines.

Stepper("Index: (index)", value: $index.animation(.easeInOut), in: 0...images.count-1) .font(Font.body.monospacedDigit()) .labelsHidden()