mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +00:00
Update types for React-Native-Video to allow passing of error and data objects to onError and onLoad callbacks respectively (#23209)
* Add types for onLoad and onError * Clean up and add tests
This commit is contained in:
Vendored
+28
-5
@@ -3,13 +3,36 @@
|
||||
// Definitions by: HuHuanming <https://github.com/huhuanming>
|
||||
// abrahambotros <https://github.com/abrahambotros>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
import * as React from 'react';
|
||||
import {
|
||||
ViewProperties
|
||||
} from 'react-native';
|
||||
|
||||
export interface OnLoadData {
|
||||
canPlayFastForward: boolean;
|
||||
canPlayReverse: boolean;
|
||||
canPlaySlowForward: boolean;
|
||||
canPlaySlowReverse: boolean;
|
||||
canStepBackward: boolean;
|
||||
canStepForward: boolean;
|
||||
currentTime: number;
|
||||
duration: number;
|
||||
naturalSize: {
|
||||
height: number;
|
||||
width: number;
|
||||
orientation: 'horizontal' | 'landscape';
|
||||
};
|
||||
}
|
||||
|
||||
export interface LoadError {
|
||||
error: {
|
||||
'': string;
|
||||
errorString: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface VideoProperties extends ViewProperties {
|
||||
/* Native only */
|
||||
src?: any;
|
||||
@@ -46,12 +69,12 @@ export interface VideoProperties extends ViewProperties {
|
||||
currentTime?: number;
|
||||
progressUpdateInterval?: number;
|
||||
onLoadStart?(): void;
|
||||
onLoad?(): void;
|
||||
onLoad?(data: OnLoadData): void;
|
||||
onBuffer?(): void;
|
||||
onError?(): void;
|
||||
onError?(error: LoadError): void;
|
||||
onProgress?(data: {
|
||||
currentTime: number,
|
||||
playableDuration: number,
|
||||
currentTime: number;
|
||||
playableDuration: number;
|
||||
}): void;
|
||||
onSeek?(): void;
|
||||
onEnd?(): void;
|
||||
|
||||
@@ -17,10 +17,40 @@ class VideoTest extends React.Component {
|
||||
<Video
|
||||
source={{ uri: '//:example.com/test.mp4' }}
|
||||
onProgress={this.onProgress}
|
||||
onError={this.onError}
|
||||
onLoad={this.onLoad}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
onError = (error: {
|
||||
error: {
|
||||
'': string,
|
||||
errorString: string
|
||||
}
|
||||
}): void => {
|
||||
console.log(error.error[''], error.error.errorString);
|
||||
}
|
||||
|
||||
onLoad = (data: {
|
||||
canPlayFastForward: boolean,
|
||||
canPlayReverse: boolean,
|
||||
canPlaySlowForward: boolean,
|
||||
canPlaySlowReverse: boolean,
|
||||
canStepBackward: boolean,
|
||||
canStepForward: boolean,
|
||||
currentTime: number,
|
||||
duration: number,
|
||||
naturalSize: {
|
||||
height: number;
|
||||
width: number;
|
||||
orientation: 'horizontal' | 'landscape';
|
||||
}
|
||||
}): void => {
|
||||
console.log(data.canPlayFastForward, data.canPlayReverse, data.canPlaySlowForward, data.canPlaySlowReverse,
|
||||
data.canStepBackward, data.canStepForward, data.currentTime, data.duration, data.naturalSize.height, data.naturalSize.width, data.naturalSize.orientation);
|
||||
}
|
||||
|
||||
onProgress = (data: {
|
||||
currentTime: number,
|
||||
playableDuration: number,
|
||||
|
||||
Reference in New Issue
Block a user