Eureka icon indicating copy to clipboard operation
Eureka copied to clipboard

DateInlineRow value not updated if tapped other cell too fast

Open GZaccaroni opened this issue 4 years ago • 2 comments

Environment: Eureka 5.2.1, Xcode 11.4.1 and iOS 13.4.1

If I tap another cell while UIDatePicker is still moving value is not saved because removeFromRowObservers is called before datePickerValueChanged(_:) ezgif-4-f46d4fc5744f

GZaccaroni avatar May 17 '20 08:05 GZaccaroni

I think this is expected. Only when datePickerValueChanged is called has the picker really changed its value. Before that, the user might be scrolling through the picker but hasn't chosen a value.

mats-claassen avatar May 18 '20 12:05 mats-claassen

I think this is expected. Only when datePickerValueChanged is called has the picker really changed its value. Before that, the user might be scrolling through the picker but hasn't chosen a value.

datePickerValueChanged is called when DatePicker is hidden and so value is not updated in inline row, with this ugly workaround it behaves correctly.

public typealias DateInlineRowFix = DateInlineRowFix_<Date>
public final class DateInlineRowFix_<T>: _DateInlineRow, RowType, InlineRowType {
    required public init(tag: String?) {
        super.init(tag: tag)
        onExpandInlineRow { cell, row, _ in
            let color = cell.detailTextLabel?.textColor
            row.onCollapseInlineRow { cell, row, inlineRow in
                cell.detailTextLabel?.textColor = color
                DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(600)) {
                    if (row.cell != nil && row.value != inlineRow.value) {
                        row.value = inlineRow.value
                        row.updateCell()
                    }
                }
            }
            cell.detailTextLabel?.textColor = cell.tintColor
        }
    }

    public override func customDidSelect() {
        super.customDidSelect()
        if !isDisabled {
            toggleInlineRow()
        }
    }
}

GZaccaroni avatar May 18 '20 15:05 GZaccaroni