airbnb / lottie-ios

An iOS library to natively render After Effects vector animations
http://airbnb.io/lottie/
Apache License 2.0
25.76k stars 3.75k forks source link

Load DotLottie error in list cell #2231

Closed wuyy closed 11 months ago

wuyy commented 11 months ago

Which Version of Lottie are you using?

Lottie 4.3.3

Expected Behavior

Loaded successfully and can be played separately

Actual Behavior

LottieAnimationView init completion error:

error:==Optional(Error Domain=NSCocoaErrorDomain Code=4 "The file doesn’t exist.") Error when decoding lottie "btn_good_comment": Error Domain=NSCocoaErrorDomain Code=3840 "No value." UserInfo={NSDebugDescription=No value.} error:==Optional(Error Domain=NSCocoaErrorDomain Code=3840 "No value." UserInfo={NSDebugDescription=No value.}) Error when decoding lottie "btn_good_comment": Error Domain=NSCocoaErrorDomain Code=516 "The file “manifest.json” couldn’t be saved in the folder “btn_good_comment” because a file with the same name already exists." UserInfo={NSFilePath=/private/var/mobile/Containers/Data/Application/C764EBFC-6DE9-4E1B-87CA-7B81831E3465/tmp/btn_good_comment/manifest.json} Error when decoding lottie "btn_good_comment": Error Domain=NSCocoaErrorDomain Code=516 "The file “manifest.json” couldn’t be saved in the folder “btn_good_comment” because a file with the same name already exists." UserInfo={NSFilePath=/private/var/mobile/Containers/Data/Application/C764EBFC-6DE9-4E1B-87CA-7B81831E3465/tmp/btn_good_comment/manifest.json} error:==nil

Code

class LottieTableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        tableView.register(TestLottieCell.self, forCellReuseIdentifier: "reuseIdentifier")
    }

    // MARK: - Table view data source
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) as? TestLottieCell {
            return cell
        }
        return UITableViewCell()
    }

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 80
    }
}
class TestLottieCell: UITableViewCell {
    lazy var lottieAnimationView: LottieAnimationView = {
        let view = LottieAnimationView(dotLottieName: "btn_good_comment") { _, error in
            print("error:==\(error.debugDescription)")
        }
        return view
    }()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func setupUI() {
        contentView.addSubview(self.lottieAnimationView)
        self.lottieAnimationView.frame = CGRect(x: 200, y: 10, width: 50, height: 50)
    }
}
calda commented 11 months ago

Can you please share a full sample project that demonstrates this issue, with repro steps? Thanks!

calda commented 11 months ago

If you update your dependency to point to the latest commit on master, you may find that this PR already fixed the problem: https://github.com/airbnb/lottie-ios/pull/2229 it sounds like it could potentially be related

wuyy commented 11 months ago

That's the problem.#2229