Chore/fix lintter and ts on source prop (#3361)

* fix: Fix types for `ReactVideoSource` to also allow `require(..)` sources

We need to be careful here to not use `any`, so I used `NodeRequire` - which is afaik present in all React Native environments as a type.

---------

Co-authored-by: Marc Rousavy <me@mrousavy.com>
Co-authored-by: olivier <olivier.bouillet@ifeelsmart.com>
This commit is contained in:
Olivier Bouillet 2023-11-18 15:39:22 +01:00 committed by GitHub
parent f2e80e9f2d
commit 80e7139897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 6 deletions

View File

@ -371,4 +371,4 @@
- Add cookie support for ExoPlayer [#922](https://github.com/react-native-community/react-native-video/pull/922) - Add cookie support for ExoPlayer [#922](https://github.com/react-native-community/react-native-video/pull/922)
- Remove ExoPlayer onMetadata that wasn't being used [#1040](https://github.com/react-native-community/react-native-video/pull/1040) - Remove ExoPlayer onMetadata that wasn't being used [#1040](https://github.com/react-native-community/react-native-video/pull/1040)
- Fix bug where setting the progress interval on iOS didn't work [#800](https://github.com/react-native-community/react-native-video/pull/800) - Fix bug where setting the progress interval on iOS didn't work [#800](https://github.com/react-native-community/react-native-video/pull/800)
- Support setting the poster resize mode [#595](https://github.com/react-native-community/react-native-video/pull/595) - Support setting the poster resize mode [#595](https://github.com/react-native-community/react-native-video/pull/595)

View File

@ -6,7 +6,7 @@ import type FilterType from './FilterType';
export type Headers = Record<string, string>; export type Headers = Record<string, string>;
export type ReactVideoSource = Readonly<{ export type ReactVideoSourceProperties = {
uri?: string; uri?: string;
isNetwork?: boolean; isNetwork?: boolean;
isAsset?: boolean; isAsset?: boolean;
@ -21,7 +21,11 @@ export type ReactVideoSource = Readonly<{
subtitle?: string; subtitle?: string;
description?: string; description?: string;
customImageUri?: string; customImageUri?: string;
}>; };
export type ReactVideoSource = Readonly<
ReactVideoSourceProperties | NodeRequire
>;
export type DebugConfig = Readonly<{ export type DebugConfig = Readonly<{
enable?: boolean; enable?: boolean;

View File

@ -1,17 +1,19 @@
import type {Component, RefObject, ComponentClass} from 'react'; import type {Component, RefObject, ComponentClass} from 'react';
import {Image, findNodeHandle} from 'react-native'; import {Image, findNodeHandle} from 'react-native';
import type {ImageSourcePropType} from 'react-native'; import type {ImageSourcePropType} from 'react-native';
import type {ReactVideoSource} from './types/video'; import type {ReactVideoSource, ReactVideoSourceProperties} from './types/video';
type Source = ImageSourcePropType | ReactVideoSource; type Source = ImageSourcePropType | ReactVideoSource;
export function resolveAssetSourceForVideo(source: Source): ReactVideoSource { export function resolveAssetSourceForVideo(
source: Source,
): ReactVideoSourceProperties {
if (typeof source === 'number') { if (typeof source === 'number') {
return { return {
uri: Image.resolveAssetSource(source).uri, uri: Image.resolveAssetSource(source).uri,
}; };
} }
return source as ReactVideoSource; return source as ReactVideoSourceProperties;
} }
export function getReactTag( export function getReactTag(