2023-10-07 04:56:35 -06:00
|
|
|
import type {Component, RefObject, ComponentClass} from 'react';
|
|
|
|
import {Image, UIManager, findNodeHandle} from 'react-native';
|
|
|
|
import type {ImageSourcePropType} from 'react-native';
|
|
|
|
import type {ReactVideoSource} from './types/video';
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
type Source = ImageSourcePropType | ReactVideoSource;
|
|
|
|
|
|
|
|
export function resolveAssetSourceForVideo(source: Source): ReactVideoSource {
|
|
|
|
if (typeof source === 'number') {
|
|
|
|
return {
|
|
|
|
uri: Image.resolveAssetSource(source).uri,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return source as ReactVideoSource;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getViewManagerConfig(name: string) {
|
2023-10-07 04:56:35 -06:00
|
|
|
if ('getViewManagerConfig' in UIManager) {
|
2023-10-06 10:39:14 -06:00
|
|
|
return UIManager.getViewManagerConfig(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return UIManager[name];
|
2023-10-07 04:56:35 -06:00
|
|
|
}
|