swiftswiftuiwidgetwidgetliveactivity

SwiftUI - ProgressBar inside Live Activity


I am trying to add a simple visual progress bar to my live activity on lock screen or in Digital Island but I can't find a way to trigger progress calculation update. Seems like Timer nor @State work inside of the live activity. Its weird because both native and public apps do use progress bars in activities that update more often then once a second even when apps are suspended and look super smooth.

Apple native timer app still animates smoothly when suspended

enter image description here

One of my favorite apps - Structured also managed to do it when suspended enter image description here

I tried already even adding Lottie animations to the activity :D

Am I missing something?


Solution

  • Apparently you are not allowed to make custom progress bars in the live activity or at least I didn't find a way to do so. iOS is limiting your abilities to trigger timers, loops and any logical methods to update the progress bar. The only way I found doing it is by using a native progress bar

    ProgressView(
        timerInterval: countFrom...endDate,
        countsDown: false,
        label: { EmptyView() },
        currentValueLabel: { EmptyView() }
    )
    .progressViewStyle(.circular)