forked from madsleejensen/react-native-image-sequence
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (53 loc) · 1.47 KB
/
index.js
File metadata and controls
61 lines (53 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
58
59
60
61
import React, { Component } from 'react';
import { requireNativeComponent } from 'react-native';
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
import { bool, string, number, array, shape, arrayOf } from 'prop-types';
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
class ImageSequence extends Component {
render() {
const {
startFrameIndex,
images,
...otherProps
} = this.props;
let normalized = images.map(resolveAssetSource);
// reorder elements if start-index is different from 0 (beginning)
if (startFrameIndex !== 0) {
normalized = [...normalized.slice(startFrameIndex), ...normalized.slice(0, startFrameIndex)];
}
return (
<RCTImageSequence
{...otherProps}
images={normalized} />
);
}
}
ImageSequence.defaultProps = {
startFrameIndex: 0,
framesPerSecond: 24,
loop: true,
downsampleWidth: -1,
downsampleHeight: -1
};
ImageSequence.propTypes = {
...ViewPropTypes,
startFrameIndex: number,
images: array.isRequired,
framesPerSecond: number,
loop: bool,
downsampleWidth: number,
downsampleHeight: number
};
const RCTImageSequence = requireNativeComponent('RCTImageSequence', {
propTypes: {
...ViewPropTypes,
images: arrayOf(shape({
uri: string.isRequired
})).isRequired,
framesPerSecond: number,
loop: bool,
downsampleWidth: number,
downsampleHeight: number
},
});
export default ImageSequence;