Skip to content

Commit 4744fff

Browse files
authored
Merge pull request lottie-react-native#291 from rodrigoelp/typescript_support
Fixed typescript support
2 parents b932a2a + 951e595 commit 4744fff

File tree

2 files changed

+75
-71
lines changed

2 files changed

+75
-71
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "2.3.2",
44
"description": "React Native bindings for Lottie",
55
"main": "lib/index.js",
6-
"types": "src/js/index.js",
6+
"types": "src/js",
77
"scripts": {
88
"start": "node node_modules/react-native/local-cli/cli.js start",
99
"build": "babel src/js --out-dir lib",

src/js/index.d.ts

Lines changed: 74 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,89 @@
1-
import * as React from 'react';
1+
declare module "lottie-react-native" {
2+
import { Animated, StyleProp, ViewStyle } from "react-native";
23

3-
import {
4-
Animated,
5-
StyleProp,
6-
ViewProperties,
7-
ViewStyle
8-
} from 'react-native';
9-
10-
export interface AnimationObject {
11-
v: string;
12-
fr: number;
13-
ip: number;
14-
op: number;
15-
w: number;
16-
h: number;
17-
nm: string;
18-
ddd: number;
19-
assets: any[];
20-
layers: any[];
21-
}
22-
23-
export interface AnimationProps extends ViewProperties {
244
/**
25-
* The source of animation. Can be referenced as a local asset by a string, or remotely
26-
* with an object with a `uri` property, or it can be an actual JS object of an
27-
* animation, obtained (for example) with something like
28-
* `require('../path/to/animation.json')`
5+
* Serialized animation as generated from After Effects
296
*/
30-
source: string | AnimationObject | { uri: string };
7+
interface AnimationObject {
8+
v: string;
9+
fr: number;
10+
ip: number;
11+
op: number;
12+
w: number;
13+
h: number;
14+
nm: string;
15+
ddd: number;
16+
assets: any[];
17+
layers: any[];
18+
}
3119

3220
/**
33-
* A number between 0 and 1, or an `Animated` number between 0 and 1. This number
34-
* represents the normalized progress of the animation. If you update this prop, the
35-
* animation will correspondingly update to the frame at that progress value. This
36-
* prop is not required if you are using the imperative API.
21+
* Properties of the AnimatedLottieView component
3722
*/
38-
progress?: number | Animated.Value;
23+
interface AnimatedLottieViewProps {
24+
/**
25+
* The source of animation. Can be referenced as a local asset by a string, or remotely
26+
* with an object with a `uri` property, or it can be an actual JS object of an
27+
* animation, obtained (for example) with something like
28+
* `require('../path/to/animation.json')`
29+
*/
30+
source: string | AnimationObject | { uri: string };
3931

40-
/**
41-
* The speed the animation will progress. This only affects the imperative API. The
42-
* default value is 1.
43-
*/
44-
speed?: number;
32+
/**
33+
* A number between 0 and 1, or an `Animated` number between 0 and 1. This number
34+
* represents the normalized progress of the animation. If you update this prop, the
35+
* animation will correspondingly update to the frame at that progress value. This
36+
* prop is not required if you are using the imperative API.
37+
*/
38+
progress?: number | Animated.Value;
4539

46-
/**
47-
* A boolean flag indicating whether or not the animation should loop.
48-
*/
49-
loop?: boolean;
40+
/**
41+
* The speed the animation will progress. This only affects the imperative API. The
42+
* default value is 1.
43+
*/
44+
speed?: number;
5045

51-
/**
52-
* Style attributes for the view, as expected in a standard `View`:
53-
* http://facebook.github.io/react-native/releases/0.39/docs/view.html#style
54-
* CAVEAT: border styling is not supported.
55-
*/
56-
style?: StyleProp<ViewStyle>;
46+
/**
47+
* A boolean flag indicating whether or not the animation should loop.
48+
*/
49+
loop?: boolean;
5750

58-
/**
59-
* [Android] Relative folder inside of assets containing image files to be animated.
60-
* Make sure that the images that bodymovin export are in that folder with their names unchanged (should be img_#).
61-
* Refer to https://github.com/airbnb/lottie-android#image-support for more details.
62-
* @platform android
63-
*/
64-
imageAssetsFolder?: string;
51+
/**
52+
* Style attributes for the view, as expected in a standard `View`:
53+
* http://facebook.github.io/react-native/releases/0.39/docs/view.html#style
54+
* CAVEAT: border styling is not supported.
55+
*/
56+
style?: StyleProp<ViewStyle>;
6557

66-
/**
67-
* [Android]. Uses hardware acceleration to perform the animation. This should only
68-
* be used for animations where your width and height are equal to the composition width
69-
* and height, e.g. you are not scaling the animation.
70-
* @platform android
71-
*/
72-
hardwareAccelerationAndroid?: boolean;
73-
}
58+
/**
59+
* [Android] Relative folder inside of assets containing image files to be animated.
60+
* Make sure that the images that bodymovin export are in that folder with their names unchanged (should be img_#).
61+
* Refer to https://github.com/airbnb/lottie-android#image-support for more details.
62+
* @platform android
63+
*/
64+
imageAssetsFolder?: string;
7465

75-
export default class Animation extends React.Component<AnimationProps, {}> {
76-
/**
77-
* Play the animation all the way through, at the speed specified as a prop.
78-
*/
79-
play: () => {};
66+
/**
67+
* [Android]. Uses hardware acceleration to perform the animation. This should only
68+
* be used for animations where your width and height are equal to the composition width
69+
* and height, e.g. you are not scaling the animation.
70+
* @platform android
71+
*/
72+
hardwareAccelerationAndroid?: boolean;
73+
}
8074

8175
/**
82-
* Reset the animation back to `0` progress.
76+
* View hosting the lottie animation. In order to successfully import this definition in
77+
* your typescript file, you need to import the view as:
78+
*
79+
* `import LottieView = require("lottie-react-native");`
80+
*
81+
* Otherwise the compiler will give you issues and won't work.
8382
*/
84-
reset: () => {}
85-
}
83+
class AnimatedLottieView extends React.Component<AnimatedLottieViewProps, {}> {
84+
play(startFrame?: number, endFrame?: number): void;
85+
reset(): void;
86+
}
87+
88+
export = AnimatedLottieView;
89+
}

0 commit comments

Comments
 (0)