@amazon-devices/lottie-react-native 2.0.1758683737

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.
Files changed (60) hide show
  1. package/LICENSE +7 -0
  2. package/SystemBundles/90296ccfe5ff2db2f9fe68a18eca092f8b7c17d1125cfafc612d18788fe9bce6.bundle +10322 -0
  3. package/SystemBundles/90296ccfe5ff2db2f9fe68a18eca092f8b7c17d1125cfafc612d18788fe9bce6.map +1 -0
  4. package/SystemModules/amzn__lottie-react-native-2.modules.txt +13 -0
  5. package/SystemModules/amzn__lottie-react-native-2.private.modules.txt +92 -0
  6. package/SystemModules/keplerscript-system-bundle-config.json +7 -0
  7. package/THIRD_PARTY_NOTICES.txt +640 -0
  8. package/android/build.gradle +120 -0
  9. package/android/gradle.properties +27 -0
  10. package/android/src/main/AndroidManifest.xml +6 -0
  11. package/android/src/main/java/com/airbnb/android/react/lottie/LottieAnimationViewManagerImpl.kt +260 -0
  12. package/android/src/main/java/com/airbnb/android/react/lottie/LottieAnimationViewPropertyManager.kt +156 -0
  13. package/android/src/main/java/com/airbnb/android/react/lottie/LottiePackage.kt +18 -0
  14. package/android/src/newarch/com/airbnb/android/react/lottie/LottieAnimationViewManager.kt +219 -0
  15. package/android/src/oldarch/com/airbnb/android/react/lottie/LottieAnimationViewManager.kt +187 -0
  16. package/ios/Fabric/LottieAnimationViewComponentView.h +28 -0
  17. package/ios/Fabric/LottieAnimationViewComponentView.mm +140 -0
  18. package/ios/Fabric/LottieContainerView.h +33 -0
  19. package/ios/Fabric/RNLottieFabricConversions.h +29 -0
  20. package/ios/LottieReactNative/AnimationViewManagerModule.swift +88 -0
  21. package/ios/LottieReactNative/Bridging.h +4 -0
  22. package/ios/LottieReactNative/ContainerView.swift +281 -0
  23. package/ios/LottieReactNative/LRNAnimationViewManagerObjC.m +25 -0
  24. package/ios/LottieReactNative/PlatformColor.swift +31 -0
  25. package/ios/LottieReactNative/RCTConvert+Lottie.h +7 -0
  26. package/ios/LottieReactNative/RCTConvert+Lottie.m +24 -0
  27. package/ios/LottieReactNative.xcodeproj/project.pbxproj +449 -0
  28. package/ios/LottieReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  29. package/ios/LottieReactNative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  30. package/kepler-compatibility.json +8 -0
  31. package/kepler-transformed-package-info.json +3 -0
  32. package/lib/commonjs/LottieView.js +207 -0
  33. package/lib/commonjs/LottieView.js.map +1 -0
  34. package/lib/commonjs/LottieView.types.js +6 -0
  35. package/lib/commonjs/LottieView.types.js.map +1 -0
  36. package/lib/commonjs/index.js +9 -0
  37. package/lib/commonjs/index.js.map +1 -0
  38. package/lib/commonjs/specs/LottieAnimationViewNativeComponent.js +97 -0
  39. package/lib/commonjs/specs/LottieAnimationViewNativeComponent.js.map +1 -0
  40. package/lib/module/LottieView.js +201 -0
  41. package/lib/module/LottieView.js.map +1 -0
  42. package/lib/module/LottieView.types.js +2 -0
  43. package/lib/module/LottieView.types.js.map +1 -0
  44. package/lib/module/index.js +3 -0
  45. package/lib/module/index.js.map +1 -0
  46. package/lib/module/specs/LottieAnimationViewNativeComponent.js +91 -0
  47. package/lib/module/specs/LottieAnimationViewNativeComponent.js.map +1 -0
  48. package/lib/typescript/LottieView.d.ts +27 -0
  49. package/lib/typescript/LottieView.types.d.ts +206 -0
  50. package/lib/typescript/index.d.ts +2 -0
  51. package/lib/typescript/specs/LottieAnimationViewNativeComponent.d.ts +61 -0
  52. package/lottie-react-native.podspec +44 -0
  53. package/package.json +1 -0
  54. package/react-native.config.js +32 -0
  55. package/src/LottieView.tsx +257 -0
  56. package/src/LottieView.types.ts +275 -0
  57. package/src/__tests__/__snapshots__/validate-public-api.test.js.snap +248 -0
  58. package/src/__tests__/validate-public-api.test.js +33 -0
  59. package/src/index.tsx +2 -0
  60. package/src/specs/LottieAnimationViewNativeComponent.ts +170 -0
