Skip to content

Commit

Permalink
Merge pull request TheWidlarzGroup#5 from laftel-team/fix/unsupported…
Browse files Browse the repository at this point in the history
…-types

fix unsupported codgen type
  • Loading branch information
jiyong1 authored May 2, 2023
2 parents bdcc940 + d6e4de7 commit 5847809
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 16 deletions.
40 changes: 35 additions & 5 deletions src/MyVideo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Image,
Platform,
} from "react-native";
import RNCVideoComponent, { Commands, OnAudioFocusChangedData, OnPlaybackStateChangedData, OnVideoErrorData } from "./fabric/VideoNativeComponent";
import RNCVideoComponent, { Commands, OnAudioFocusChangedData, OnAudioTracksData, OnPlaybackStateChangedData, OnTextTracksData, OnTimedMetadataData, OnVideoErrorData, OnVideoTracksData } from "./fabric/VideoNativeComponent";

import type { StyleProp, ImageStyle, NativeSyntheticEvent } from "react-native";
import type {
Expand Down Expand Up @@ -60,7 +60,6 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
onEnd,
onBuffer,
onBandwidthUpdate,
onTimedMetadata,
onExternalPlaybackChange,
onFullscreenPlayerWillPresent,
onFullscreenPlayerDidPresent,
Expand All @@ -75,6 +74,11 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
onPlaybackStateChanged,
onAudioFocusChanged,
onIdle,
// @todo: fix type
onTimedMetadata,
onAudioTracks,
onTextTracks,
onVideoTracks,
...rest
},
ref
Expand Down Expand Up @@ -239,12 +243,27 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(

/** @todo: fix type */
const _onTimedMetadata = useCallback(
() => {
onTimedMetadata?.();
(e: NativeSyntheticEvent<OnTimedMetadataData>) => {
onTimedMetadata?.(e.nativeEvent);
},
[onTimedMetadata]
);

/** @todo: fix type */
const _onAudioTracks = useCallback((e: NativeSyntheticEvent<OnAudioTracksData>) => {
onAudioTracks?.(e.nativeEvent)
}, [onAudioTracks])

/** @todo: fix type */
const _onTextTracks = useCallback((e: NativeSyntheticEvent<OnTextTracksData>) => {
onTextTracks?.(e.nativeEvent)
}, [onAudioTracks])

/** @todo: fix type */
const _onVideoTracks = useCallback((e: NativeSyntheticEvent<OnVideoTracksData>) => {
onVideoTracks?.(e.nativeEvent)
}, [onAudioTracks])

const _onPlaybackRateChange = useCallback(
(e: NativeSyntheticEvent<Readonly<{ playbackRate: number }>>) => {
onPlaybackRateChange?.(e.nativeEvent);
Expand Down Expand Up @@ -352,7 +371,18 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
onVideoBuffer={onVideoBuffer}
onVideoPlaybackStateChanged={onVideoPlaybackStateChanged}
onBandwidthUpdate={_onBandwidthUpdate}
onTimedMetadata={_onTimedMetadata}
onTimedMetadata={(e) => {
_onTimedMetadata(e as NativeSyntheticEvent<OnTimedMetadataData>)
}}
onAudioTracks={(e) => {
_onAudioTracks(e as NativeSyntheticEvent<OnAudioTracksData>)
}}
onTextTracks={(e) => {
_onTextTracks(e as NativeSyntheticEvent<OnTextTracksData>)
}}
onVideoTracks={(e) => {
_onVideoTracks(e as NativeSyntheticEvent<OnVideoTracksData>)
}}
onVideoFullscreenPlayerDidDismiss={onFullscreenPlayerDidDismiss}
onVideoFullscreenPlayerDidPresent={onFullscreenPlayerDidPresent}
onVideoFullscreenPlayerWillDismiss={onFullscreenPlayerWillDismiss}
Expand Down
59 changes: 53 additions & 6 deletions src/fabric/VideoNativeComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,55 @@ export type OnPlaybackStateChangedData = Readonly<{
isPlaying: boolean;
}>

export type OnTimedMetadataData = Readonly<{}>
// @todo: fix type. for now react native doesn't support array codegen type for native event
type _OnTimedMetadataData = Readonly<{}>
export type OnTimedMetadataData = Readonly<{
metadata: ReadonlyArray<Readonly<{
value?: string
identifier?: string
}>>
}>

// @todo: fix type. for now react native doesn't support array codegen type for native event
type _OnAudioTracksData = Readonly<{}>
export type OnAudioTracksData = Readonly<{
audioTracks: ReadonlyArray<Readonly<{
index?: Int32
title?: string
language?: string
bitrate?: Float
type?: string
selected?: boolean
}>>
}>

// @todo: fix type. for now react native doesn't support array codegen type for native event
type _OnTextTracksData = Readonly<{}>
export type OnTextTracksData = Readonly<{
textTracks: ReadonlyArray<Readonly<{
index?: Int32
title?: string
language?: string
/**
* iOS only supports VTT, Android supports all 3
*/
type?: 'srt' | 'ttml' | 'vtt'
selected?: boolean
}>>
}>

// @todo: fix type. for now react native doesn't support array codegen type for native event
type _OnVideoTracksData = Readonly<{}>
export type OnVideoTracksData = Readonly<{
videoTracks: ReadonlyArray<Readonly<{
trackId?: Int32
codecs?: string
width?: Float
height?: Float
bitrate?: Float
selected?: boolean
}>>
}>

export type OnPlaybackData = Readonly<{
playbackRate: Float;
Expand Down Expand Up @@ -228,7 +276,6 @@ export interface VideoNativeProps extends ViewProps {
onBandwidthUpdate?: DirectEventHandler<OnBandwidthUpdateData>
onVideoSeek?: DirectEventHandler<OnSeekData>;
onVideoEnd?: DirectEventHandler<Readonly<{}>>; // all
onTimedMetadata?: DirectEventHandler<OnTimedMetadataData>; // ios, android
onVideoAudioBecomingNoisy?: DirectEventHandler<Readonly<{}>>;
onVideoFullscreenPlayerWillPresent?: DirectEventHandler<Readonly<{}>>; // ios, android
onVideoFullscreenPlayerDidPresent?: DirectEventHandler<Readonly<{}>>; // ios, android
Expand All @@ -245,10 +292,10 @@ export interface VideoNativeProps extends ViewProps {
onVideoIdle?: DirectEventHandler<{}>; // android only (nowhere in document, so do not use as props. just type declaration)
onAudioFocusChanged?: DirectEventHandler<OnAudioFocusChangedData>; // android only (nowhere in document, so do not use as props. just type declaration)
// @todo: fix type
// onAudioTracks: DirectEventHandler<any>; // android
// onTextTracks: DirectEventHandler<any>; // android
// onVideoTracks: DirectEventHandler<any>; // android
// onTimedMetadata: DirectEventHandler<any>; // android
onTimedMetadata?: DirectEventHandler<_OnTimedMetadataData>; // ios, android
onAudioTracks: DirectEventHandler<_OnAudioTracksData>; // android
onTextTracks: DirectEventHandler<_OnTextTracksData>; // android
onVideoTracks: DirectEventHandler<_OnVideoTracksData>; // android
}

export type VideoComponentType = HostComponent<VideoNativeProps>
Expand Down
10 changes: 5 additions & 5 deletions src/types/events.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { OnBandwidthUpdateData, OnBufferData, OnLoadData, OnLoadStartData, OnProgressData, OnSeekData, OnPlaybackData, OnExternalPlaybackChangeData, OnPictureInPictureStatusChangedData, OnReceiveAdEventData, OnVideoErrorData, OnPlaybackStateChangedData, OnAudioFocusChangedData } from "src/fabric/VideoNativeComponent";
import type { OnBandwidthUpdateData, OnBufferData, OnLoadData, OnLoadStartData, OnProgressData, OnSeekData, OnPlaybackData, OnExternalPlaybackChangeData, OnPictureInPictureStatusChangedData, OnReceiveAdEventData, OnVideoErrorData, OnPlaybackStateChangedData, OnAudioFocusChangedData, OnTimedMetadataData, OnAudioTracksData, OnTextTracksData, OnVideoTracksData } from 'src/fabric/VideoNativeComponent';

export interface ReactVideoEvents {
onAudioBecomingNoisy?: () => void //Android, iOS
onAudioTracks?: () => void // Android
onAudioFocusChanged?: (e: OnAudioFocusChangedData) => void // Android
onIdle?: () => void // Android
onBandwidthUpdate?: (e: OnBandwidthUpdateData) => void //Android
Expand All @@ -25,7 +24,8 @@ export interface ReactVideoEvents {
onSeek?: (e: OnSeekData) => void //Android, iOS, Windows UWP
onPlaybackStateChanged?: (e: OnPlaybackStateChangedData) => void // Android
// @todo: fix type
onTimedMetadata?: () => void //Android, iOS
onTextTracks?: () => void //Android
onVideoTracks?: () => void //Android
onTimedMetadata?: (e: OnTimedMetadataData) => void //Android, iOS
onAudioTracks?: (e: OnAudioTracksData) => void // Android
onTextTracks?: (e: OnTextTracksData) => void //Android
onVideoTracks?: (e: OnVideoTracksData) => void //Android
}

0 comments on commit 5847809

Please sign in to comment.