Behaviour of .onAppear/ .onDisappear inside ScrollView

In the code snippet below, .onAppear is triggered on app launch for the 1st Text view. It fires again for the 2nd Text view when scrolled to be visible. Scrolling back to the 1st does not fire .onAppear. .onDisappear is not triggered at all, neither for the 1st Text view after scrolling to the 2nd nor vice versa.

Is this intended behavior?

Any ideas how to trigger .onAppear/ .onDisappear when repeatedly scrolling the views to be visible/ invisible?

I'm using iPadOS 16.1 and Swift Playgrounds 4.2.

import SwiftUI

struct ContentView: View {
    var body: some View {
        ScrollView(.horizontal, showsIndicators: false) {
            LazyHStack {
                Text("1st")
                    .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
                    .onAppear(perform: { print("1st appeared") })
                    .onDisappear(perform: { print("1st disappeared") })
                Text("2nd")
                    .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
                    .onAppear(perform: { print("2nd appeared") })
                    .onDisappear(perform: { print("2nd disappeared") })
            }
        }
    }
}

I think lazy stacks keep each item in memory, so they don't actually disappear. Equally, when you scroll back to the 1st Text() it already got loaded into memory so won't trigger .onAppear() again. In this case, these modifiers are acting more like .onLoad (which isn't a thing).

Sorry I can't be of any help.

Behaviour of .onAppear/ .onDisappear inside ScrollView
 
 
Q