.onAppear() and .onDisappear() not running in child views (WatchOS 8 beta 4)

I'm working on a companion Watch App for my iOS App.

.onAppear() and .onDisappear() do not run if they're inside a child view of the three main views in my content view. For example, my first page is a list of workouts, If I click and navigate to a workout on the list the .onAppear() on that workout page does not run. Is this a bug on WatchOS 8 beta 4 or am I doing something wrong? The iOS app has very similar functionality and the .onAppear/.onDisappear all work fine on iOS 15 beta 4. Lastly, they seem to work in previews, just not in simulators or my device.

The content view for the app (Those 3 functions do run):

import SwiftUI
import CoreData

struct ContentView: View {
   
  @Environment(\.managedObjectContext) private var viewContext
   
  var body: some View {
    TabView {
      WorkoutList()
      ExerciseList()
      HeartRate()
    }
    .onAppear {
      loadDefaultExercises()
      loadDefaultWorkouts()
      loadProfile()
    }
  }
  func loadDefaultExercises() -> () {...     }
  func loadDefaultExercises() -> () {...     }
  func loadDefaultExercises() -> () {...     }
}

The WorkoutList() view (.onAppear/.onDisappears placed in here do run but only once at app launch):

import SwiftUI

struct WorkoutList: View {
   
  @Environment(\.managedObjectContext) private var viewContext
   
  @FetchRequest(
    sortDescriptors: [NSSortDescriptor(keyPath: \Workout.name, ascending: true)],
    animation: .default)
  var workouts: FetchedResults<Workout>
   
  var body: some View {
    NavigationView {
      List {
        ForEach(workouts) { workout in
          NavigationLink(destination: WorkoutDetail(workout: workout)) {
            WorkoutListRow(workout: workout)
          }
        }
      }
      .navigationTitle("Workouts")
      .onAppear {
          print("On Appear (Working but only once on launch)")
      }
    }
  }
}

The WorkoutDetail page that appears when I click on a workout from WorkoutList() (.onAppear/.onDisappears placed in here on any child views from here do not run):

import SwiftUI
import CoreData

struct WorkoutDetail: View {
   
  @ObservedObject var workout: Workout
   
  var body: some View {
    ScrollView {
      VStack(alignment: .leading) {...    }
    }
    .onAppear {
      print("On Appear (NOT WORKING)")
    }
    .navigationTitle(workout.name ?? "")
  }
}

Thanks in advance.

Answered by Lobooo in 731567022

In swiftui, I meet the same question, with a list in navigation, I added a footer view, onappear didn't work well when the footer view appears, but worked when back to home...

The same is happening with my code: onAppear() does not fire when the view on which it is called is nested too deeply. For example, if the body chain is ContentView->ViewController->MyView->Image, and the onAppear() is called on Image within the body of MyView, then it will not fire. However if Image is instead referenced within the body of ViewController, as a parameter to MyView, then onAppear will fire.

Accepted Answer

In swiftui, I meet the same question, with a list in navigation, I added a footer view, onappear didn't work well when the footer view appears, but worked when back to home...

.onAppear() and .onDisappear() not running in child views (WatchOS 8 beta 4)
 
 
Q