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.51k stars 1.1k forks source link

`lastLineFillPercent` doesn't work on one-line text views #430

Closed lopesmcc closed 2 years ago

lopesmcc commented 2 years ago

lastLineFillPercent by design is limited to multiline text views. It's mostly due to the following lines within the calculatedWidthForLine function:

        if index == totalLines - 1 && totalLines != 1 {
            width = width * CGFloat(lastLineFillPercent) / 100
        }

I believe removing the totalLines != 1 would be enough to enable fill percent for one-line text views, but am unsure of side-effects as I haven't tested it.

I was curious however as to why limit the skeleton view to not allow changing the skeleton fill-percent on one-line text views. Is there a reason for this?

It would be useful as some skeleton designs don't fill the whole width of the view. To go around this, I've been using skeletonPaddingInsets, but IMO it would be a lot cleaner and precise using the lastLineFillPercent attribute instead.

Juanpe commented 2 years ago

Hi @lopesmcc 👋🏼

TBH, I didn't consider this scenario until now, but I agree with you and I can find no good reasons to do that 🤔 The only important thing would be to update the README file indicating that lastLineFillPercent will be applied to the one-line labels as well.

Would you like to contribute? 🙂

selanthiraiyan commented 2 years ago

@Juanpe Hello, Hope you are doing well. I have created a PR to add the change that was suggested by @lopesmcc. I have tested this by altering the labels and textviews in the iOS Example's Main.storyboard file. As far as I understood the code, this change doesn't break anything else. Kindly let me know your thoughts. Thank you!