SwiftUI TabView with PageTabViewStyle calls onAppear of children multiple times on iOS 14.2

Number:rdar://FB8907671 Date Originated:11/19/2020
Status:Open Resolved:
Product:SwiftUI Framework Product Version:14.2
Classification: Reproducible:Yes
On iOS 14.2, when using the TabView in SwiftUI in combination with a PageTabViewStyle, the onAppear function of its children will be called excessively. When running the app on iOS 14, onAppear is called exactly once for each child when it appears.

Steps to reproduce:
- Add the following code to a view:
TabView {
    Text("First text")
        .onAppear {
            print("First text appeared")
    Text("Second text")
        .onAppear {
            print("Second text appeared")
    Text("Third text")
        .onAppear {
            print("Third text appeared")
    Text("Fourth text")
        .onAppear {
            print("Fourth text appeared")
}.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))

- run the app in a simulator or on a device
- swipe through the tabs

Expected behavior:
- The message is printed once when swiping between tabs.

Actual behavior:
- (iOS 14.2) The message is printed multiple times when swiping between tabs.
- (iOS 14) The message is printed once when swiping between tabs.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!