[ad_1]
You need to use enumerated() together with ForEach to trace an index of the array and use it to cover and present your button. One thing like this.
struct ContentView: View {
let gadgets = (1...50).map(String.init)
@State non-public var showScrollButton = false
var physique: some View {
ScrollViewReader { reader in
ZStack(alignment: .bottomTrailing) {
Record {
let enumerated = gadgets.enumerated().map({ $0 })
ForEach(enumerated, id: .factor) { (index, merchandise) in
Textual content(merchandise)
.id(index)
.onAppear {
guard index == 0, showScrollButton else {
return
}
showScrollButton = false
}
.onDisappear {
guard index == 0, !showScrollButton else {
return
}
showScrollButton = true
}
}
}
if showScrollButton {
Button(motion: {
withAnimation {
reader.scrollTo(0, anchor: .prime)
}
}, label: {
Picture(systemName: "chevron.up.circle")
.font(.largeTitle)
.foregroundColor(.black)
.padding()
.padding(.trailing)
})
}
}
}
}
}
[ad_2]
