mirror of
https://github.com/zoriya/react-native-video.git
synced 2026-05-27 00:23:45 +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) {
|
||||
when (focusChange) {
|
||||
AudioManager.AUDIOFOCUS_GAIN -> eventEmitter?.onAudioFocusChange(true)
|
||||
AudioManager.AUDIOFOCUS_LOSS -> eventEmitter?.onAudioFocusChange(false)
|
||||
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> eventEmitter?.onAudioFocusChange(false)
|
||||
AudioManager.AUDIOFOCUS_GAIN -> eventEmitter?.onAudioFocusChange?.invoke(true)
|
||||
AudioManager.AUDIOFOCUS_LOSS -> eventEmitter?.onAudioFocusChange?.invoke(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?) {
|
||||
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
|
||||
get() = videoView.get()?.autoEnterPictureInPicture == true
|
||||
get() = videoView.get()?.autoEnterPictureInPicture
|
||||
set(value) {
|
||||
videoView.get()?.autoEnterPictureInPicture = value
|
||||
}
|
||||
@@ -69,32 +69,32 @@ class HybridVideoViewViewManager(nitroId: Int): HybridVideoViewViewManagerSpec()
|
||||
}
|
||||
|
||||
// View callbacks
|
||||
override var onPictureInPictureChange: ((Boolean) -> Unit)?
|
||||
override var onPictureInPictureChange: ((Boolean) -> Unit)? = null
|
||||
set(value) {
|
||||
field = value
|
||||
videoView.get()?.events?.onPictureInPictureChange = value
|
||||
}
|
||||
override var onFullscreenChange: ((Boolean) -> Unit)?
|
||||
override var onFullscreenChange: ((Boolean) -> Unit)? = null
|
||||
set(value) {
|
||||
field = value
|
||||
videoView.get()?.events?.onFullscreenChange = value
|
||||
}
|
||||
override var willEnterFullscreen: (() -> Unit)?
|
||||
override var willEnterFullscreen: (() -> Unit)? = null
|
||||
set(value) {
|
||||
field = value
|
||||
videoView.get()?.events?.willEnterFullscreen = value
|
||||
}
|
||||
override var willExitFullscreen: (() -> Unit)?
|
||||
override var willExitFullscreen: (() -> Unit)? = null
|
||||
set(value) {
|
||||
field = value
|
||||
videoView.get()?.events?.willExitFullscreen = value
|
||||
}
|
||||
override var willEnterPictureInPicture: (() -> Unit)?
|
||||
override var willEnterPictureInPicture: (() -> Unit)? = null
|
||||
set(value) {
|
||||
field = value
|
||||
videoView.get()?.events?.willEnterPictureInPicture = value
|
||||
}
|
||||
override var willExitPictureInPicture: (() -> Unit)?
|
||||
override var willExitPictureInPicture: (() -> Unit)? = null
|
||||
set(value) {
|
||||
field = value
|
||||
videoView.get()?.events?.willExitPictureInPicture = value
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-video",
|
||||
"version": "7.0.0-dev.6",
|
||||
"version": "7.0.0-dev.7",
|
||||
"description": "<Video /> Component for React Native",
|
||||
"source": "./src/index.tsx",
|
||||
"main": "./lib/commonjs/index.js",
|
||||
|
||||
@@ -2,12 +2,23 @@ import { useEffect } from 'react';
|
||||
import { VideoPlayer } from '../VideoPlayer';
|
||||
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>(
|
||||
player: VideoPlayer,
|
||||
event: T,
|
||||
callback: (...args: Parameters<VideoPlayerEvents[T]>) => void
|
||||
callback: (...args: EventsParams<T>) => void
|
||||
) => {
|
||||
useEffect(() => {
|
||||
// @ts-expect-error we narrow the type of the event
|
||||
|
||||
Reference in New Issue
Block a user