Search code examples
iosswift3eureka-forms

iOS eureka-forms LabelRow hidden condition not evaluating


Setup

  • Swift 3.1
  • iOS 10.0
  • Eureka 3.0

Problem

Can not make a LabelRow hide together with a TextAreaRow hidden state. The label is defined before adding both to a section. It gets added on top of the text.

Code

After a few different ways to define the Condition, when debugging, it seems the function is not getting called. Only in the first 2 it gets called once, but not when the TextAreaRow changes to hide or show

    let switchRowTag = "switchRowTag"
    form +++ section
        <<< SwitchRow(switchRowTag) { row in
            row.title = "Select me"}

    // Test hiding functions ========================
    let tag = "textArea"
    let title = "Test Hiding"
    let labelTag = "\(tag)_label"
    let textArea = TextAreaRow(tag) {
        $0.title = title
        $0.tag = tag
        $0.placeholder = title
        $0.textAreaHeight = .dynamic(initialTextViewHeight: 110)
        $0.hidden = Condition.predicate(NSPredicate(format: "$\(switchRowTag) == false"))
    }
    let labelRow = LabelRow(labelTag) {
        $0.title = title
        $0.tag = labelTag
        /* try setting the function after adding to the section
        $0.hidden = Condition.function([tag], { form in
            if let textRow = form.rowBy(tag: tag) as? TextAreaRow {
                return textRow.isHidden
            } else {
                return false
            }
        })
         */
    }

    section <<< labelRow <<< textArea
    // Is never evaluated
    /*
    labelRow.hidden = Condition.function([tag], { form in
        if let textRow = form.rowBy(tag: tag) as? TextAreaRow {
            return textRow.isHidden
        } else {
            return false
        }
    })
     */
    if let labelRow = form.rowBy(tag: labelTag) as? LabelRow {
        labelRow.hidden = Condition.function([tag], { form in
            if let textRow = form.rowBy(tag: tag) as? TextAreaRow {
                return textRow.isHidden
            } else {
                return false
            }
        })
    }

Solution

  • It is currently not supported.

    Eureka supports only reevaluating the hidden conditions, when the row related by the tag depended upon has a change of value only. Not a change of visibility (ref).