ScrollStackController icon indicating copy to clipboard operation
ScrollStackController copied to clipboard

Fix: `ScrollStackControllerDelegate` methods calls

Open NicFontana opened this issue 1 year ago • 2 comments

This PR adresses an issue that causes calls to the ScrollStackControllerDelegate methods

  • scrollStackRowDidBecomeVisible(_:row:index:state:)
  • scrollStackRowDidBecomeHidden(_:row:index:state:)

before the completion of the ScrollStack layout process, when each rows still don't have a valid frame.

This can happen for example when a ViewController uses a ScrollStack as a subview and inserts rows in a for-loop inside its viewDidLoad() method.

Now these methods are called:

  1. Only once after all the rows have been added and the ScrollStack has been fully laid out
  2. When the user scrolls

A fix has been also made to the dispatchRowsVisibilityChangesTo(_:) ScrollStack method: it now takes into account new inserted rows which still don't have a previous visibility state.


Finally, the call to askForCutomizedSizeOfContentView(animated:) of ScrollStackRow has been moved back in the updateConstraints() method following the best practices described in ModifyingConstraints:

To batch a change, instead of making the change directly, call the setNeedsUpdateConstraints method on the view holding the constraint. Then, override the view’s updateConstraints method to modify the affected constraints. Always call the superclasses implementation as the last step of your updateConstraints method’s implementation.

This is necessary because we call setNeedsUpdateConstraints() in the layoutUI() method of ScrollStackRow.

NicFontana avatar May 07 '24 15:05 NicFontana

Hi @NicFontana , thank you for PR. I would also add the new logic to get the size of the view by reading contentView instead of stackView as described in this commit. Would you add it to this PR so we'll avoid to merge both of them.

malcommac avatar May 10 '24 12:05 malcommac

I'm not sure I've correctly understood, where should I add this logic?

NicFontana avatar May 10 '24 13:05 NicFontana

my bad, it was already on develop. merging it, thanks!

malcommac avatar May 20 '24 14:05 malcommac