@momo-kits/native-kits 0.151.2-test.8 → 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
- var name: String = ""
14
- var url: String?
15
- var loopMode: LottieLoopMode = .playOnce
16
- var contentMode : UIView.ContentMode = .scaleAspectFit
17
- var onDone: (() -> Void)?
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
- // Add static cache for animations
20
- private static var animationCache = NSCache<NSString, LottieAnimation>()
33
+ // Add static cache for animations
34
+ public static var animationCache = NSCache<NSString, LottieAnimation>()
21
35
 
22
- func makeUIView(context: UIViewRepresentableContext<LottieView>) -> UIView {
23
- let view = UIView(frame: .zero)
36
+ public func makeUIView(context: UIViewRepresentableContext<LottieView>) -> UIView {
37
+ let view = UIView(frame: .zero)
24
38
 
25
- // Configure Lottie with optimized settings
26
- let configuration = LottieConfiguration(
27
- renderingEngine: .coreAnimation,
28
- decodingStrategy: .dictionaryBased
29
- )
39
+ // Configure Lottie with optimized settings
40
+ let configuration = LottieConfiguration(
41
+ renderingEngine: .coreAnimation,
42
+ decodingStrategy: .dictionaryBased
43
+ )
30
44
 
31
- let animationView = LottieAnimationView(configuration: configuration)
45
+ let animationView = LottieAnimationView(configuration: configuration)
32
46
 
33
- if let url = url {
34
- // Use cached animation if available
35
- if let cachedAnimation = Self.animationCache.object(forKey: url as NSString) {
36
- animationView.animation = cachedAnimation
37
- setupAnimationView(animationView, view)
38
- } else {
39
- LottieAnimation.loadedFrom(url: URL(string: url)!, closure: { animation in
40
- if let animation = animation {
41
- Self.animationCache.setObject(animation, forKey: url as NSString)
42
- animationView.animation = animation
43
- setupAnimationView(animationView, view)
44
- }
45
- }, animationCache: nil)
46
- }
47
- } else {
48
- // Use cached animation if available
49
- if let cachedAnimation = Self.animationCache.object(forKey: name as NSString) {
50
- animationView.animation = cachedAnimation
51
- setupAnimationView(animationView, view)
52
- } else if let animation = LottieAnimation.named(name) {
53
- Self.animationCache.setObject(animation, forKey: name as NSString)
54
- animationView.animation = animation
55
- setupAnimationView(animationView, view)
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
- return view
60
- }
73
+ return view
74
+ }
61
75
 
62
- private func setupAnimationView(_ animationView: LottieAnimationView, _ containerView: UIView) {
63
- animationView.contentMode = contentMode
64
- animationView.loopMode = loopMode
65
- animationView.backgroundBehavior = loopMode == .loop ? .pauseAndRestore : .pause
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
- // Optimize rendering
68
- animationView.shouldRasterizeWhenIdle = true
81
+ // Optimize rendering
82
+ animationView.shouldRasterizeWhenIdle = true
69
83
 
70
- animationView.translatesAutoresizingMaskIntoConstraints = false
71
- containerView.addSubview(animationView)
84
+ animationView.translatesAutoresizingMaskIntoConstraints = false
85
+ containerView.addSubview(animationView)
72
86
 
73
- NSLayoutConstraint.activate([
74
- animationView.widthAnchor.constraint(equalTo: containerView.widthAnchor),
75
- animationView.heightAnchor.constraint(equalTo: containerView.heightAnchor)
76
- ])
87
+ NSLayoutConstraint.activate([
88
+ animationView.widthAnchor.constraint(equalTo: containerView.widthAnchor),
89
+ animationView.heightAnchor.constraint(equalTo: containerView.heightAnchor)
90
+ ])
77
91
 
78
- animationView.play { finished in
79
- if finished {
80
- onDone?()
81
- }
92
+ animationView.play { finished in
93
+ if finished {
94
+ onDone?()
95
+ }
96
+ }
82
97
  }
83
- }
84
98
 
85
- func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<LottieView>) {}
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
- var name: String = ""
15
- var url: String?
16
- var loopMode: LottieLoopMode = .playOnce
17
- var frame: CGRect
18
- var id: String?
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.151.2-test.8",
3
+ "version": "0.151.2-test.9",
4
4
  "private": false,
5
5
  "dependencies": {
6
6
  "@momo-platform/native-max-api": "1.0.18"