chore: lint code

This commit is contained in:
Krzysztof Moch
2025-01-20 13:28:27 +01:00
parent 2e6ac0d5a0
commit 85a9a1472f
6 changed files with 71 additions and 52 deletions
+29 -22
View File
@@ -1,5 +1,5 @@
import * as React from 'react'; import * as React from 'react';
import { Button, Dimensions, Platform, StyleSheet, View } from 'react-native'; import { Button, Dimensions, StyleSheet, View } from 'react-native';
import { VideoView, createSource, useVideoPlayer } from 'react-native-video'; import { VideoView, createSource, useVideoPlayer } from 'react-native-video';
export default function App() { export default function App() {
@@ -10,32 +10,39 @@ export default function App() {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<View style={styles.videoContainer}> <View style={styles.videoContainer}>
{/* <VideoView player={player} style={styles.box} /> */} {show && <VideoView player={player} style={styles.box} />}
{/* Two VideoViews with same player are supported not supported on Android */}
{show && (
<VideoView player={player} style={styles.box} />
)}
</View> </View>
<Button title="Play" onPress={() => player.play()} /> <Button title="Play" onPress={() => player.play()} />
<Button title="Pause" onPress={() => player.pause()} /> <Button title="Pause" onPress={() => player.pause()} />
<Button title="Seek to 3sec" onPress={() => player.currentTime = 3} /> <Button title="Seek to 3sec" onPress={() => (player.currentTime = 3)} />
<Button title="Toggle" onPress={() => setShow((prev) => !prev)} /> <Button title="Toggle" onPress={() => setShow((prev) => !prev)} />
<Button title="Preload player" onPress={() => { <Button
player.preload().then(() => { title="Preload player"
// setShow(true); onPress={() => {
}).catch((error) => { player
console.error(error); .preload()
}); .then(() => {
}} /> // setShow(true);
<Button title="Replace source" onPress={() => { })
const newSource = createSource("https://www.w3schools.com/html/mov_bbb.mp4") .catch((error) => {
console.error(error);
newSource.getAssetInformationAsync().then((assetInfo) => { });
console.log(assetInfo); }}
}) />
<Button
title="Replace source"
onPress={() => {
const newSource = createSource(
'https://www.w3schools.com/html/mov_bbb.mp4'
);
player.replaceSourceAsync(newSource); newSource.getAssetInformationAsync().then((assetInfo) => {
}} /> console.log(assetInfo);
});
player.replaceSourceAsync(newSource);
}}
/>
</View> </View>
); );
} }
+1 -1
View File
@@ -3,4 +3,4 @@ export { useVideoPlayer } from './utils/useVideoPlayer';
export { createPlayer, createSource } from './utils/factory'; export { createPlayer, createSource } from './utils/factory';
export type { VideoPlayer } from './spec/nitro/VideoPlayer.nitro'; export type { VideoPlayer } from './spec/nitro/VideoPlayer.nitro';
export type { VideoSource } from './types/VideoConfig'; export type { VideoSource } from './types/VideoConfig';
+2 -2
View File
@@ -1,5 +1,5 @@
export type VideoSource = number | string; export type VideoSource = number | string;
export type VideoConfig = { export type VideoConfig = {
uri: VideoSource; uri: VideoSource;
} };
+8 -2
View File
@@ -1,4 +1,10 @@
export type VideoOrientation = "portrait" | "landscape" | "portrait-upside-down" | "landscape-left" | "landscape-right" | "unknown"; export type VideoOrientation =
| 'portrait'
| 'landscape'
| 'portrait-upside-down'
| 'landscape-left'
| 'landscape-right'
| 'unknown';
export interface VideoInformation { export interface VideoInformation {
/** /**
@@ -41,4 +47,4 @@ export interface VideoInformation {
* see {@link VideoOrientation} * see {@link VideoOrientation}
*/ */
orientation: VideoOrientation; orientation: VideoOrientation;
} }
+18 -9
View File
@@ -1,8 +1,11 @@
import { NitroModules } from "react-native-nitro-modules"; import { NitroModules } from 'react-native-nitro-modules';
import type { VideoPlayer, VideoPlayerFactory } from '../spec/nitro/VideoPlayer.nitro'; import type {
VideoPlayer,
VideoPlayerFactory,
} from '../spec/nitro/VideoPlayer.nitro';
import type { VideoPlayerSourceFactory } from '../spec/nitro/VideoPlayerSource.nitro'; import type { VideoPlayerSourceFactory } from '../spec/nitro/VideoPlayerSource.nitro';
import type { VideoConfig, VideoSource } from "../types/VideoConfig"; import type { VideoConfig, VideoSource } from '../types/VideoConfig';
import { Image } from "react-native"; import { Image } from 'react-native';
// ----------- Factories ----------- // ----------- Factories -----------
const VideoPlayerSourceFactory = const VideoPlayerSourceFactory =
@@ -14,20 +17,26 @@ const VideoPlayerFactory =
NitroModules.createHybridObject<VideoPlayerFactory>('VideoPlayerFactory'); NitroModules.createHybridObject<VideoPlayerFactory>('VideoPlayerFactory');
// ----------- Factories functions ----------- // ----------- Factories functions -----------
export const createPlayer = (source: VideoSource | VideoConfig): VideoPlayer => { export const createPlayer = (
source: VideoSource | VideoConfig
): VideoPlayer => {
// If source is a string, we can directly create the player // If source is a string, we can directly create the player
if (typeof source === 'string') { if (typeof source === 'string') {
return VideoPlayerFactory.createPlayer(VideoPlayerSourceFactory.fromUri(source)); return VideoPlayerFactory.createPlayer(
VideoPlayerSourceFactory.fromUri(source)
);
} }
// If source is a number (asset), we need to resolve the asset source and create the player // If source is a number (asset), we need to resolve the asset source and create the player
if (typeof source === 'number') { if (typeof source === 'number') {
return VideoPlayerFactory.createPlayer(VideoPlayerSourceFactory.fromUri(Image.resolveAssetSource(source).uri)); return VideoPlayerFactory.createPlayer(
VideoPlayerSourceFactory.fromUri(Image.resolveAssetSource(source).uri)
);
} }
// If source is an object (VideoConfig) // If source is an object (VideoConfig)
if (typeof source === 'object' && 'uri' in source) { if (typeof source === 'object' && 'uri' in source) {
return createPlayer(source.uri) return createPlayer(source.uri);
} }
throw new Error('RNV: Invalid source type'); throw new Error('RNV: Invalid source type');
@@ -35,4 +44,4 @@ export const createPlayer = (source: VideoSource | VideoConfig): VideoPlayer =>
export const createSource = (uri: string) => { export const createSource = (uri: string) => {
return VideoPlayerSourceFactory.fromUri(uri); return VideoPlayerSourceFactory.fromUri(uri);
}; };
+13 -16
View File
@@ -1,25 +1,22 @@
import type { VideoPlayer } from "../spec/nitro/VideoPlayer.nitro"; import type { VideoPlayer } from '../spec/nitro/VideoPlayer.nitro';
import { useReleasingHybridObject } from "./useReleasingHybridObject"; import { useReleasingHybridObject } from './useReleasingHybridObject';
import { createPlayer } from "./factory"; import { createPlayer } from './factory';
import type { VideoConfig, VideoSource } from "../types/VideoConfig"; import type { VideoConfig, VideoSource } from '../types/VideoConfig';
/** /**
* A hook that creates and manages a video player. * A hook that creates and manages a video player.
* *
* @param source - The source of the video. * @param source - The source of the video.
* @param setup - A function that allow to setup the video player after it is created. * @param setup - A function that allow to setup the video player after it is created.
* @returns VideoPlayer (see {@link VideoPlayer}) * @returns VideoPlayer (see {@link VideoPlayer})
*/ */
export const useVideoPlayer = ( export const useVideoPlayer = (
source: VideoConfig | VideoSource, source: VideoConfig | VideoSource,
setup?: (player: VideoPlayer) => void setup?: (player: VideoPlayer) => void
) => { ) => {
return useReleasingHybridObject( return useReleasingHybridObject(() => {
() => { const videoPlayer = createPlayer(source);
const videoPlayer = createPlayer(source); setup?.(videoPlayer);
setup?.(videoPlayer); return videoPlayer;
return videoPlayer; }, [source]);
}, };
[source]
);
}