From 5fdadfe5982e7a9c7b6c559967a3271d99f132e5 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Wed, 7 Jul 2021 21:30:28 +0900 Subject: [PATCH] close now playing on no track fix bugs caused by not queueing service commands --- src/components/NowPlayingBar.tsx | 2 +- src/components/NowPlayingLayout.tsx | 17 +++++++++++++++-- src/components/Settings.tsx | 2 +- src/components/navigation/RootNavigator.tsx | 2 +- src/playback/service.ts | 21 +++++++++++++-------- src/state/trackplayer.ts | 2 +- 6 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/components/NowPlayingBar.tsx b/src/components/NowPlayingBar.tsx index abf819f..230681b 100644 --- a/src/components/NowPlayingBar.tsx +++ b/src/components/NowPlayingBar.tsx @@ -63,7 +63,7 @@ const NowPlayingBar = () => { return ( navigation.navigate('Now Playing')} + onPress={() => navigation.navigate('NowPlaying')} style={{ ...styles.container, display: track ? 'flex' : 'none' }}> diff --git a/src/components/NowPlayingLayout.tsx b/src/components/NowPlayingLayout.tsx index b33d3d4..dfcd03a 100644 --- a/src/components/NowPlayingLayout.tsx +++ b/src/components/NowPlayingLayout.tsx @@ -1,7 +1,8 @@ import { useNavigation } from '@react-navigation/native' import { useAtomValue } from 'jotai/utils' -import React from 'react' +import React, { useEffect } from 'react' import { StatusBar, StyleSheet, Text, View } from 'react-native' +import { NativeStackScreenProps } from 'react-native-screens/lib/typescript/native-stack' import { State } from 'react-native-track-player' import IconFA from 'react-native-vector-icons/FontAwesome' import IconFA5 from 'react-native-vector-icons/FontAwesome5' @@ -296,9 +297,21 @@ const controlsStyles = StyleSheet.create({ }, }) -const NowPlayingLayout = () => { +type RootStackParamList = { + Main: undefined + NowPlaying: undefined +} +type NowPlayingProps = NativeStackScreenProps + +const NowPlayingLayout: React.FC = ({ navigation }) => { const track = useAtomValue(currentTrackAtom) + useEffect(() => { + if (!track && navigation.canGoBack()) { + navigation.popToTop() + } + }) + return ( diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx index b157f8c..acac4a9 100644 --- a/src/components/Settings.tsx +++ b/src/components/Settings.tsx @@ -19,7 +19,7 @@ const TestControls = () => { return (