StepperView icon indicating copy to clipboard operation
StepperView copied to clipboard

How to update StepperView Steps dynamically from UIKit

Open sajidjutt7 opened this issue 1 year ago • 0 comments

I am using this stepper view in UIKit and adding it programmatically in my code. For Static data. It is working perfectly.

I have to pass data for Steps and Indicators from an array of tracking details. Below is the detailed code

    var trackings = event?.getTracking() // My Tracking data
    var trackingSteps: [AnyView] = []
    var trackingIndicators: [StepperIndicationType<AnyView>] = []

    for item in trackings! {
        trackingSteps.append(
            HStack() {
                VStack(alignment: .leading) {
                    Text(title)
                    Text(description)
                    Text(dateTime)
                }
                
                VStack(alignment: .trailing) {
                    Button(action: {
                        item.isCompleted.toggle() // This is suppose to change button image but not doing it :( 
                    }) {
                        Image(item.isCompleted == true ? ImagesNames.ic_toggle_on : ImagesNames.ic_toggle_off)
                    }
                }
            }
        )
        
        trackingIndicators.append(StepperIndicationType.custom(MyCustomImage))
    }
    

Now using the above steps and indicators to make SwiftUIView

    var stepperView = StepperView()
        .addSteps(trackingSteps) // [View]
        .indicators(trackingIndicators)  // [StepperIndicationType<View>]
        .onAppear(perform: {
           self.trackingD[1].isCompleted = true // This also not working
        })
    
    let host = UIHostingController(rootView: stepperView)
    let hostView = host.view!
    addChild(host)
    trackingListView.addSubview(hostView)

In this above code. Inside VStack of Steps Button is bind with image with mutating data. When the item.isCompleted gets toggled which is finely doing so. The button image is not changing.

I have tried all. I am able to set the UI elements of SwiftUIView for the first time of calling. They are not changing themselves afterward.

What i am missing?

sajidjutt7 avatar Feb 23 '24 11:02 sajidjutt7