Skip to content

Conversation

chulbert
Copy link

We have a stack view with a row whose hidden state is animated and dependent on user input in a text field meeting certain criteria. As a result, setRowHidden() is called many times in relatively rapid succession with each keystroke. We have seen many scenarios where a succession of setRowHidden(true) renders the row permanently hidden - setRowHidden(false) does nothing. If animation is disabled this issue does not occur.

I believe this is due to overlapping layout operations inside the UIView.animate block of setRowHidden() when called multiple times. My understanding of best practices and guidance from Apple is to call layoutIfNeeded() prior to the animation block to complete/flush any pending layout operations. I have made this change and it resolves the issue.

Copy link
Owner

@marlimox marlimox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this @chulbert! Just one comment.

cell.layoutIfNeeded()
UIView.animate(withDuration: 0.3) {
cell.isHidden = isHidden
cell.layoutIfNeeded()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this second layout call needed now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is the second call, within the animation block, that actually animates the constraint change (via isHidden).

That said, I spoke too soon and this did not actually fix my problem. What is happening is multiple calls to setRowHidden(true) are "accumulating" and setRowHidden(false) does not take effect until it's called enough times to "balance" all the hides. There is a unit test in the project for this scenario - and it passes - but that is exactly what I'm seeing.

I've presently wrapped the call to setRowHidden() in isRowHidden() to execute only when there's a change but that's, well, gross. I'm perplexed.

@wow-such-amazing
Copy link

@chulbert @marlimox I think this is more related to this bug in the UIStackView.
https://github.com/nkukushkin/StackView-Hiding-With-Animation-Bug-Example

I think your wrapper isRowHidden() would be nice to have right inside AloeStackView implementation

@wow-such-amazing
Copy link

Oh, I found that it was merged here 👍
#27

@chulbert
Copy link
Author

@crabman448 You're exactly right. Thank you.

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

Successfully merging this pull request may close these issues.

3 participants