feat: refactor resize prop handler (#3286)
This commit is contained in:
@@ -8,9 +8,8 @@ import React, {
|
||||
type ComponentRef,
|
||||
} from 'react';
|
||||
import {View, StyleSheet, Image, Platform} from 'react-native';
|
||||
import NativeVideoComponent, {RCTVideoConstants} from './VideoNativeComponent';
|
||||
import NativeVideoComponent from './VideoNativeComponent';
|
||||
import type {
|
||||
NativeVideoResizeMode,
|
||||
OnAudioFocusChangedData,
|
||||
OnAudioTracksData,
|
||||
OnPlaybackStateChangedData,
|
||||
@@ -150,19 +149,6 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
||||
};
|
||||
}, [source]);
|
||||
|
||||
const _resizeMode: NativeVideoResizeMode = useMemo(() => {
|
||||
switch (resizeMode) {
|
||||
case 'contain':
|
||||
return RCTVideoConstants.ScaleAspectFit;
|
||||
case 'cover':
|
||||
return RCTVideoConstants.ScaleAspectFill;
|
||||
case 'stretch':
|
||||
return RCTVideoConstants.ScaleToFill;
|
||||
default:
|
||||
return RCTVideoConstants.ScaleNone;
|
||||
}
|
||||
}, [resizeMode]);
|
||||
|
||||
const _drm = useMemo(() => {
|
||||
if (!drm) {
|
||||
return;
|
||||
@@ -476,7 +462,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
||||
src={src}
|
||||
drm={_drm}
|
||||
style={StyleSheet.absoluteFill}
|
||||
resizeMode={_resizeMode}
|
||||
resizeMode={resizeMode}
|
||||
fullscreen={isFullscreen}
|
||||
restoreUserInterfaceForPIPStopCompletionHandler={
|
||||
_restoreUserInterfaceForPIPStopCompletionHandler
|
||||
|
@@ -4,7 +4,6 @@ import type {
|
||||
ViewProps,
|
||||
} from 'react-native';
|
||||
import {NativeModules, requireNativeComponent} from 'react-native';
|
||||
import {getViewManagerConfig} from './utils';
|
||||
|
||||
// -------- There are types for native component (future codegen) --------
|
||||
// if you are looking for types for react component, see src/types/video.ts
|
||||
@@ -233,15 +232,13 @@ export type OnVideoErrorData = Readonly<{
|
||||
export type OnAudioFocusChangedData = Readonly<{
|
||||
hasFocus: boolean;
|
||||
}>;
|
||||
|
||||
export type NativeVideoResizeMode = unknown;
|
||||
export interface VideoNativeProps extends ViewProps {
|
||||
src?: VideoSrc;
|
||||
drm?: Drm;
|
||||
adTagUrl?: string;
|
||||
allowsExternalPlayback?: boolean; // ios, true
|
||||
maxBitRate?: number;
|
||||
resizeMode?: NativeVideoResizeMode;
|
||||
resizeMode?: 'none' | 'cover' | 'contain' | 'stretch';
|
||||
repeat?: boolean;
|
||||
automaticallyWaitsToMinimizeStalling?: boolean;
|
||||
textTracks?: TextTracks;
|
||||
@@ -364,22 +361,9 @@ export interface VideoDecoderPropertiesType {
|
||||
isHEVCSupported: () => Promise<'unsupported' | 'hardware' | 'software'>;
|
||||
}
|
||||
|
||||
export type VideoViewManagerConfig = {
|
||||
Constants: {
|
||||
ScaleNone: unknown;
|
||||
ScaleToFill: unknown;
|
||||
ScaleAspectFit: unknown;
|
||||
ScaleAspectFill: unknown;
|
||||
};
|
||||
Commands: {[key: string]: number};
|
||||
};
|
||||
|
||||
export const VideoManager = NativeModules.VideoManager as VideoManagerType;
|
||||
export const VideoDecoderProperties =
|
||||
NativeModules.VideoDecoderProperties as VideoDecoderPropertiesType;
|
||||
export const RCTVideoConstants = (
|
||||
getViewManagerConfig('RCTVideo') as VideoViewManagerConfig
|
||||
).Constants;
|
||||
|
||||
export default requireNativeComponent<VideoNativeProps>(
|
||||
'RCTVideo',
|
||||
|
10
src/utils.ts
10
src/utils.ts
@@ -1,5 +1,5 @@
|
||||
import type {Component, RefObject, ComponentClass} from 'react';
|
||||
import {Image, UIManager, findNodeHandle} from 'react-native';
|
||||
import {Image, findNodeHandle} from 'react-native';
|
||||
import type {ImageSourcePropType} from 'react-native';
|
||||
import type {ReactVideoSource} from './types/video';
|
||||
|
||||
@@ -35,11 +35,3 @@ export function getReactTag(
|
||||
|
||||
return reactTag;
|
||||
}
|
||||
|
||||
export function getViewManagerConfig(name: string) {
|
||||
if ('getViewManagerConfig' in UIManager) {
|
||||
return UIManager.getViewManagerConfig(name);
|
||||
}
|
||||
|
||||
return UIManager[name];
|
||||
}
|
||||
|
Reference in New Issue
Block a user