@momo-kits/native-kits 0.151.2-test.7 → 0.151.2-test.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,81 +6,95 @@
|
|
|
6
6
|
// Copyright © 2023 Facebook. All rights reserved.
|
|
7
7
|
//
|
|
8
8
|
|
|
9
|
-
import SwiftUI
|
|
10
9
|
import Lottie
|
|
10
|
+
import SwiftUI
|
|
11
11
|
|
|
12
|
-
struct LottieView: UIViewRepresentable {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
public struct LottieView: UIViewRepresentable {
|
|
13
|
+
public var name: String = ""
|
|
14
|
+
public var url: String?
|
|
15
|
+
public var loopMode: LottieLoopMode = .playOnce
|
|
16
|
+
public var contentMode: UIView.ContentMode = .scaleAspectFit
|
|
17
|
+
public var onDone: (() -> Void)?
|
|
18
|
+
|
|
19
|
+
public init(
|
|
20
|
+
name: String = "",
|
|
21
|
+
url: String? = nil,
|
|
22
|
+
loopMode: LottieLoopMode = .playOnce,
|
|
23
|
+
contentMode: UIView.ContentMode = .scaleAspectFit,
|
|
24
|
+
onDone: (() -> Void)? = nil
|
|
25
|
+
) {
|
|
26
|
+
self.name = name
|
|
27
|
+
self.url = url
|
|
28
|
+
self.loopMode = loopMode
|
|
29
|
+
self.contentMode = contentMode
|
|
30
|
+
self.onDone = onDone
|
|
31
|
+
}
|
|
18
32
|
|
|
19
|
-
|
|
20
|
-
|
|
33
|
+
// Add static cache for animations
|
|
34
|
+
public static var animationCache = NSCache<NSString, LottieAnimation>()
|
|
21
35
|
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
public func makeUIView(context: UIViewRepresentableContext<LottieView>) -> UIView {
|
|
37
|
+
let view = UIView(frame: .zero)
|
|
24
38
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
// Configure Lottie with optimized settings
|
|
40
|
+
let configuration = LottieConfiguration(
|
|
41
|
+
renderingEngine: .coreAnimation,
|
|
42
|
+
decodingStrategy: .dictionaryBased
|
|
43
|
+
)
|
|
30
44
|
|
|
31
|
-
|
|
45
|
+
let animationView = LottieAnimationView(configuration: configuration)
|
|
32
46
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
if let url = url {
|
|
48
|
+
// Use cached animation if available
|
|
49
|
+
if let cachedAnimation = Self.animationCache.object(forKey: url as NSString) {
|
|
50
|
+
animationView.animation = cachedAnimation
|
|
51
|
+
setupAnimationView(animationView, view)
|
|
52
|
+
} else {
|
|
53
|
+
LottieAnimation.loadedFrom(url: URL(string: url)!, closure: { animation in
|
|
54
|
+
if let animation = animation {
|
|
55
|
+
Self.animationCache.setObject(animation, forKey: url as NSString)
|
|
56
|
+
animationView.animation = animation
|
|
57
|
+
setupAnimationView(animationView, view)
|
|
58
|
+
}
|
|
59
|
+
}, animationCache: nil)
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
// Use cached animation if available
|
|
63
|
+
if let cachedAnimation = Self.animationCache.object(forKey: name as NSString) {
|
|
64
|
+
animationView.animation = cachedAnimation
|
|
65
|
+
setupAnimationView(animationView, view)
|
|
66
|
+
} else if let animation = LottieAnimation.named(name) {
|
|
67
|
+
Self.animationCache.setObject(animation, forKey: name as NSString)
|
|
68
|
+
animationView.animation = animation
|
|
69
|
+
setupAnimationView(animationView, view)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
58
72
|
|
|
59
|
-
|
|
60
|
-
|
|
73
|
+
return view
|
|
74
|
+
}
|
|
61
75
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
private func setupAnimationView(_ animationView: LottieAnimationView, _ containerView: UIView) {
|
|
77
|
+
animationView.contentMode = contentMode
|
|
78
|
+
animationView.loopMode = loopMode
|
|
79
|
+
animationView.backgroundBehavior = loopMode == .loop ? .pauseAndRestore : .pause
|
|
66
80
|
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
// Optimize rendering
|
|
82
|
+
animationView.shouldRasterizeWhenIdle = true
|
|
69
83
|
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
animationView.translatesAutoresizingMaskIntoConstraints = false
|
|
85
|
+
containerView.addSubview(animationView)
|
|
72
86
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
87
|
+
NSLayoutConstraint.activate([
|
|
88
|
+
animationView.widthAnchor.constraint(equalTo: containerView.widthAnchor),
|
|
89
|
+
animationView.heightAnchor.constraint(equalTo: containerView.heightAnchor)
|
|
90
|
+
])
|
|
77
91
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
92
|
+
animationView.play { finished in
|
|
93
|
+
if finished {
|
|
94
|
+
onDone?()
|
|
95
|
+
}
|
|
96
|
+
}
|
|
82
97
|
}
|
|
83
|
-
}
|
|
84
98
|
|
|
85
|
-
|
|
99
|
+
public func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<LottieView>) {}
|
|
86
100
|
}
|
|
@@ -11,13 +11,13 @@ import Lottie
|
|
|
11
11
|
import SwiftUI
|
|
12
12
|
|
|
13
13
|
public class LottieViewController: UIViewController {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
public var name: String = ""
|
|
15
|
+
public var url: String?
|
|
16
|
+
public var loopMode: LottieLoopMode = .playOnce
|
|
17
|
+
public var frame: CGRect
|
|
18
|
+
public var id: String?
|
|
19
19
|
|
|
20
|
-
init(name: String, url: String? = nil, loopMode: LottieLoopMode, frame: CGRect, id: String? = nil) {
|
|
20
|
+
public init(name: String, url: String? = nil, loopMode: LottieLoopMode, frame: CGRect, id: String? = nil) {
|
|
21
21
|
self.name = name
|
|
22
22
|
self.url = url
|
|
23
23
|
self.loopMode = loopMode
|