forked from madsleejensen/react-native-image-sequence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (39 loc) · 1.19 KB
/
index.js
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
import React, { Component } from 'react';
import {
View,
requireNativeComponent
} from 'react-native';
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
class ImageSequence extends Component {
render() {
let normalized = this.props.images.map(resolveAssetSource);
// reorder elements if start-index is different from 0 (beginning)
if (this.props.startFrameIndex !== 0) {
normalized = [...normalized.slice(this.props.startFrameIndex), ...normalized.slice(0, this.props.startFrameIndex)];
}
return (
<RCTImageSequence
{...this.props}
images={normalized} />
);
}
}
ImageSequence.defaultProps = {
startFrameIndex: 0,
framesPerSecond: 24,
};
ImageSequence.propTypes = {
startFrameIndex: React.PropTypes.number,
images: React.PropTypes.array.isRequired,
framesPerSecond: React.PropTypes.number
};
const RCTImageSequence = requireNativeComponent('RCTImageSequence', {
propTypes: {
...View.propTypes,
images: React.PropTypes.arrayOf(React.PropTypes.shape({
uri: React.PropTypes.string.isRequired
})).isRequired,
framesPerSecond: React.PropTypes.number
},
});
export default ImageSequence;