chore(js): clean code

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