feat: move require (local files) to source.uri
(#3535)
* feat!: move require source to `uri` * pass other source properties * chore: update basic example * chore: restore backward compatibility * docs: update source via require * fix types * make docs build workflow pretty * improve docs
This commit is contained in:
@@ -29,7 +29,9 @@ export type ReactVideoSourceProperties = {
|
||||
};
|
||||
|
||||
export type ReactVideoSource = Readonly<
|
||||
ReactVideoSourceProperties | NodeRequire
|
||||
Omit<ReactVideoSourceProperties, 'uri'> & {
|
||||
uri?: string | NodeRequire;
|
||||
}
|
||||
>;
|
||||
|
||||
export type DebugConfig = Readonly<{
|
||||
|
16
src/utils.ts
16
src/utils.ts
@@ -1,10 +1,7 @@
|
||||
import type {Component, RefObject, ComponentClass} from 'react';
|
||||
import {Image, findNodeHandle} from 'react-native';
|
||||
import type {ImageSourcePropType} from 'react-native';
|
||||
import {Image, findNodeHandle, type ImageSourcePropType} from 'react-native';
|
||||
import type {ReactVideoSource, ReactVideoSourceProperties} from './types/video';
|
||||
|
||||
type Source = ImageSourcePropType | ReactVideoSource;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function generateHeaderForNative(obj?: Record<string, any>) {
|
||||
if (!obj) {
|
||||
@@ -13,14 +10,25 @@ export function generateHeaderForNative(obj?: Record<string, any>) {
|
||||
return Object.entries(obj).map(([key, value]) => ({key, value}));
|
||||
}
|
||||
|
||||
type Source = ImageSourcePropType | ReactVideoSource;
|
||||
|
||||
export function resolveAssetSourceForVideo(
|
||||
source: Source,
|
||||
): ReactVideoSourceProperties {
|
||||
// This is deprecated, but we need to support it for backward compatibility
|
||||
if (typeof source === 'number') {
|
||||
return {
|
||||
uri: Image.resolveAssetSource(source).uri,
|
||||
};
|
||||
}
|
||||
|
||||
if ('uri' in source && typeof source.uri === 'number') {
|
||||
return {
|
||||
...source,
|
||||
uri: Image.resolveAssetSource(source.uri).uri,
|
||||
};
|
||||
}
|
||||
|
||||
return source as ReactVideoSourceProperties;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user