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

onCellUnHighlight doesn't get called unless onCellHighlight is also defined #96

Closed
jefflai opened this issue Nov 20, 2015 · 4 comments
Closed

Comments

@jefflai
Copy link

jefflai commented Nov 20, 2015

The onCellUnHighlight function for a Row doesn't get called if the onCellHighlight function is not also specified for the Row. This is confusing because the documentation doesn't state that both of these functions have to be defined for onCellUnHighlight to work.

This is the debug code I used to find this bug.

form +++ Section("Debug")
            <<< TextRow("debugTextRow1") {
                    $0.title = "Debug Text Row 1"
                }.onCellHighlight { cell, row in
                    print("text onCellHighlight 1")
                }.onCellUnHighlight{ cell, row in
                    print("text onCellUnHighlight 1")
                }
            <<< TextRow("debugTextRow2") {
                    $0.title = "Debug Text Row 2"
                }.onCellUnHighlight{ cell, row in
                    print("text onCellUnHighlight 2")
                }

Tapping on debugTextRow1 and then tapping outside debugTextRow1 to trigger onCellUnHighlight works as expected with both onCellHighlight and onCellUnHighlight defined.

However, doing the same steps with debugTextRow2 doesn't work as expected. The onCellUnHighlight function for debugTextRow2 is never called.

I'm using XCode 7.1.1 and the project has a deployment target of iOS 9.1

@mtnbarreto
Copy link
Member

@jefflai Actually this is not an issue. This is how onCellHighlight and onCellUnHighlight work by default.

Your custom onCellUnHighlight is not being invoked because each time the cell is highlighted we override onCellUnHighlight as shown below.

public final class TextRow: _TextRow, RowType {
    required public init(tag: String?) {
        super.init(tag: tag)
        onCellHighlight { cell, row  in
            let color = cell.textLabel?.textColor
            row.onCellUnHighlight { cell, _ in
                cell.textLabel?.textColor = color
            }
            cell.textLabel?.textColor = cell.tintColor
        }
    }
}

The reason we override by default the onCellUnHighlight from inside onCellHighlight is to put back the original label text color since it can be changed at any time.

So in order to avoid this you must set up a onCellHighlight function in addition to onCellUnHighlight. Your custom onCellHighlight will not override onCellUnHighlight.

Regards

@jefflai
Copy link
Author

jefflai commented Nov 20, 2015

@mtnbarreto ok that makes sense. perhaps the ReadMe should be updated to explain this

@mtnbarreto
Copy link
Member

@jefflai done

@jefflai
Copy link
Author

jefflai commented Nov 20, 2015

Thanks! @mtnbarreto

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

No branches or pull requests

2 participants