2023-10-07 04:56:35 -06:00
|
|
|
import type {Component, RefObject, ComponentClass} from 'react';
|
2023-10-11 13:56:54 -06:00
|
|
|
import {Image, findNodeHandle} from 'react-native';
|
2023-10-07 04:56:35 -06:00
|
|
|
import 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
|
|
|
|
|
|
|
type Source = ImageSourcePropType | ReactVideoSource;
|
|
|
|
|
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}));
|
|
|
|
}
|
|
|
|
|
2023-11-18 07:39:22 -07:00
|
|
|
export function resolveAssetSourceForVideo(
|
|
|
|
source: Source,
|
|
|
|
): ReactVideoSourceProperties {
|
2023-10-06 10:39:14 -06:00
|
|
|
if (typeof source === 'number') {
|
|
|
|
return {
|
|
|
|
uri: Image.resolveAssetSource(source).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;
|
|
|
|
}
|