Merge pull request 'fix(mobile): animate volume and restore system overlay outside player' (#51) from t3/animate-volume-controls into main

This commit was merged in pull request #51.
This commit is contained in:
joshuafhiggins committed 2026-11-01 17:31:03 -05:00
commit 369e928bad
4 files changed
+33 -6

No files matched your search

+1
View File
@@ -392,6 +392,7 @@ export default function PlayerScreen() {
<PlayerSlider
accessibilityLabel="Volume"
commitHoldMs={0}
animateValueChanges
value={volume}
maximumValue={1}
fillColor={colors.sliderFill}
+9 -2
View File
@@ -2,6 +2,7 @@ import { useEffect, useMemo, useRef, type ReactNode } from "react"
import { StyleSheet, View } from "react-native"
import { Gesture, GestureDetector } from "react-native-gesture-handler"
import Animated, {
cancelAnimation,
interpolate,
interpolateColor,
useAnimatedStyle,
@@ -35,6 +36,7 @@ export function PlayerSlider({
trailing,
accessibilityLabel,
commitHoldMs = COMMIT_HOLD_MS,
animateValueChanges = false,
}: {
value: number
maximumValue: number
@@ -47,6 +49,7 @@ export function PlayerSlider({
leading?: ReactNode
trailing?: ReactNode
accessibilityLabel: string
animateValueChanges?: boolean
/** Seeking needs a hold while playback catches up; system volume does not. */
commitHoldMs?: number
}) {
@@ -60,8 +63,11 @@ export function PlayerSlider({
useEffect(() => {
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)
+13 -1
View File
@@ -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<VolumeEvents> {
setPlayerVisible?(visible: boolean): Promise<void>
getState(): Promise<VolumeState>
setVolume(volume: number): Promise<void>
}
@@ -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
+10 -3
View File
@@ -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)