mirror of
https://github.com/zoriya/react-native-video.git
synced 2026-05-29 17:34:41 +00:00
chore(js): clean code
This commit is contained in:
+302
-286
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@
|
||||
import AVFoundation
|
||||
|
||||
public final class AVAssetUtils {
|
||||
public static func getAssetInformation(for asset: AVAsset) async throws -> VideoInformation {
|
||||
public static func getAssetInformation(for asset: AVURLAsset) async throws -> VideoInformation {
|
||||
// Initialize with default values
|
||||
var videoInformation = VideoInformation(
|
||||
bitrate: Double.nan,
|
||||
@@ -20,7 +20,7 @@ public final class AVAssetUtils {
|
||||
orientation: .unknown
|
||||
)
|
||||
|
||||
videoInformation.fileSize = try await getFileSize(for: <#T##URL#>)
|
||||
videoInformation.fileSize = try await getFileSize(for: asset.url)
|
||||
|
||||
// Check if asset is live stream
|
||||
if asset.duration.flags.contains(.indefinite) {
|
||||
|
||||
+1
-11
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
UIManager,
|
||||
Platform,
|
||||
// type ViewStyle,
|
||||
// type ViewProps,
|
||||
} from 'react-native';
|
||||
import { UIManager, Platform } from 'react-native';
|
||||
|
||||
import VideoViewNativeComponent from './spec/fabric/VideoViewNativeComponent';
|
||||
|
||||
@@ -13,11 +8,6 @@ const LINKING_ERROR =
|
||||
'- You rebuilt the app after installing the package\n' +
|
||||
'- You are not using Expo Go\n';
|
||||
|
||||
// interface VideoProps extends ViewProps {
|
||||
// nitroId: number;
|
||||
// style?: ViewStyle;
|
||||
// }
|
||||
|
||||
const ComponentName = 'VideoView';
|
||||
|
||||
export const NativeVideoView =
|
||||
|
||||
+2
-16
@@ -1,12 +1,12 @@
|
||||
import * as React from 'react';
|
||||
import type { ViewStyle } from 'react-native';
|
||||
import { NitroModules } from 'react-native-nitro-modules';
|
||||
import type { VideoPlayer } from './spec/nitro/VideoPlayer.nitro';
|
||||
import { NativeVideoView } from './NativeVideoView';
|
||||
import { NitroModules } from 'react-native-nitro-modules';
|
||||
import type {
|
||||
VideoViewViewManager,
|
||||
VideoViewViewManagerFactory,
|
||||
} from './spec/nitro/VideoViewViewManager.nitro';
|
||||
import type { ViewStyle } from 'react-native';
|
||||
|
||||
interface VideoViewProps {
|
||||
player: VideoPlayer;
|
||||
@@ -19,8 +19,6 @@ const VideoViewViewManagerFactory =
|
||||
'VideoViewViewManagerFactory'
|
||||
);
|
||||
|
||||
const DEBUG = false;
|
||||
|
||||
const VideoView = ({ player, ...props }: VideoViewProps) => {
|
||||
const nitroId = React.useMemo(() => nitroIdCounter++, []);
|
||||
const nitroViewManager = React.useRef<VideoViewViewManager | null>(null);
|
||||
@@ -28,11 +26,9 @@ const VideoView = ({ player, ...props }: VideoViewProps) => {
|
||||
const setupViewManager = React.useCallback(
|
||||
(id: number) => {
|
||||
if (nitroViewManager.current !== null) {
|
||||
DEBUG && console.warn('View Manager already setup');
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG && console.log('Setup View Manager');
|
||||
nitroViewManager.current =
|
||||
VideoViewViewManagerFactory.createViewManager(id);
|
||||
|
||||
@@ -50,26 +46,16 @@ const VideoView = ({ player, ...props }: VideoViewProps) => {
|
||||
|
||||
const onNitroIdChange = React.useCallback(
|
||||
(event: { nativeEvent: { nitroId: number } }) => {
|
||||
DEBUG && console.log('NitroId Change', event.nativeEvent.nitroId);
|
||||
setupViewManager(event.nativeEvent.nitroId);
|
||||
},
|
||||
[setupViewManager]
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
DEBUG && console.log('VideoView Mounted');
|
||||
|
||||
return () => {
|
||||
DEBUG && console.log('VideoView Unmounted');
|
||||
};
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!nitroViewManager.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG && console.log('Update View Manager Props');
|
||||
nitroViewManager.current.player = player;
|
||||
}, [player]);
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { useMemo, useRef, useEffect } from 'react';
|
||||
import { useEffect, useMemo, useRef, type DependencyList } from 'react';
|
||||
import type { HybridObject } from 'react-native-nitro-modules';
|
||||
|
||||
// https://github.com/expo/expo/blob/main/packages/expo-modules-core/src/hooks/useReleasingSharedObject.ts
|
||||
|
||||
/**
|
||||
* A hook that helps to manage the lifecycle of a hybrid object in a React component.
|
||||
*
|
||||
*
|
||||
* @param objectFactory - A function that creates a new hybrid object.
|
||||
* @param dependencies - An array of dependencies that determine when the object should be recreated.
|
||||
* @returns The hybrid object.
|
||||
*/
|
||||
export const useReleasingHybridObject = <THybridObject extends HybridObject>(
|
||||
objectFactory: () => THybridObject,
|
||||
dependencies: unknown[]
|
||||
dependencies: DependencyList
|
||||
): THybridObject => {
|
||||
const objectRef = useRef<THybridObject | null>(null);
|
||||
const isFastRefresh = useRef(false);
|
||||
@@ -26,7 +26,9 @@ export const useReleasingHybridObject = <THybridObject extends HybridObject>(
|
||||
let newObject = objectRef.current;
|
||||
const depsAreEqual =
|
||||
previousDependencies.current?.length === dependencies.length &&
|
||||
dependencies.every((value, index) => value === previousDependencies.current[index]);
|
||||
dependencies.every(
|
||||
(value, index) => value === previousDependencies.current[index]
|
||||
);
|
||||
|
||||
if (!newObject || !depsAreEqual) {
|
||||
// Destroy the old object
|
||||
@@ -42,8 +44,10 @@ export const useReleasingHybridObject = <THybridObject extends HybridObject>(
|
||||
} else {
|
||||
isFastRefresh.current = true;
|
||||
}
|
||||
|
||||
|
||||
return newObject;
|
||||
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, dependencies);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user