Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to update StepperView Steps dynamically from UIKit #98

Open
sajidjutt7 opened this issue Feb 23, 2024 · 0 comments
Open

How to update StepperView Steps dynamically from UIKit #98

sajidjutt7 opened this issue Feb 23, 2024 · 0 comments

Comments

@sajidjutt7
Copy link

sajidjutt7 commented Feb 23, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant