I want to Make A SwiftUI Image Slideshow With Auto Scrolling but My code is not Running. this problem shown when I try to set Image from url(AsyncImage()) otherwise this code run properly .how can I set as image slider in SwiftUI
struct MagazineBannerView: View{
// @ObservedObject var list = MagazineBannerVM()
private let timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect()
@State var currentIndex = 0
@State var totalImages = 7
var body: some View{
GeometryReader { proxy in
TabView(selection: $currentIndex) {
HStack{
ForEach(0..<totalImages){ item in
AsyncImage(url: URL(string: "https://moneyinc.com/wp-content/uploads/2020/12/Motorcycle-is-Used-in-the-Movie-Ghost-Rider-1536x864.jpg")){ image in
image
.resizable()
.frame(width:proxy.size.width, height: 122)
}placeholder: {
Image("eye").resizable()
.frame(width:UIScreen.main.bounds.width, height: 122)
}
}
}
}
.tabViewStyle(PageTabViewStyle())
.onReceive(timer, perform: { _ in
withAnimation{
currentIndex = currentIndex < totalImages ? currentIndex + 1: 0
}
})
}
}
}
I have attached an image of result what is showing in my Preview Section.