block global audio from screens
This commit is contained in:
@@ -8,8 +8,46 @@ import React, {
|
||||
} from "react";
|
||||
import { Platform } from "react-native";
|
||||
import { useAudioPlayer, useAudioPlayerStatus } from "expo-audio";
|
||||
import { useGlobal } from "reactn";
|
||||
|
||||
import GlobalAudioPlayer from "../components/player/GlobalAudioPlayer";
|
||||
import { Routes } from "../navigation/Routes";
|
||||
|
||||
const HIDDEN_ROUTE_NAMES = new Set([
|
||||
Routes.Writing,
|
||||
Routes.WritingLyrics,
|
||||
Routes.CreateLyricsWithAi,
|
||||
Routes.Lyrics,
|
||||
Routes.FinishedWriting,
|
||||
Routes.Studio,
|
||||
Routes.Compose,
|
||||
Routes.ComposeSong,
|
||||
Routes.CustomizeVoice,
|
||||
Routes.SongReady,
|
||||
Routes.Regenerate,
|
||||
Routes.PouchReady,
|
||||
Routes.PhotoCover,
|
||||
Routes.ValidateCover,
|
||||
Routes.FinishCompose,
|
||||
Routes.GeneratingSong,
|
||||
Routes.ProductionOnboarding,
|
||||
Routes.Production,
|
||||
Routes.DownloadSongs,
|
||||
Routes.DownloadPrices,
|
||||
Routes.SongDownloaded,
|
||||
Routes.StreamSong,
|
||||
Routes.SongRelease,
|
||||
Routes.PlaybackExample,
|
||||
Routes.PlaybackOnboarding,
|
||||
Routes.Playback,
|
||||
Routes.RecordPlayback,
|
||||
Routes.RecordedPlayback,
|
||||
Routes.ChooseDecor,
|
||||
Routes.CreatingDecor,
|
||||
Routes.VideoFinalize,
|
||||
Routes.FlowSelection,
|
||||
Routes.ChooseCoverType,
|
||||
]);
|
||||
|
||||
const noopAsync = async () => {};
|
||||
const noop = () => {};
|
||||
@@ -23,6 +61,7 @@ const DEFAULT_CONTEXT = {
|
||||
positionMs: 0,
|
||||
durationMs: 0,
|
||||
error: null,
|
||||
isPlayerVisible: true,
|
||||
play: noopAsync,
|
||||
togglePlay: noopAsync,
|
||||
pause: noopAsync,
|
||||
@@ -146,6 +185,7 @@ const normalizeTrack = (trackInput = {}, options = {}) => {
|
||||
};
|
||||
|
||||
const PlayerProvider = ({ children }) => {
|
||||
const [activeRouteName] = useGlobal("activeRouteName");
|
||||
const [currentTrack, setCurrentTrack] = useState(null);
|
||||
const [queue, setQueue] = useState([]);
|
||||
const [playback, setPlayback] = useState({
|
||||
@@ -167,6 +207,9 @@ const PlayerProvider = ({ children }) => {
|
||||
|
||||
const player = useAudioPlayer(source || null, 200);
|
||||
const status = useAudioPlayerStatus(player);
|
||||
const shouldHideOnRoute = activeRouteName
|
||||
? HIDDEN_ROUTE_NAMES.has(activeRouteName)
|
||||
: false;
|
||||
|
||||
useEffect(() => {
|
||||
if (!status) return;
|
||||
@@ -392,6 +435,7 @@ const PlayerProvider = ({ children }) => {
|
||||
positionMs: playback.positionMs,
|
||||
durationMs: playback.durationMs,
|
||||
error,
|
||||
isPlayerVisible: !shouldHideOnRoute,
|
||||
play,
|
||||
togglePlay,
|
||||
pause,
|
||||
@@ -415,6 +459,7 @@ const PlayerProvider = ({ children }) => {
|
||||
resume,
|
||||
seekBy,
|
||||
seekTo,
|
||||
shouldHideOnRoute,
|
||||
stop,
|
||||
]
|
||||
);
|
||||
@@ -422,7 +467,7 @@ const PlayerProvider = ({ children }) => {
|
||||
return (
|
||||
<PlayerContext.Provider value={contextValue}>
|
||||
{children}
|
||||
<GlobalAudioPlayer />
|
||||
{!shouldHideOnRoute && <GlobalAudioPlayer />}
|
||||
</PlayerContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ export default ({ children }) => {
|
||||
const { setIsLoading, setTooltip } = useMinuit();
|
||||
|
||||
const [pendingUserData, setPendingUserData] = useState({
|
||||
creationTimestamp: new Date(),
|
||||
createdAt: new Date(),
|
||||
});
|
||||
|
||||
const [currentUID] = useGlobal("currentUID");
|
||||
@@ -292,8 +292,8 @@ export default ({ children }) => {
|
||||
userID: dynamicUID,
|
||||
};
|
||||
|
||||
if (!cleanData?.creationTimestamp) {
|
||||
cleanData.creationTimestamp = new Date();
|
||||
if (!cleanData?.createdAt) {
|
||||
cleanData.createdAt = firebase.firestore.FieldValue.serverTimestamp();
|
||||
}
|
||||
|
||||
await usersRef.doc(dynamicUID).set(cleanData, { merge: true });
|
||||
|
||||
Reference in New Issue
Block a user