diff --git a/apps/mobile/app/(app)/player.tsx b/apps/mobile/app/(app)/player.tsx index fac62e7..81682e6 100644 --- a/apps/mobile/app/(app)/player.tsx +++ b/apps/mobile/app/(app)/player.tsx @@ -391,6 +391,7 @@ export default function PlayerScreen() { { if (dragging.value || Date.now() < holdUntil.current) return - fraction.value = clamp(value / max) - }, [dragging, fraction, max, value]) + const next = clamp(value / max) + fraction.value = animateValueChanges + ? withTiming(next, { duration: 160 }) + : next + }, [animateValueChanges, dragging, fraction, max, value]) const callbacks = useRef({ onValueChange, @@ -100,6 +106,7 @@ export function PlayerSlider({ active.value = withSpring(1, { duration: 250, dampingRatio: 0.8 }) }) .onStart(() => { + cancelAnimation(fraction) dragging.value = true startFraction.value = fraction.value scheduleOnRN(start) diff --git a/apps/mobile/hooks/use-system-volume.ts b/apps/mobile/hooks/use-system-volume.ts index c887719..55f6d3b 100644 --- a/apps/mobile/hooks/use-system-volume.ts +++ b/apps/mobile/hooks/use-system-volume.ts @@ -1,10 +1,12 @@ import { requireOptionalNativeModule, type EventEmitter } from "expo" +import { useFocusEffect } from "expo-router" import { useCallback, useEffect, useState } from "react" -import { AppState } from "react-native" +import { AppState, Platform } from "react-native" type VolumeState = { volume: number; available: boolean } type VolumeEvents = { onVolumeChange: (state: VolumeState) => void } interface SystemVolumeModule extends EventEmitter { + setPlayerVisible?(visible: boolean): Promise getState(): Promise setVolume(volume: number): Promise } @@ -18,6 +20,16 @@ export function useSystemVolume() { available: false, }) + useFocusEffect( + useCallback(() => { + if (Platform.OS !== "ios" || !native?.setPlayerVisible) return + void native.setPlayerVisible(true).catch(() => {}) + return () => { + void native.setPlayerVisible?.(false).catch(() => {}) + } + }, []) + ) + useEffect(() => { if (!native) return let active = true diff --git a/apps/mobile/native/SystemVolume.swift b/apps/mobile/native/SystemVolume.swift index f5a7746..529544b 100644 --- a/apps/mobile/native/SystemVolume.swift +++ b/apps/mobile/native/SystemVolume.swift @@ -13,13 +13,20 @@ final class SystemVolume: Module { Events("onVolumeChange") AsyncFunction("getState") { () -> [String: Any] in - self.prepareVolumeView() return self.state() }.runOnQueue(.main) + AsyncFunction("setPlayerVisible") { (visible: Bool) in + if visible { + self.prepareVolumeView() + } else { + self.volumeView?.removeFromSuperview() + self.volumeView = nil + } + }.runOnQueue(.main) + AsyncFunction("setVolume") { (value: Double) in - self.prepareVolumeView() - guard value.isFinite, + guard value.isFinite, self.volumeView?.window != nil, let slider = self.volumeView?.subviews.compactMap({ $0 as? UISlider }).first else { return } slider.setValue(Float(min(1, max(0, value))), animated: false)