xmartlabs / Eureka

Elegant iOS form builder in Swift
https://eurekacommunity.github.io
MIT License
11.79k stars 1.33k forks source link

Row in SelectableSection is disabled when navigating back to the form #2053

Closed xav1b closed 4 years ago

xav1b commented 4 years ago

Eureka version 5.2.1 Xcode 11.4 iOS 13.5.1

I have two check box rows in a .singleSelection(enableDeselection: false) SelectableSection that unintentionally become disabled when navigating away from the screen and then returning to it. I say that because Im not sure what causes the switch. I have tried explicitly setting $0.disabled = false when creating the row then again in a viewWillAppear function followed by a call to evaluateDisabled() but no luck. I found that the prepare function in the SelectableSection class as the blocker for the desired behavior. Any thoughts on why the rows are disabled when returning to the form?


func prepare(selectableRows rows: [BaseRow]) {
         for row in rows {
            if let row = row as? SelectableRow {
                row.onCellSelection { [weak self] cell, row in
                    guard let s = self, !row.isDisabled else { return } // !row.isDisabled is the blocker
                    switch s.selectionType {
                    case .multipleSelection:
                        row.value = row.value == nil ? row.selectableValue : nil
                    case let .singleSelection(enableDeselection):
                        s.forEach {
                            guard $0.baseValue != nil && $0 != row && $0 is SelectableRow else { return }
                            $0.baseValue = nil
                            $0.updateCell()
                        }
                        // Check if row is not already selected
                        if row.value == nil {
                            row.value = row.selectableValue
                        } else if enableDeselection {
                            row.value = nil
                        }
                    }
                    row.updateCell()
                    s.onSelectSelectableRow?(cell, row)
                }
            }
        }
    }
mats-claassen commented 4 years ago

Eureka's code does not set the section to disabled. Maybe you should make sure that you are not doing it somewhere else. And make sure that isDisabled is actually the reason why the guard statement is false.

xav1b commented 4 years ago

@mats-claassen To give a little more context, I have a CheckBoxRow which is a subclass of Row and every time it's interacted with, the row simply updates it's UI between an on and off state. I'm not explicitly setting disabled to true anywhere because there's no case where I would want a checkbox row to be disabled. In an attempt to ensure it isn't, I set row.disabled = false in update() as well as the places mentioned before.

Example: disabled_row

Print statements in Eureka code

Screen Shot 2020-06-25 at 12 22 04 PM Screen Shot 2020-06-25 at 12 19 43 PM

When successfully checking a row:

Screen Shot 2020-06-25 at 11 00 57 AM

Navigating back to the screen and trying to check a row:

Screen Shot 2020-06-25 at 11 04 36 AM
mats-claassen commented 4 years ago

It is weird. I cannot reproduce it. isDisabled is an interface to disabledCache which is only reset in evaluateDisabled so I don't understand how you can have disabled rows there unless some part of your code does it.

I can't investigate this without a sample project as I cannot reproduce it with a simple push and back.

xav1b commented 4 years ago

Found the bug. Overlooked a line of code on my end. Closing the issue