From 80e713989709a8b14821219967f9aa4cde87af38 Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Sat, 18 Nov 2023 15:39:22 +0100 Subject: [PATCH] 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 Co-authored-by: olivier --- CHANGELOG.md | 2 +- src/types/video.ts | 8 ++++++-- src/utils.ts | 8 +++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee341c38..5870c0f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -371,4 +371,4 @@ - 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) - 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) \ No newline at end of file +- Support setting the poster resize mode [#595](https://github.com/react-native-community/react-native-video/pull/595) diff --git a/src/types/video.ts b/src/types/video.ts index e3b03bc0..013ba245 100644 --- a/src/types/video.ts +++ b/src/types/video.ts @@ -6,7 +6,7 @@ import type FilterType from './FilterType'; export type Headers = Record; -export type ReactVideoSource = Readonly<{ +export type ReactVideoSourceProperties = { uri?: string; isNetwork?: boolean; isAsset?: boolean; @@ -21,7 +21,11 @@ export type ReactVideoSource = Readonly<{ subtitle?: string; description?: string; customImageUri?: string; -}>; +}; + +export type ReactVideoSource = Readonly< + ReactVideoSourceProperties | NodeRequire +>; export type DebugConfig = Readonly<{ enable?: boolean; diff --git a/src/utils.ts b/src/utils.ts index 84beb7d3..9af9c67b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,17 +1,19 @@ import type {Component, RefObject, ComponentClass} from 'react'; import {Image, findNodeHandle} 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; -export function resolveAssetSourceForVideo(source: Source): ReactVideoSource { +export function resolveAssetSourceForVideo( + source: Source, +): ReactVideoSourceProperties { if (typeof source === 'number') { return { uri: Image.resolveAssetSource(source).uri, }; } - return source as ReactVideoSource; + return source as ReactVideoSourceProperties; } export function getReactTag(