Migrate SoundSlider to TypeScript. (#3227)

* Migrate `SoundSlider` to TypeScript.

* Update src/components/ObsDetailsDefaultMode/SoundContainer.tsx
This commit is contained in:
Corey Farwell
2025-11-17 18:34:13 -05:00
committed by GitHub
parent bbe646ab42
commit 84f58e6c30

View File

@@ -16,10 +16,18 @@ import AudioRecorderPlayer from "react-native-audio-recorder-player";
import { useTranslation } from "sharedHooks";
import colors from "styles/tailwindColors";
const SoundSlider = ( { playBackState, onSlidingComplete } ) => {
interface SoundSliderProps {
playBackState: {
currentPosition: number;
duration: number;
};
onSlidingComplete: ( value: number ) => void;
}
const SoundSlider = ( { playBackState, onSlidingComplete }: SoundSliderProps ) => {
const sliderStyle = {
width: "100%"
};
} as const;
return (
<Slider
style={sliderStyle}
@@ -37,12 +45,21 @@ const SoundSlider = ( { playBackState, onSlidingComplete } ) => {
);
};
interface SoundContainerProps {
autoPlay: boolean;
isVisible: boolean;
sizeClass: string;
sound: {
file_url: string;
};
}
const SoundContainer = ( {
autoPlay,
isVisible,
sizeClass,
sound
} ) => {
}: SoundContainerProps ) => {
const needsInternet = sound.file_url.includes( "https://" );
const { isConnected } = useNetInfo( );
const playerRef = useRef( new AudioRecorderPlayer( ) );
@@ -68,14 +85,14 @@ const SoundContainer = ( {
Math.floor( value / 1000 )
), [player] );
const playSound = useCallback( position => {
const playSound = useCallback( ( position?: number ) => {
async function playSoundAsync( ) {
await player.startPlayer( sound.file_url );
if ( position ) {
try {
await player.seekToPlayer( position );
} catch ( seekPlayerError ) {
if ( seekPlayerError.message.match( /Player has already stopped/ ) ) {
if ( seekPlayerError instanceof Error && seekPlayerError.message.match( /Player has already stopped/ ) ) {
// Something else might be wrong, but it's not really something to
// bother the user with
return;
@@ -110,7 +127,7 @@ const SoundContainer = ( {
try {
await player.pausePlayer( );
} catch ( pausePlayerError ) {
if ( pausePlayerError.message.match( /Player has already stopped/ ) ) {
if ( pausePlayerError instanceof Error && pausePlayerError.message.match( /Player has already stopped/ ) ) {
// Something else might be wrong, but it's not really something to
// bother the user with
return;