Juanpe / SkeletonView

☠️ An elegant way to show users that something is happening and also prepare them to which contents they are awaiting
MIT License
12.53k stars 1.1k forks source link

fix bug remove constraints wrongly #406

Closed Juanpe closed 3 years ago

Juanpe commented 3 years ago

Summary

Fixes #405

This PR fixes a bug related to the constraints that SkeletonView added to labels when the skeleton is active. The previous logic was:

When the labels are prepared for the skeleton:

  1. Check the desired height for labels.
  2. If needed, backup the current constraints and remove them.
  3. Activate the calculated skeleton constraints.

When the skeleton disappears

  1. Remove all the constraints related to the height.
  2. If there are some constraints backed up, restore them.

The problem was step 1 when the skeleton disappears because we were always removing the height constraints, even if the library had added no constraints.

The solution is to add an identifier to constraints added by the library. Then, SkeletonView only removes the constraints added by the library. So, the logic now when the skeleton disappears is:

  1. Remove all the constraints related to the height added by the library.
  2. If there are some constraints backed up, restore them.

Requirements