@@ -0,0 +1,88 @@
1
+ import Lottie
2
+
3
+ #if os(OSX)
4
+ import AppKit
5
+
6
+ typealias View = NSView
7
+
8
+ #else
9
+ import UIKit
10
+
11
+ typealias View = UIView
12
+
13
+ #endif
14
+
15
+ @objc(LottieAnimationView)
16
+ class AnimationViewManagerModule: RCTViewManager {
17
+ override func view() -> View! {
18
+ return ContainerView()
19
+ }
20
+
21
+ @objc override func constantsToExport() -> [AnyHashable : Any]! {
22
+ return ["VERSION": 1]
23
+ }
24
+
25
+ @objc(play:fromFrame:toFrame:)
26
+ public func play(_ reactTag: NSNumber, startFrame: NSNumber, endFrame: NSNumber) {
27
+ self.bridge.uiManager.addUIBlock { (uiManager, viewRegistry) in
28
+ guard let view = viewRegistry?[reactTag] as? ContainerView else {
29
+ if (RCT_DEBUG == 1) {
30
+ print("Invalid view returned from registry, expecting ContainerView")
31
+ }
32
+ return
33
+ }
34
+
35
+ if (startFrame.intValue != -1 && endFrame.intValue != -1) {
36
+ view.play(fromFrame: AnimationFrameTime(truncating: startFrame), toFrame: AnimationFrameTime(truncating: endFrame))
37
+ } else {
38
+ view.play()
39
+ }
40
+ }
41
+ }
42
+
43
+ @objc(reset:)
44
+ public func reset(_ reactTag: NSNumber) {
45
+ self.bridge.uiManager.addUIBlock { uiManager, viewRegistry in
46
+ guard let view = viewRegistry?[reactTag] as? ContainerView else {
47
+ if (RCT_DEBUG == 1) {
48
+ print("Invalid view returned from registry, expecting ContainerView")
49
+ }
50
+ return
51
+ }
52
+
53
+ view.reset()
54
+ }
55
+ }
56
+
57
+ @objc(pause:)
58
+ public func pause(_ reactTag: NSNumber) {
59
+ self.bridge.uiManager.addUIBlock { uiManager, viewRegistry in
60
+ guard let view = viewRegistry?[reactTag] as? ContainerView else {
61
+ if (RCT_DEBUG == 1) {
62
+ print("Invalid view returned from registry, expecting ContainerView")
63
+ }
64
+ return
65
+ }
66
+
67
+ view.pause()
68
+ }
69
+ }
70
+
71
+ @objc(resume:)
72
+ public func resume(_ reactTag: NSNumber) {
73
+ self.bridge.uiManager.addUIBlock { uiManager, viewRegistry in
74
+ guard let view = viewRegistry?[reactTag] as? ContainerView else {
75
+ if (RCT_DEBUG == 1) {
76
+ print("Invalid view returned from registry, expecting ContainerView")
77
+ }
78
+ return
79
+ }
80
+
81
+ view.resume()
82
+ }
83
+ }
84
+
85
+ override static func requiresMainQueueSetup() -> Bool {
86
+ return true
87
+ }
88
+ }
@@ -0,0 +1,4 @@
1
+ #import <React/RCTViewManager.h>
2
+ #import <React/RCTBridge.h>
3
+ #import <React/RCTUIManager.h>
4
+ #import <React/RCTView.h>
@@ -0,0 +1,281 @@
1
+ import Lottie
2
+ import Foundation
3
+
4
+ @objc protocol LottieContainerViewDelegate {
5
+ func onAnimationFinish(isCancelled: Bool);
6
+ }
7
+
8
+ @objc(LottieContainerView)
9
+ class ContainerView: RCTView {
10
+ private var speed: CGFloat = 0.0
11
+ private var progress: CGFloat = 0.0
12
+ private var loop: LottieLoopMode = .playOnce
13
+ private var sourceJson: String = ""
14
+ private var resizeMode: String = ""
15
+ private var sourceName: String = ""
16
+ private var colorFilters: [NSDictionary] = []
17
+ private var textFilters: [NSDictionary] = []
18
+ private var renderMode: RenderingEngineOption = .automatic
19
+ @objc weak var delegate: LottieContainerViewDelegate? = nil
20
+
21
+ @objc var onAnimationFinish: RCTBubblingEventBlock?
22
+ var animationView: LottieAnimationView?
23
+
24
+ override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
25
+ super.traitCollectionDidChange(previousTraitCollection)
26
+ if #available(iOS 13.0, tvOS 13.0, *) {
27
+ if (self.traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection)) {
28
+ applyProperties()
29
+ print("dark mode changed")
30
+ }
31
+ }
32
+ }
33
+
34
+ @objc func setSpeed(_ newSpeed: CGFloat) {
35
+ speed = newSpeed
36
+
37
+ if (newSpeed != 0.0) {
38
+ animationView?.animationSpeed = newSpeed
39
+ if (!(animationView?.isAnimationPlaying ?? true)) {
40
+ animationView?.play()
41
+ }
42
+ } else if (animationView?.isAnimationPlaying ?? false) {
43
+ animationView?.pause()
44
+ }
45
+ }
46
+
47
+ @objc func setProgress(_ newProgress: CGFloat) {
48
+ progress = newProgress
49
+ animationView?.currentProgress = progress
50
+ }
51
+
52
+ override func reactSetFrame(_ frame: CGRect) {
53
+ super.reactSetFrame(frame)
54
+ animationView?.reactSetFrame(frame)
55
+ }
56
+
57
+ @objc func setLoop(_ isLooping: Bool) {
58
+ loop = isLooping ? .loop : .playOnce
59
+ animationView?.loopMode = loop
60
+ }
61
+
62
+ @objc func setTextFiltersIOS(_ newTextFilters: [NSDictionary]) {
63
+ textFilters = newTextFilters
64
+
65
+ if (textFilters.count > 0) {
66
+ var filters = [String:String]()
67
+ for filter in textFilters {
68
+ let key = filter.value(forKey: "keypath") as! String
69
+ let value = filter.value(forKey: "text") as! String
70
+ filters[key] = value;
71
+ }
72
+
73
+ let starAnimationView = LottieAnimationView()
74
+ starAnimationView.textProvider = DictionaryTextProvider(filters)
75
+ starAnimationView.animation = animationView?.animation
76
+ replaceAnimationView(next: starAnimationView)
77
+ }
78
+ }
79
+
80
+ func getLottieConfiguration() -> LottieConfiguration {
81
+ return LottieConfiguration(
82
+ renderingEngine: renderMode
83
+ )
84
+ }
85
+
86
+ @objc func setRenderMode(_ newRenderMode: String) {
87
+ switch newRenderMode {
88
+ case "SOFTWARE":
89
+ if (renderMode == .mainThread) {
90
+ return
91
+ }
92
+ renderMode = .mainThread
93
+ case "HARDWARE":
94
+ if (renderMode == .coreAnimation) {
95
+ return
96
+ }
97
+ renderMode = .coreAnimation
98
+ case "AUTOMATIC":
99
+ fallthrough
100
+ default:
101
+ if (renderMode == .automatic) {
102
+ return
103
+ }
104
+ renderMode = .automatic
105
+ }
106
+ if (animationView != nil) {
107
+ let starAnimationView = LottieAnimationView(
108
+ animation: animationView?.animation,
109
+ configuration: getLottieConfiguration()
110
+ )
111
+ replaceAnimationView(next: starAnimationView)
112
+ }
113
+ }
114
+
115
+ @objc func setSourceURL(_ newSourceURLString: String) {
116
+ var url = URL(string: newSourceURLString)
117
+
118
+ if(url?.scheme == nil) {
119
+ // interpret raw URL paths as relative to the resource bundle
120
+ url = URL(fileURLWithPath: newSourceURLString, relativeTo: Bundle.main.resourceURL)
121
+ }
122
+
123
+ if(url != nil) {
124
+ DispatchQueue.global(qos: .default).async {
125
+ do {
126
+ let sourceJson = try String(contentsOf: url!)
127
+ guard let data = sourceJson.data(using: String.Encoding.utf8),
128
+ let animation = try? JSONDecoder().decode(LottieAnimation.self, from: data) else {
129
+ if (RCT_DEBUG == 1) {
130
+ print("Unable to decode the lottie animation object from the fetched URL source")
131
+ }
132
+ return
133
+ }
134
+
135
+ DispatchQueue.main.async {
136
+ let starAnimationView = LottieAnimationView(
137
+ animation: animation,
138
+ configuration: self.getLottieConfiguration()
139
+ )
140
+ self.replaceAnimationView(next: starAnimationView)
141
+ self.animationView?.play()
142
+ }
143
+ } catch {
144
+ if (RCT_DEBUG == 1) {
145
+ print("Unable to load the lottie animation URL")
146
+ }
147
+ }
148
+ }
149
+ }
150
+ }
151
+
152
+ @objc func setSourceJson(_ newSourceJson: String) {
153
+ sourceJson = newSourceJson
154
+
155
+ guard let data = sourceJson.data(using: String.Encoding.utf8),
156
+ let animation = try? JSONDecoder().decode(LottieAnimation.self, from: data) else {
157
+ if (RCT_DEBUG == 1) {
158
+ print("Unable to create the lottie animation object from the JSON source")
159
+ }
160
+ return
161
+ }
162
+
163
+ let starAnimationView = LottieAnimationView(
164
+ animation: animation,
165
+ configuration: getLottieConfiguration()
166
+ )
167
+ replaceAnimationView(next: starAnimationView)
168
+ }
169
+
170
+ @objc func setSourceName(_ newSourceName: String) {
171
+ if (newSourceName == sourceName) {
172
+ return
173
+ }
174
+ sourceName = newSourceName
175
+
176
+ let starAnimationView = LottieAnimationView(
177
+ name: sourceName,
178
+ configuration: getLottieConfiguration()
179
+ )
180
+ replaceAnimationView(next: starAnimationView)
181
+ }
182
+
183
+ @objc func setResizeMode(_ resizeMode: String) {
184
+ switch (resizeMode) {
185
+ case "cover":
186
+ animationView?.contentMode = .scaleAspectFill
187
+ case "contain":
188
+ animationView?.contentMode = .scaleAspectFit
189
+ case "center":
190
+ animationView?.contentMode = .center
191
+ default: break
192
+ }
193
+ }
194
+
195
+ @objc func setColorFilters(_ newColorFilters: [NSDictionary]) {
196
+ colorFilters = newColorFilters
197
+ applyProperties()
198
+ }
199
+
200
+ // There is no Nullable CGFloat in Objective-C, so this function uses a Nullable NSNumber and converts it later
201
+ @objc(playFromFrame:toFrame:)
202
+ func objcCompatiblePlay(fromFrame: NSNumber? = nil, toFrame: AnimationFrameTime) {
203
+ let convertedFromFrame = fromFrame != nil ? CGFloat(truncating: fromFrame!) : nil;
204
+ play(fromFrame: convertedFromFrame, toFrame: toFrame);
205
+ }
206
+
207
+ func play(fromFrame: AnimationFrameTime? = nil, toFrame: AnimationFrameTime) {
208
+ let callback: LottieCompletionBlock = { animationFinished in
209
+ if let onFinish = self.onAnimationFinish {
210
+ onFinish(["isCancelled": !animationFinished])
211
+ }
212
+ self.delegate?.onAnimationFinish(isCancelled: !animationFinished);
213
+ }
214
+
215
+ animationView?.backgroundBehavior = .pauseAndRestore
216
+ animationView?.play(fromFrame: fromFrame, toFrame: toFrame, loopMode: self.loop, completion: callback);
217
+ }
218
+
219
+ @objc func play() {
220
+ let callback: LottieCompletionBlock = { animationFinished in
221
+ if let onFinish = self.onAnimationFinish {
222
+ onFinish(["isCancelled": !animationFinished])
223
+ }
224
+ self.delegate?.onAnimationFinish(isCancelled: !animationFinished);
225
+ }
226
+
227
+ animationView?.backgroundBehavior = .pauseAndRestore
228
+ animationView?.play(completion: callback)
229
+ }
230
+
231
+ @objc func reset() {
232
+ animationView?.currentProgress = 0;
233
+ animationView?.pause()
234
+ }
235
+
236
+ @objc func pause() {
237
+ animationView?.pause()
238
+ }
239
+
240
+ @objc func resume() {
241
+ play()
242
+ }
243
+
244
+ // reset the animationView frame whenever the view's frame changes
245
+ override var frame: CGRect {
246
+ didSet {
247
+ animationView?.reactSetFrame(frame)
248
+ }
249
+ }
250
+
251
+ // MARK: Private
252
+ func replaceAnimationView(next: LottieAnimationView) {
253
+ animationView?.removeFromSuperview()
254
+
255
+ let contentMode = animationView?.contentMode ?? .scaleAspectFit
256
+ animationView = next
257
+ addSubview(next)
258
+ animationView?.contentMode = contentMode
259
+ animationView?.reactSetFrame(frame)
260
+ applyProperties()
261
+ }
262
+
263
+ func applyProperties() {
264
+ guard let animationView = animationView else { return }
265
+ let isPlaying = animationView.isAnimationPlaying
266
+ animationView.currentProgress = progress
267
+ animationView.animationSpeed = speed
268
+ animationView.loopMode = loop
269
+ if (colorFilters.count > 0) {
270
+ for filter in colorFilters {
271
+ let keypath: String = "\(filter.value(forKey: "keypath") as! String).**.Color"
272
+ let fillKeypath = AnimationKeypath(keypath: keypath)
273
+ let colorFilterValueProvider = ColorValueProvider((filter.value(forKey: "color") as! PlatformColor).lottieColorValue)
274
+ animationView.setValueProvider(colorFilterValueProvider, keypath: fillKeypath)
275
+ }
276
+ }
277
+ if isPlaying {
278
+ resume()
279
+ }
280
+ }
281
+ }
@@ -0,0 +1,25 @@
1
+ #import <React/RCTViewManager.h>
2
+ #import "RCTConvert+Lottie.h"
3
+
4
+ @interface RCT_EXTERN_MODULE(LottieAnimationView, RCTViewManager)
5
+
6
+ RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString);
7
+ RCT_EXPORT_VIEW_PROPERTY(sourceJson, NSString);
8
+ RCT_EXPORT_VIEW_PROPERTY(sourceName, NSString);
9
+ RCT_EXPORT_VIEW_PROPERTY(sourceURL, NSString);
10
+ RCT_EXPORT_VIEW_PROPERTY(progress, CGFloat);
11
+ RCT_EXPORT_VIEW_PROPERTY(loop, BOOL);
12
+ RCT_EXPORT_VIEW_PROPERTY(speed, CGFloat);
13
+ RCT_EXPORT_VIEW_PROPERTY(onAnimationFinish, RCTBubblingEventBlock);
14
+ RCT_EXPORT_VIEW_PROPERTY(colorFilters, LRNColorFilters);
15
+ RCT_EXPORT_VIEW_PROPERTY(textFiltersIOS, NSArray);
16
+ RCT_EXPORT_VIEW_PROPERTY(renderMode, NSString);
17
+
18
+ RCT_EXTERN_METHOD(play:(nonnull NSNumber *)reactTag fromFrame:(nonnull NSNumber *) startFrame toFrame:(nonnull NSNumber *) endFrame);
19
+
20
+ RCT_EXTERN_METHOD(reset:(nonnull NSNumber *)reactTag);
21
+ RCT_EXTERN_METHOD(pause:(nonnull NSNumber *)reactTag);
22
+ RCT_EXTERN_METHOD(resume:(nonnull NSNumber *)reactTag);
23
+
24
+ @end
25
+
@@ -0,0 +1,31 @@
1
+ //
2
+ // PlatformColor.swift
3
+ // LottieReactNative
4
+ //
5
+ // Created by Igor Mandrigin on 2020-08-28.
6
+ // Copyright © 2020 Airbnb. All rights reserved.
7
+ //
8
+ import Lottie
9
+
10
+ #if os(OSX)
11
+
12
+ import AppKit
13
+
14
+ typealias PlatformColor = NSColor
15
+
16
+ // NSColor doesn't have this extension (UIColor receives it from Lottie), so we add it here
17
+ public extension NSColor {
18
+ var lottieColorValue: Color {
19
+ var r: CGFloat = 0, g: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0
20
+ getRed(&r, green: &g, blue: &b, alpha: &a)
21
+ return Color(r: Double(r), g: Double(g), b: Double(b), a: Double(a))
22
+ }
23
+ }
24
+
25
+ #else
26
+
27
+ import UIKit
28
+
29
+ typealias PlatformColor = UIColor
30
+
31
+ #endif
@@ -0,0 +1,7 @@
1
+ #import <React/RCTConvert.h>
2
+
3
+ @interface RCTConvert (Lottie)
4
+
5
+ + (NSArray<NSDictionary *> *)LRNColorFilters:(id)json;
6
+
7
+ @end
@@ -0,0 +1,24 @@
1
+ #import "RCTConvert+Lottie.h"
2
+
3
+ @implementation RCTConvert (Lottie)
4
+
5
+ + (NSArray<NSDictionary *> *)LRNColorFilters:(id)json
6
+ {
7
+ NSArray *rawFilters = [self NSArray:json];
8
+ NSMutableArray *filters = [NSMutableArray arrayWithCapacity:[rawFilters count]];
9
+ [rawFilters enumerateObjectsUsingBlock:^(NSDictionary *rawFilter, NSUInteger idx, BOOL *stop) {
10
+ NSString *keypath = rawFilter[@"keypath"];
11
+ #if TARGET_OS_OSX
12
+ NSColor *color = [RCTConvert NSColor:rawFilter[@"color"]];
13
+ #else
14
+ UIColor *color = [RCTConvert UIColor:rawFilter[@"color"]];
15
+ #endif
16
+ [filters addObject:@{
17
+ @"color": color,
18
+ @"keypath": keypath,
19
+ }];
20
+ }];
21
+ return filters;
22
+ }
23
+
24
+ @end