add navigation focus to AudioPlayer component and fix the jest
This commit is contained in:
parent
5625d5311b
commit
c157552bfb
|
@ -3,6 +3,7 @@ import { View } from 'react-native';
|
|||
import { AVPlaybackStatus } from 'expo-av';
|
||||
import { activateKeepAwake, deactivateKeepAwake } from 'expo-keep-awake';
|
||||
import { useSharedValue } from 'react-native-reanimated';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
|
||||
import { useTheme } from '../../theme';
|
||||
import styles from './styles';
|
||||
|
@ -36,6 +37,8 @@ const AudioPlayer = ({
|
|||
|
||||
const audioUri = useRef<string>('');
|
||||
|
||||
const navigation = useNavigation();
|
||||
|
||||
const onPlaybackStatusUpdate = (status: AVPlaybackStatus) => {
|
||||
if (status) {
|
||||
onPlaying(status);
|
||||
|
@ -124,6 +127,16 @@ const AudioPlayer = ({
|
|||
}
|
||||
}, [paused]);
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribeFocus = navigation.addListener('focus', () => {
|
||||
audioPlayer.setOnPlaybackStatusUpdate(audioUri.current, onPlaybackStatusUpdate);
|
||||
});
|
||||
|
||||
return () => {
|
||||
unsubscribeFocus();
|
||||
};
|
||||
}, [navigation]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<View style={[styles.audioContainer, { backgroundColor: colors.surfaceTint, borderColor: colors.strokeExtraLight }]}>
|
||||
|
|
|
@ -32,7 +32,15 @@ const mockedNavigate = jest.fn();
|
|||
|
||||
jest.mock('@react-navigation/native', () => ({
|
||||
...jest.requireActual('@react-navigation/native'),
|
||||
useNavigation: () => mockedNavigate
|
||||
useNavigation: () => ({
|
||||
navigate: jest.fn(),
|
||||
addListener: jest.fn().mockImplementation((event, callback) => {
|
||||
callback();
|
||||
return {
|
||||
remove: jest.fn()
|
||||
};
|
||||
})
|
||||
})
|
||||
}));
|
||||
|
||||
jest.mock('react-native-notifications', () => ({
|
||||
|
|
Loading…
Reference in New Issue