mirror of
https://github.com/zoriya/react-native-video.git
synced 2026-06-04 11:35:13 +00:00
chore: code cleanup
This commit is contained in:
+3
-3
@@ -11,9 +11,9 @@ class OnAudioFocusChangedListener : AudioManager.OnAudioFocusChangeListener {
|
|||||||
|
|
||||||
override fun onAudioFocusChange(focusChange: Int) {
|
override fun onAudioFocusChange(focusChange: Int) {
|
||||||
when (focusChange) {
|
when (focusChange) {
|
||||||
AudioManager.AUDIOFOCUS_GAIN -> eventEmitter?.onAudioFocusChange(true)
|
AudioManager.AUDIOFOCUS_GAIN -> eventEmitter?.onAudioFocusChange?.invoke(true)
|
||||||
AudioManager.AUDIOFOCUS_LOSS -> eventEmitter?.onAudioFocusChange(false)
|
AudioManager.AUDIOFOCUS_LOSS -> eventEmitter?.onAudioFocusChange?.invoke(false)
|
||||||
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> eventEmitter?.onAudioFocusChange(false)
|
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> eventEmitter?.onAudioFocusChange?.invoke(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ class AudioBecomingNoisyReceiver() : BroadcastReceiver() {
|
|||||||
|
|
||||||
override fun onReceive(context: Context?, intent: Intent?) {
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
if (intent?.action == AudioManager.ACTION_AUDIO_BECOMING_NOISY) {
|
if (intent?.action == AudioManager.ACTION_AUDIO_BECOMING_NOISY) {
|
||||||
eventEmitter?.onAudioBecomingNoisy()
|
eventEmitter?.onAudioBecomingNoisy?.invoke()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -51,7 +51,7 @@ class HybridVideoViewViewManager(nitroId: Int): HybridVideoViewViewManagerSpec()
|
|||||||
}
|
}
|
||||||
|
|
||||||
override var autoEnterPictureInPicture: Boolean
|
override var autoEnterPictureInPicture: Boolean
|
||||||
get() = videoView.get()?.autoEnterPictureInPicture == true
|
get() = videoView.get()?.autoEnterPictureInPicture
|
||||||
set(value) {
|
set(value) {
|
||||||
videoView.get()?.autoEnterPictureInPicture = value
|
videoView.get()?.autoEnterPictureInPicture = value
|
||||||
}
|
}
|
||||||
@@ -69,32 +69,32 @@ class HybridVideoViewViewManager(nitroId: Int): HybridVideoViewViewManagerSpec()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// View callbacks
|
// View callbacks
|
||||||
override var onPictureInPictureChange: ((Boolean) -> Unit)?
|
override var onPictureInPictureChange: ((Boolean) -> Unit)? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
videoView.get()?.events?.onPictureInPictureChange = value
|
videoView.get()?.events?.onPictureInPictureChange = value
|
||||||
}
|
}
|
||||||
override var onFullscreenChange: ((Boolean) -> Unit)?
|
override var onFullscreenChange: ((Boolean) -> Unit)? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
videoView.get()?.events?.onFullscreenChange = value
|
videoView.get()?.events?.onFullscreenChange = value
|
||||||
}
|
}
|
||||||
override var willEnterFullscreen: (() -> Unit)?
|
override var willEnterFullscreen: (() -> Unit)? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
videoView.get()?.events?.willEnterFullscreen = value
|
videoView.get()?.events?.willEnterFullscreen = value
|
||||||
}
|
}
|
||||||
override var willExitFullscreen: (() -> Unit)?
|
override var willExitFullscreen: (() -> Unit)? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
videoView.get()?.events?.willExitFullscreen = value
|
videoView.get()?.events?.willExitFullscreen = value
|
||||||
}
|
}
|
||||||
override var willEnterPictureInPicture: (() -> Unit)?
|
override var willEnterPictureInPicture: (() -> Unit)? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
videoView.get()?.events?.willEnterPictureInPicture = value
|
videoView.get()?.events?.willEnterPictureInPicture = value
|
||||||
}
|
}
|
||||||
override var willExitPictureInPicture: (() -> Unit)?
|
override var willExitPictureInPicture: (() -> Unit)? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
videoView.get()?.events?.willExitPictureInPicture = value
|
videoView.get()?.events?.willExitPictureInPicture = value
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-video",
|
"name": "react-native-video",
|
||||||
"version": "7.0.0-dev.6",
|
"version": "7.0.0-dev.7",
|
||||||
"description": "<Video /> Component for React Native",
|
"description": "<Video /> Component for React Native",
|
||||||
"source": "./src/index.tsx",
|
"source": "./src/index.tsx",
|
||||||
"main": "./lib/commonjs/index.js",
|
"main": "./lib/commonjs/index.js",
|
||||||
|
|||||||
@@ -2,12 +2,23 @@ import { useEffect } from 'react';
|
|||||||
import { VideoPlayer } from '../VideoPlayer';
|
import { VideoPlayer } from '../VideoPlayer';
|
||||||
import { type VideoPlayerEvents } from '../types/Events';
|
import { type VideoPlayerEvents } from '../types/Events';
|
||||||
|
|
||||||
type Events = keyof VideoPlayerEvents & 'onError';
|
// Omit undefined from events
|
||||||
|
type NonUndefined<T> = T extends undefined ? never : T;
|
||||||
|
|
||||||
|
// Valid events names
|
||||||
|
type Events = keyof VideoPlayerEvents | 'onError';
|
||||||
|
|
||||||
|
// Valid events params
|
||||||
|
type EventsParams<T extends Events> = T extends keyof VideoPlayerEvents
|
||||||
|
? // (Native) Events from VideoPlayerEvents
|
||||||
|
Parameters<VideoPlayerEvents[T]>
|
||||||
|
: // (JS) Events from Video Player
|
||||||
|
Parameters<NonUndefined<VideoPlayer[T]>>;
|
||||||
|
|
||||||
export const useEvent = <T extends Events>(
|
export const useEvent = <T extends Events>(
|
||||||
player: VideoPlayer,
|
player: VideoPlayer,
|
||||||
event: T,
|
event: T,
|
||||||
callback: (...args: Parameters<VideoPlayerEvents[T]>) => void
|
callback: (...args: EventsParams<T>) => void
|
||||||
) => {
|
) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// @ts-expect-error we narrow the type of the event
|
// @ts-expect-error we narrow the type of the event
|
||||||
|
|||||||
Reference in New Issue
Block a user