onDisappear not getting called for widget

Below is the body of my main entry view for a widget.

onAppear seems to be working fine, but onDisappear is never getting called.

How can I know that widget is offscreen and not visible to the user?

Are there any other events similar to view controller lifecycle for a swiftui view?


var body: some View {
    Text("Hello world")
      .onAppear{
        print("onAppear called")
      }
      .onDisappear {
        print("onDisappear called")
      }
  }

Console output

onAppear called



I don't work at Apple so my word isn't canonical, but my instinct is that the fact that onAppear is working is a bug. The widgets are totally static, you should imagine that they are generating a still image which is shown the user at the system's discretion. Much like the app switcher screens, or launch screens.

They can't take any action on being shown or hidden, or under any other circumstance.
You should not use onAppear or onDisappear with Widgetkit because widget is much like a pre-built image.
Just prepare all necessary data in Widget Entry then show it for each timeline
onDisappear not getting called for widget
 
 
Q