-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathVideoPreview.js
More file actions
103 lines (90 loc) · 3.26 KB
/
Copy pathVideoPreview.js
File metadata and controls
103 lines (90 loc) · 3.26 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, requireNativeComponent, View, ViewPropTypes } from 'react-native';
import ImageResizeMode from 'react-native/Libraries/Image/ImageResizeMode';
import ImageStylePropTypes from 'react-native/Libraries/Image/ImageStylePropTypes';
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
import StyleSheetPropType from 'react-native/Libraries/StyleSheet/StyleSheetPropType';
const styles = StyleSheet.create({
base: {
overflow: 'hidden',
},
});
export default class VideoPreview extends Component {
render() {
const source = resolveAssetSource(this.props.source);
const loadingIndicatorSource = resolveAssetSource(this.props.loadingIndicatorSource);
// As opposed to the ios version, here we render `null` when there is no source, source.uri
// or source array.
if (source && source.uri === '') {
console.warn('source.uri should not be an empty string');
}
if (this.props.src) {
console.warn('The <VideoPreview> component requires a `source` property rather than `src`.');
}
if (this.props.children) {
throw new Error('The <VideoPreview> component cannot contain children. If you want to render content on top of the image, consider using the <ImageBackground> component or absolute positioning.');
}
if (source && (source.uri || Array.isArray(source))) {
let style;
let sources;
if (source.uri) {
const {width, height} = source;
style = StyleSheet.flatten([{width, height}, styles.base, this.props.style]);
sources = [{uri: source.uri}];
} else {
style = StyleSheet.flatten([styles.base, this.props.style]);
sources = source;
}
const {onLoadStart, onLoad, onLoadEnd, onError} = this.props;
const nativeProps = Object.assign({}, this.props, {
style,
shouldNotifyLoadEvents: !!(onLoadStart || onLoad || onLoadEnd || onError),
src: sources,
loadingIndicatorSrc: loadingIndicatorSource ? loadingIndicatorSource.uri : null,
});
return <RCTVideoPreview {...nativeProps}/>;
}
return null;
}
};
VideoPreview.propTypes = {
...ViewPropTypes,
style: StyleSheetPropType(ImageStylePropTypes),
source: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string,
}),
PropTypes.number,
PropTypes.arrayOf(
PropTypes.shape({
uri: PropTypes.string,
width: PropTypes.number,
height: PropTypes.number,
}))
]),
blurRadius: PropTypes.number,
loadingIndicatorSource: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string,
}),
PropTypes.number,
]),
progressiveRenderingEnabled: PropTypes.bool,
fadeDuration: PropTypes.number,
onLoadStart: PropTypes.func,
onError: PropTypes.func,
onLoad: PropTypes.func,
onLoadEnd: PropTypes.func,
testID: PropTypes.string,
resizeMethod: PropTypes.oneOf(['auto', 'resize', 'scale']),
resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch', 'center']),
};
const RCTVideoPreview = requireNativeComponent('RCTVideoPreview', VideoPreview, {
nativeOnly: {
src: true,
headers: true,
loadingIndicatorSrc: true,
shouldNotifyLoadEvents: true,
},
});