@amazon-devices/lottie-react-native 3.0.9000000000 → 3.0.9000000002

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.
@@ -1,257 +0,0 @@
1
- /*
2
- * Portions of this file are copyright (c) 2023 Amazon.com, Inc. or its affiliates. All rights reserved.
3
- *
4
- * PORTIONS OF THIS FILE ARE AMAZON PROPRIETARY/CONFIDENTIAL. USE IS SUBJECT TO LICENSE TERMS.
5
- *
6
- * Amazon modifications are indicated by [amznmod_* comments].
7
- */
8
-
9
- /*
10
- * Changelog:
11
- * Set up lottie-react-native package to build for Kepler
12
- */
13
-
14
- import React from 'react';
15
- import {
16
- View,
17
- StyleSheet,
18
- NativeSyntheticEvent,
19
- Animated,
20
- processColor,
21
- } from 'react-native';
22
-
23
- import type { AnimatedLottieViewProps } from './LottieView.types';
24
-
25
- import NativeLottieAnimationView, {
26
- Commands,
27
- } from './specs/LottieAnimationViewNativeComponent';
28
-
29
- const AnimatedNativeLottieView = Animated.createAnimatedComponent(
30
- NativeLottieAnimationView,
31
- );
32
-
33
- // amznmod_react - add textFiltersKepler prop for Kepler
34
- const defaultProps: AnimatedLottieViewProps = {
35
- source: undefined,
36
- progress: 0,
37
- speed: 1,
38
- loop: true,
39
- autoPlay: false,
40
- autoSize: false,
41
- enableMergePathsAndroidForKitKatAndAbove: false,
42
- cacheComposition: true,
43
- useNativeLooping: false,
44
- resizeMode: 'contain',
45
- colorFilters: [],
46
- textFiltersAndroid: [],
47
- textFiltersIOS: [],
48
- textFiltersKepler: [],
49
- };
50
-
51
- /**
52
- * View hosting the lottie animation.
53
- */
54
- export class AnimatedLottieView extends React.PureComponent<
55
- AnimatedLottieViewProps,
56
- {}
57
- > {
58
- static defaultProps = defaultProps;
59
-
60
- _lottieAnimationViewRef:
61
- | React.ElementRef<typeof NativeLottieAnimationView>
62
- | undefined;
63
-
64
- constructor(props: AnimatedLottieViewProps) {
65
- super(props);
66
- this.play = this.play.bind(this);
67
- this.reset = this.reset.bind(this);
68
- this.pause = this.pause.bind(this);
69
- this.resume = this.resume.bind(this);
70
- this.onAnimationFinish = this.onAnimationFinish.bind(this);
71
- this._captureRef = this._captureRef.bind(this);
72
- // amznmod_react - add onAnimation... callbacks
73
- this.onAnimationLoad = this.onAnimationLoad.bind(this);
74
- this.onAnimationPlay = this.onAnimationPlay.bind(this);
75
- this.onAnimationPause = this.onAnimationPause.bind(this);
76
- this.onAnimationResume = this.onAnimationResume.bind(this);
77
- this.onAnimationJsonLoad = this.onAnimationJsonLoad.bind(this);
78
- }
79
-
80
- componentDidUpdate(prevProps: AnimatedLottieViewProps) {
81
- if (
82
- this.props.autoPlay === true &&
83
- this.props.source !== prevProps.source &&
84
- !!this.props.source
85
- ) {
86
- this.play();
87
- }
88
- }
89
-
90
- play(startFrame?: number, endFrame?: number): void {
91
- Commands.play(
92
- this._lottieAnimationViewRef,
93
- startFrame ?? -1,
94
- endFrame ?? -1,
95
- );
96
- }
97
-
98
- reset() {
99
- Commands.reset(this._lottieAnimationViewRef);
100
- }
101
-
102
- pause() {
103
- Commands.pause(this._lottieAnimationViewRef);
104
- }
105
-
106
- resume() {
107
- Commands.resume(this._lottieAnimationViewRef);
108
- }
109
-
110
- onAnimationFinish = (evt: NativeSyntheticEvent<{ isCancelled: boolean }>) => {
111
- if (this.props.onAnimationFinish) {
112
- this.props.onAnimationFinish(evt.nativeEvent.isCancelled);
113
- }
114
- };
115
-
116
- // amznmod_react - onAnimationLoad callback
117
- onAnimationLoad = () => {
118
- if (this.props.onAnimationLoad) {
119
- this.props.onAnimationLoad();
120
- }
121
- };
122
-
123
- // PROJ*-136246 - deprecate onAnimationJsonLoad
124
- // amznmod_react - onAnimationLoad callback
125
- onAnimationJsonLoad = () => {
126
- console.warn("onAnimationJsonLoad will be deprecated in favor of onAnimationLoad. Migrate to use onAnimationLoad.")
127
- if (this.props.onAnimationJsonLoad) {
128
- this.props.onAnimationJsonLoad();
129
- }
130
- };
131
-
132
- // amznmod_react - onAnimationPlay callback
133
- onAnimationPlay = () => {
134
- if (this.props.onAnimationPlay) {
135
- this.props.onAnimationPlay();
136
- }
137
- };
138
-
139
- // amznmod_react - onAnimationPause callback
140
- onAnimationPause = () => {
141
- if (this.props.onAnimationPause) {
142
- this.props.onAnimationPause();
143
- }
144
- };
145
-
146
- // amznmod_react - onAnimationResume callback
147
- onAnimationResume = () => {
148
- if (this.props.onAnimationResume) {
149
- this.props.onAnimationResume();
150
- }
151
- };
152
-
153
- _captureRef(ref: React.ElementRef<typeof NativeLottieAnimationView>) {
154
- if (ref === null) {
155
- return;
156
- }
157
-
158
- this._lottieAnimationViewRef = ref;
159
- // amznmod_react - Fix for a crash on autoplay + progress with animation
160
- if (this._lottieAnimationViewRef && this.props.autoPlay === true) {
161
- this.play();
162
- }
163
- }
164
-
165
- render(): React.ReactNode {
166
- // amznmod_react - add textFiltersKepler prop
167
- const {
168
- style,
169
- source,
170
- autoSize,
171
- autoPlay,
172
- duration,
173
- textFiltersAndroid,
174
- textFiltersIOS,
175
- textFiltersKepler,
176
- ...rest
177
- } = this.props;
178
-
179
- const sourceName = typeof source === 'string' ? source : undefined;
180
- const sourceJson =
181
- typeof source === 'object' && !(source as any).uri
182
- ? JSON.stringify(source)
183
- : undefined;
184
- const sourceURL =
185
- typeof source === 'object' && (source as any).uri
186
- ? (source as any).uri
187
- : undefined;
188
-
189
- const aspectRatioStyle = sourceJson
190
- ? { aspectRatio: (source as any).w / (source as any).h }
191
- : undefined;
192
-
193
- const styleObject = StyleSheet.flatten(style);
194
- let sizeStyle;
195
- if (
196
- !styleObject ||
197
- (styleObject.width === undefined && styleObject.height === undefined)
198
- ) {
199
- sizeStyle =
200
- autoSize && sourceJson
201
- ? { width: (source as any).w }
202
- : StyleSheet.absoluteFill;
203
- }
204
-
205
- const speed =
206
- duration && sourceJson && (source as any).fr
207
- ? Math.round(
208
- (((source as any).op / (source as any).fr) * 1000) / duration,
209
- )
210
- : this.props.speed;
211
-
212
- const colorFilters = this.props.colorFilters?.map((colorFilter) => ({
213
- ...colorFilter,
214
- color: processColor(colorFilter.color),
215
- }));
216
- // amznmod_react - Clip LottieView on ReactNative
217
- const baseStyle= {
218
- overflow: 'hidden',
219
- };
220
-
221
- return (
222
- // amznmod_react - Clip LottieView on ReactNative
223
- <View style={[aspectRatioStyle, sizeStyle, style, baseStyle]}>
224
- <AnimatedNativeLottieView
225
- ref={this._captureRef}
226
- {...rest}
227
- // amznmod_react - add autoPlay prop
228
- autoPlay={autoPlay}
229
- colorFilters={colorFilters}
230
- textFiltersAndroid={textFiltersAndroid}
231
- textFiltersIOS={textFiltersIOS}
232
- // amznmod_react - add textFiltersKepler prop
233
- // amznmod_react - Clip LottieView on ReactNative
234
- textFiltersKepler={textFiltersKepler}
235
- speed={speed}
236
- style={[
237
- aspectRatioStyle,
238
- sizeStyle || { width: '100%', height: '100%' },
239
- style,
240
- baseStyle
241
- ]}
242
- sourceName={sourceName}
243
- sourceJson={sourceJson}
244
- sourceURL={sourceURL}
245
- onAnimationFinish={this.onAnimationFinish}
246
- //amznmod_react - add onAnimation... callbacks
247
- onAnimationLoad={this.onAnimationLoad}
248
- onAnimationPlay={this.onAnimationPlay}
249
- onAnimationPause={this.onAnimationPause}
250
- onAnimationResume={this.onAnimationResume}
251
- // PROJ*-136246 - deprecate onAnimationJsonLoad
252
- onAnimationJsonLoad={this.onAnimationJsonLoad}
253
- />
254
- </View>
255
- );
256
- }
257
- }
@@ -1,275 +0,0 @@
1
- /*
2
- * Portions of this file are copyright (c) 2023 Amazon.com, Inc. or its affiliates. All rights reserved.
3
- *
4
- * PORTIONS OF THIS FILE ARE AMAZON PROPRIETARY/CONFIDENTIAL. USE IS SUBJECT TO LICENSE TERMS.
5
- *
6
- * Amazon modifications are indicated by [amznmod_* comments].
7
- */
8
-
9
- /*
10
- * Changelog:
11
- * Set up lottie-react-native package to build for Kepler
12
- * Add accessibility props
13
- */
14
-
15
- import type {
16
- StyleProp,
17
- ViewStyle,
18
- LayoutChangeEvent,
19
- Animated,
20
- AccessibilityProps,
21
- } from 'react-native';
22
-
23
- /**
24
- * Serialized animation as generated from After Effects
25
- */
26
- export interface AnimationObject {
27
- v: string;
28
- fr: number;
29
- ip: number;
30
- op: number;
31
- w: number;
32
- h: number;
33
- nm?: string;
34
- ddd?: number;
35
- assets: any[];
36
- layers: any[];
37
- markers?: any[];
38
- }
39
-
40
- type ColorFilter = {
41
- keypath: string;
42
- color: string;
43
- };
44
-
45
- type TextFilterIOS = {
46
- keypath: string;
47
- text: string;
48
- };
49
-
50
- type TextFilterAndroid = {
51
- find: string;
52
- replace: string;
53
- };
54
-
55
- // amznmod_react - TextFilterKepler type
56
- type TextFilterKepler = {
57
- keypath: string;
58
- text: string;
59
- };
60
-
61
- // Animated.AnimatedInterpolation has been converted to a generic type
62
- // in @types/react-native 0.70. This way we can maintain compatibility
63
- // with all versions of @types/react-native`
64
- type AnimatedInterpolation = ReturnType<Animated.Value['interpolate']>;
65
-
66
- /**
67
- * Properties of the AnimatedLottieView component
68
- */
69
- // amznmod_react LottieView supports all AccessibilityProps
70
- export interface AnimatedLottieViewProps extends AccessibilityProps{
71
- /**
72
- * The source of animation. Can be referenced as a local asset by a string, or remotely
73
- * with an object with a `uri` property, or it can be an actual JS object of an
74
- * animation, obtained (for example) with something like
75
- * `require('../path/to/animation.json')`
76
- */
77
- source: string | AnimationObject | { uri: string };
78
-
79
- /**
80
- * A number between 0 and 1, or an `Animated` number between 0 and 1. This number
81
- * represents the normalized progress of the animation. If you update this prop, the
82
- * animation will correspondingly update to the frame at that progress value. This
83
- * prop is not required if you are using the imperative API.
84
- */
85
- progress?: number | Animated.Value | AnimatedInterpolation;
86
-
87
- /**
88
- * The speed the animation will progress. This only affects the imperative API. The
89
- * default value is 1.
90
- */
91
- speed?: number;
92
-
93
- /**
94
- * The duration of the animation in ms. Takes precedence over speed when set.
95
- * This only works when source is an actual JS object of an animation.
96
- */
97
- duration?: number;
98
-
99
- /**
100
- * A boolean flag indicating whether or not the animation should loop.
101
- */
102
- loop?: boolean;
103
-
104
- /**
105
- * Style attributes for the view, as expected in a standard `View`:
106
- * http://facebook.github.io/react-native/releases/0.39/docs/view.html#style
107
- *
108
- * **CAVEAT: border styling is not supported.**
109
- */
110
- style?: StyleProp<ViewStyle>;
111
-
112
- /**
113
- * Determines how to resize the animated view when the frame doesn't match the raw image
114
- * dimensions.
115
- *
116
- * Refer to https://facebook.github.io/react-native/docs/image.html#resizemode
117
- */
118
- resizeMode?: 'cover' | 'contain' | 'center';
119
-
120
- /**
121
- * Determines how Lottie should render
122
- * Refer to LottieAnimationView#setRenderMode(RenderMode) for more information.
123
- */
124
- renderMode?: 'AUTOMATIC' | 'HARDWARE' | 'SOFTWARE';
125
-
126
- /**
127
- * A boolean flag indicating whether or not the animation should start automatically when
128
- * mounted. This only affects the imperative API.
129
- */
130
- autoPlay?: boolean;
131
-
132
- /**
133
- * A boolean flag indicating whether or not the animation should size itself automatically
134
- * according to the width in the animation's JSON. This only works when source is an actual
135
- * JS object of an animation.
136
- */
137
- autoSize?: boolean;
138
-
139
- /**
140
- * A callback function which will be called when animation is finished. Note that this
141
- * callback will be called only when `loop` is set to false.
142
- */
143
- onAnimationFinish?: (isCancelled: boolean) => void;
144
-
145
- /**
146
- * A callback function which will be called when the view has been laid out.
147
- */
148
- onLayout?: (event: LayoutChangeEvent) => void;
149
-
150
- /**
151
- * An array of layers you want to override its color filter.
152
- */
153
- colorFilters?: Array<ColorFilter>;
154
-
155
- /**
156
- * A string to identify the component during testing.
157
- */
158
- testID?: string;
159
-
160
- // Android Props
161
-
162
- /**
163
- * A boolean flag to enable merge patching.
164
- * @platform android
165
- */
166
- enableMergePathsAndroidForKitKatAndAbove?: boolean;
167
-
168
- /**
169
- * A boolean flag indicating whether or not the animation should caching. Defaults to true.
170
- * Refer to LottieAnimationView#setCacheComposition(boolean) for more information.
171
- *
172
- * @platform android
173
- */
174
- cacheComposition?: boolean;
175
-
176
- /**
177
- * An array of objects denoting text values to find and replace.
178
- *
179
- * @platform android
180
- */
181
- textFiltersAndroid?: Array<TextFilterAndroid>;
182
-
183
- /**
184
- * Relative folder inside of assets containing image files to be animated.
185
- * Make sure that the images that bodymovin export are in that folder with their names unchanged (should be img_#).
186
- * Refer to https://github.com/airbnb/lottie-android#image-support for more details.
187
- *
188
- * @platform android
189
- */
190
- imageAssetsFolder?: string;
191
-
192
- /**
193
- * Uses hardware acceleration to perform the animation. This should only
194
- * be used for animations where your width and height are equal to the composition width
195
- * and height, e.g. you are not scaling the animation.
196
- *
197
- * @platform android
198
- */
199
- hardwareAccelerationAndroid?: boolean;
200
-
201
- // iOS Props
202
-
203
- /**
204
- * An array of objects denoting text layers by KeyPath and a new string value.
205
- *
206
- * @platform ios
207
- */
208
- textFiltersIOS?: Array<TextFilterIOS>;
209
-
210
- // Windows Props
211
-
212
- /**
213
- * A boolean flag to enable use of platform-level looping on Windows. This improves loop smoothness,
214
- * but onAnimationLoop will not fire and changing the loop prop will restart playback.
215
- *
216
- * @platform windows
217
- */
218
- useNativeLooping?: boolean;
219
-
220
- /**
221
- * A callback function which will be called when the animation loops.
222
- *
223
- * @platform windows
224
- */
225
- onAnimationLoop?: () => void;
226
-
227
- // amznmod_react - add onAnimationLoad callback
228
- /**
229
- * A callback function which will be called when animation json load is finished.
230
- *
231
- * @platform kepler
232
- */
233
- onAnimationLoad?: () => void;
234
-
235
- // PROJ*-136246 - deprecate onAnimationJsonLoad
236
- // amznmod_react - add onAnimationJsonLoad callback
237
- /**
238
- * A callback function which will be called when animation json load is finished.
239
- *
240
- * @platform kepler
241
- */
242
- onAnimationJsonLoad?: () => void;
243
-
244
- // amznmod_react - add onAnimationPlay callback
245
- /**
246
- * A callback function which will be called when animation play is started.
247
- *
248
- * @platform kepler
249
- */
250
- onAnimationPlay?: () => void;
251
-
252
- // amznmod_react - add onAnimationPause callback
253
- /**
254
- * A callback function which will be called when animation is paused.
255
- *
256
- * @platform kepler
257
- */
258
- onAnimationPause?: () => void;
259
-
260
- // amznmod_react - add onAnimationResume callback
261
- /**
262
- * A callback function which will be called when animation is resumed.
263
- *
264
- * @platform kepler
265
- */
266
- onAnimationResume?: () => void;
267
-
268
- // amznmod_react - add textFiltersKepler prop
269
- /**
270
- * An array of objects denoting text values to find and replace.
271
- *
272
- * @platform kepler
273
- */
274
- textFiltersKepler?: Array<TextFilterKepler>;
275
- }
@@ -1,33 +0,0 @@
1
- //
2
- // Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- //
4
- // PROPRIETARY/CONFIDENTIAL
5
- // Use is subject to license terms.
6
- //
7
-
8
- const {APIValidationOptions, validate_public_api} = require('@amazon-devices/react-native-kepler/jest/validatePublicAPI');
9
- const glob = require('glob');
10
- const path = require('path');
11
-
12
- const PACKAGE_ROOT = path.resolve(__dirname, '../../');
13
- const TS_FILES_PATTERN = 'lib/typescript/**/*.d.ts';
14
- const IGNORE_PATTERNS = [
15
- '**/__{tests,mocks,fixtures,flowtests}__/**',
16
- '**/specs/**',
17
- ];
18
-
19
- const sourceFiles = [
20
- ...glob.sync(TS_FILES_PATTERN, {
21
- cwd: PACKAGE_ROOT,
22
- ignore: IGNORE_PATTERNS,
23
- nodir: true,
24
- }),
25
- ];
26
-
27
- let options = new APIValidationOptions;
28
- // TODO(huntie): Re-enable once upstream flow-api-translator fixes are made
29
- options.excludedPlatforms = ['win32'];
30
- options.typeScriptOnly = true;
31
- options.verifyTypeScriptDefGenerated = false;
32
-
33
- validate_public_api(PACKAGE_ROOT, sourceFiles, options);