Skip to content

Commit

Permalink
Fix react-native-video types (#2753)
Browse files Browse the repository at this point in the history
* Change Flow version

* Update tests and types

* Update tests
  • Loading branch information
David Narbutovich authored and villesau committed Sep 24, 2018
1 parent b2855bf commit c8f1226
Show file tree
Hide file tree
Showing 3 changed files with 441 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
declare module "react-native-video" {
// https://github.com/react-native-community/react-native-video/blob/master/TextTrackType.js#L3-L6
declare export type TrackType =
| "application/x-subrip"
| "application/ttml+xml"
| "text/vtt";

// iOS only supports VTT, Android ExoPlayer supports all 3
declare export type TextTrackTypes = {
SRT: "application/x-subrip",
TTML: "application/ttml+xml",
VTT: "text/vtt"
};

declare export var TextTrackType: TextTrackTypes;

declare export type TrackType = $Values<TextTrackTypes>;

declare export type TrackDescriptor = {|
title?: ?string,
Expand All @@ -12,10 +19,28 @@ declare module "react-native-video" {
language: string
|};

declare export type SelectedTrackDescriptor = {|
type: string,
value?: ?(string | number)
|};
// https://github.com/react-native-community/react-native-video#selectedaudiotrack
declare export type SelectedTrackDescriptor =
| {|
type: "system",
value?: any
|}
| {|
type: "disabled",
value?: any
|}
| {|
type: "title",
value: string
|}
| {|
type: "language",
value: string
|}
| {|
type: "index",
value: number
|};

declare export type BufferConfigDescriptor = {|
minBufferMs?: ?number,
Expand All @@ -24,11 +49,14 @@ declare module "react-native-video" {
bufferForPlaybackAfterRebufferMs?: ?number
|};

declare export type Event<T: {}> = { +target: number } & T;
declare export type Event<T: {}> = $ReadOnly<{|
target: number,
...$Exact<T>
|}>;

declare export type LoadEvent = Event<
$ReadOnly<{
audioTracks: Array<TrackDescriptor>,
audioTracks: $ReadOnlyArray<TrackDescriptor>,
canPlayFastForward: boolean,
canPlayReverse: boolean,
canPlaySlowForward: boolean,
Expand All @@ -42,14 +70,14 @@ declare module "react-native-video" {
orientation: string,
width: number
|}>,
textTracks: Array<TrackDescriptor>
textTracks: $ReadOnlyArray<TrackDescriptor>
}>
>;

declare export type ProgressEvent = Event<{|
currentTime: number,
playableDuration: number,
seekableDuration: number
+currentTime: number,
+playableDuration: number,
+seekableDuration: number
|}>;

declare export type AudioFocusChangedEvent = Event<{
Expand All @@ -58,36 +86,18 @@ declare module "react-native-video" {

declare export type BufferEvent = Event<{ +isBuffering: boolean }>;

declare export type LoadStartEvent = Event<{|
isNetwork: boolean,
type: string,
uri: string
|}>;
declare export type LoadStartEvent = Event<{
+isNetwork: boolean,
+type: string,
+uri: string
}>;

declare export type TimedMetadataEvent = Event<{|
metadata: Array<{| value: string, identifier: string |}>
|}>;
declare export type TimedMetadata = {| +value: string, +identifier: string |};
declare export type TimedMetadataEvent = Event<{
+metadata: $ReadOnlyArray<TimedMetadata>
}>;

declare export type VideoProps = $ReadOnly<{
/* Native only */
src?: ?Object,
seek?: ?(number | Object),
fullscreen?: ?boolean,
onVideoLoadStart?: ?Function,
onVideoLoad?: ?Function,
onVideoBuffer?: ?Function,
onVideoError?: ?Function,
onVideoProgress?: ?Function,
onVideoSeek?: ?Function,
onVideoEnd?: ?Function,
onTimedMetadata?: ?(?TimedMetadataEvent) => void,
onVideoAudioBecomingNoisy?: ?Function,
onVideoFullscreenPlayerWillPresent?: ?Function,
onVideoFullscreenPlayerDidPresent?: ?Function,
onVideoFullscreenPlayerWillDismiss?: ?Function,
onVideoFullscreenPlayerDidDismiss?: ?Function,

/* Wrapper component */
source: number | {| uri: string |},
// https://github.com/react-native-community/react-native-video/blob/master/VideoResizeMode.js#L4-L6
resizeMode?: ?("contain" | "cover" | "stretch"),
Expand All @@ -96,8 +106,8 @@ declare module "react-native-video" {
posterResizeMode?: ?("cover" | "contain" | "stretch" | "repeat" | "center"),
repeat?: ?boolean,
allowsExternalPlayback?: ?boolean,
selectedAudioTrack?: ?SelectedTrackDescriptor,
selectedTextTrack?: ?SelectedTrackDescriptor,
selectedAudioTrack?: SelectedTrackDescriptor,
selectedTextTrack?: SelectedTrackDescriptor,
textTracks?: Array<TrackDescriptor>,
paused?: ?boolean,
muted?: ?boolean,
Expand All @@ -114,11 +124,11 @@ declare module "react-native-video" {
currentTime?: ?number,
progressUpdateInterval?: ?number,
useTextureView?: ?boolean,
onLoadStart?: ?(?LoadStartEvent) => void,
onLoad?: ?(?LoadEvent) => void,
onBuffer?: ?(?BufferEvent) => void,
onLoadStart?: ?(LoadStartEvent) => void,
onLoad?: ?(LoadEvent) => void,
onBuffer?: ?(BufferEvent) => void,
onError?: ?Function,
onProgress?: ?(?ProgressEvent) => void,
onProgress?: ?(ProgressEvent) => void,
onSeek?: ?Function,
onEnd?: ?Function,
onFullscreenPlayerWillPresent?: ?Function,
Expand All @@ -129,8 +139,9 @@ declare module "react-native-video" {
onPlaybackStalled?: ?Function,
onPlaybackResume?: ?Function,
onPlaybackRateChange?: ?Function,
onAudioFocusChanged?: ?(?AudioFocusChangedEvent) => void,
onAudioFocusChanged?: ?(AudioFocusChangedEvent) => void,
onAudioBecomingNoisy?: ?Function,
onTimedMetadata?: ?(TimedMetadataEvent) => void,

/* Required by react-native */
scaleX?: ?number,
Expand All @@ -140,8 +151,6 @@ declare module "react-native-video" {
rotation?: ?number
}>;

declare export var TextTrackType: { +[key: string]: TrackType };

declare export default class Video extends React$Component<VideoProps> {
dismissFullscreenPlayer(): void;
presentFullscreenPlayer(): void;
Expand Down
Loading

0 comments on commit c8f1226

Please sign in to comment.