-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeymeLottie.swift
49 lines (41 loc) · 1.45 KB
/
KeymeLottie.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// KeymeLottie.swift
// DSKit
//
// Created by 김영인 on 2023/08/13.
// Copyright © 2023 team.humanwave. All rights reserved.
//
import SwiftUI
import Lottie
public struct KeymeLottieView: UIViewRepresentable {
public let asset: AnimationAsset
public let loopMode: LottieLoopMode
public var completion: (() -> Void)?
public init(asset: AnimationAsset,
loopMode: LottieLoopMode = .playOnce,
completion: (() -> Void)? = nil) {
self.asset = asset
self.loopMode = loopMode
self.completion = completion
}
public func makeUIView(context: Context) -> some UIView {
let lottieView = LottieAnimationView(animation: asset.animation)
lottieView.translatesAutoresizingMaskIntoConstraints = false
lottieView.loopMode = loopMode
lottieView.contentMode = .scaleAspectFill
lottieView.play(completion: { finished in
if finished {
completion?()
}
})
let containerView = UIView(frame: .zero)
containerView.addSubview(lottieView)
NSLayoutConstraint.activate([
lottieView.heightAnchor.constraint(equalTo: containerView.heightAnchor),
lottieView.widthAnchor.constraint(equalTo: containerView.widthAnchor)
])
return containerView
}
public func updateUIView(_ uiView: UIViewType, context: Context) {
}
}