2023-10-07 04:56:35 -06:00
|
|
|
import type {Component, RefObject, ComponentClass} from 'react';
|
2024-03-13 01:23:11 -06:00
|
|
|
import {Image, findNodeHandle, type ImageSourcePropType} from 'react-native';
|
2023-11-18 07:39:22 -07:00
|
|
|
import type {ReactVideoSource, ReactVideoSourceProperties} from './types/video';
|
2023-10-06 10:39:14 -06:00
|
|
|
|
2024-03-07 03:35:17 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
export function generateHeaderForNative(obj?: Record<string, any>) {
|
|
|
|
if (!obj) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return Object.entries(obj).map(([key, value]) => ({key, value}));
|
|
|
|
}
|
|
|
|
|
2024-03-13 01:23:11 -06:00
|
|
|
type Source = ImageSourcePropType | ReactVideoSource;
|
|
|
|
|
2023-11-18 07:39:22 -07:00
|
|
|
export function resolveAssetSourceForVideo(
|
|
|
|
source: Source,
|
|
|
|
): ReactVideoSourceProperties {
|
2024-03-13 01:23:11 -06:00
|
|
|
// This is deprecated, but we need to support it for backward compatibility
|
2023-10-06 10:39:14 -06:00
|
|
|
if (typeof source === 'number') {
|
|
|
|
return {
|
|
|
|
uri: Image.resolveAssetSource(source).uri,
|
|
|
|
};
|
|
|
|
}
|
2024-03-13 01:23:11 -06:00
|
|
|
|
|
|
|
if ('uri' in source && typeof source.uri === 'number') {
|
|
|
|
return {
|
|
|
|
...source,
|
|
|
|
uri: Image.resolveAssetSource(source.uri).uri,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-11-18 07:39:22 -07:00
|
|
|
return source as ReactVideoSourceProperties;
|
2023-10-06 10:39:14 -06:00
|
|
|
}
|
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
export function getReactTag(
|
|
|
|
ref: RefObject<
|
|
|
|
| Component<unknown, unknown, unknown>
|
|
|
|
| ComponentClass<unknown, unknown>
|
|
|
|
| null
|
|
|
|
>,
|
|
|
|
): number {
|
2023-10-06 10:39:14 -06:00
|
|
|
if (!ref.current) {
|
2023-10-07 04:56:35 -06:00
|
|
|
throw new Error('Video Component is not mounted');
|
2023-10-06 10:39:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const reactTag = findNodeHandle(ref.current);
|
|
|
|
|
|
|
|
if (!reactTag) {
|
2023-10-07 04:56:35 -06:00
|
|
|
throw new Error(
|
|
|
|
'Cannot find reactTag for Video Component in components tree',
|
|
|
|
);
|
2023-10-06 10:39:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return reactTag;
|
|
|
|
}
|