This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathVideo.tsx
82 lines (70 loc) · 1.98 KB
/
Video.tsx
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
import PropTypes from "prop-types"
import React from "react"
import { FlexStyle, requireNativeComponent, StyleProp } from "react-native"
import resolveAssetSource from "react-native/Libraries/Image/resolveAssetSource"
type VideoResizeMode = "contain" | "cover" | "stretch" | "none"
interface VideoProps {
source: {
uri: string
}
size?: {
width: number
height: number
}
loop?: boolean
style?: StyleProp<FlexStyle>
resizeMode?: VideoResizeMode
}
// Note: This is currently unused in Emission,
// but is useful enough that we may want it again in the future.
export class Video extends React.Component<VideoProps> {
static propTypes = {
source: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string,
}),
// Opaque type returned by require('./video.mp4')
PropTypes.number,
]).isRequired,
size: PropTypes.shape({
width: PropTypes.number,
height: PropTypes.number,
}).isRequired,
loop: PropTypes.bool,
resizeMode: PropTypes.string,
style: PropTypes.object,
}
static defaultProps: Partial<VideoProps> = {
loop: true,
resizeMode: "cover",
}
// See https://github.com/react-native-community/react-native-video/blob/master/Video.js#L194
get source(): {
uri: string
isNetwork: boolean
isAsset: boolean
type: string
resizeMode: VideoResizeMode
} {
const resizeMode = this.props.resizeMode
const source = resolveAssetSource(this.props.source) || {}
let uri = source.uri
if (uri && uri.match(/^\//)) {
uri = `file://${uri}`
}
const isNetwork = !!(uri && uri.match(/^https?:/))
const isAsset = !!(uri && uri.match(/^(assets-library|file|content):/))
const type = source.type || "mp4"
return {
uri,
isNetwork,
isAsset,
type,
resizeMode,
}
}
render() {
return <NativeVideo {...this.props} source={this.source} />
}
}
const NativeVideo: React.ComponentClass<any> = requireNativeComponent("ARVideo")