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.59k stars 1.11k forks source link

Fix incorrect padding and multiline layer frame calculation #340

Closed yzhao198 closed 3 years ago

yzhao198 commented 3 years ago

Summary

Thank you for writing this library. Here is a snippet of code I used when testing SkeletonView:

import UIKit
import SkeletonView

class ViewController: UIViewController {

    private lazy var label: UILabel = {
        let label = UILabel()
        label.translatesAutoresizingMaskIntoConstraints = false
        label.numberOfLines = 2
        label.skeletonLineSpacing = 8
        label.font = .systemFont(ofSize: 10)
        label.lastLineFillPercent = 50
        label.skeletonPaddingInsets = .init(top: 12, left: 0, bottom: 12, right: 30)
        label.isSkeletonable = true

        return label
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white

        SkeletonAppearance.default.multilineHeight = 12

        view.addSubview(label)

        label.heightAnchor.constraint(equalToConstant: 54).isActive = true
        label.widthAnchor.constraint(equalToConstant: 250).isActive = true
        label.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        label.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true

        view.isSkeletonable = true
        view.showSkeleton()
    }
}

The desired result should be

Screen Shot 2020-10-08 at 8 30 09 PM

but the current version (1.10.0) gives me

Screen Shot 2020-10-08 at 8 34 58 PM

Given my testing device is NOT RTL, it is clear the padding is incorrectly rendered. After the changes made in this MR, the desired result is achieved.

Requirements (place an x in each of the [ ])

Juanpe commented 3 years ago

Hi @yzhao198, thanks for your first contribution. I've checked the code and it looks perfect.

There is only one thing to do before merging. You should update the CHANGELOG file including this PR, ok?

Thanks again

yzhao198 commented 3 years ago

Thanks for your review @Juanpe I've updated CHANGELOG.md.