0

How to implement custom progress view with moving car,

I'm implementing live activity in which I'm stuck in progress view where the default linear which is working well

                    ProgressView(

                        timerInterval: Date()...context.state.deliveryTime,

                        countsDown: false,

                        label: { EmptyView() },

                        currentValueLabel: { EmptyView() }

                    )

struct EmojiProgressViewStyle: ProgressViewStyle {
    var emoji: String
    func makeBody(configuration: Configuration) -> some View {
        GeometryReader { geometry in
            ZStack(alignment: .leading) {
                RoundedRectangle(cornerRadius: 10)
                    .foregroundColor(Color.gray.opacity(0.3))
                    .frame(width: geometry.size.width, height: 10)
                
                RoundedRectangle(cornerRadius: 10)
                    .foregroundColor(.purple)
                    .frame(width: geometry.size.width * CGFloat(configuration.fractionCompleted ?? 0.1), height: 10)
                
                Text(emoji)
                    .frame(width: 20, height: 20)
                    .background(.clear)
                    .cornerRadius(10)
                    .position(x: geometry.size.width * CGFloat(configuration.fractionCompleted ?? 0.1), y: 5)
            }
        }
    }
}

but while using custom progress view style, I need to move that progress

Here is the code where the .fractionCompleted method is always 0, so can you help me here

how to fix or in your way you have implemented it

NOTE: This code is done in Live Activity.

The problem is that default progress view handles the progress but when tying to use custom progress style the fractionCompleted method always comes zero,

Does there is any way to solve this problem,

Thanks in advance for help

  • It seems that updates don't work for a custom ```ProgressViewStyle``` when used with a ```ProgressView``` initialized with with a closed range of ```Date``` values. This is corroborated by [Serialcoder.dev](https://serialcoder.dev/text-tutorials/swiftui/swiftui-progress-view-showing-time-progress/). See also [SwiftUI - ProgressBar inside Live Activity](https://stackoverflow.com/q/76444040/20386264). – Benzy Neez Sep 01 '23 at 19:43

0 Answers0