mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-29 17:39:27 +01:00
buffering icon for play buttons
This commit is contained in:
parent
e69555f05c
commit
58cee33af7
@ -14,6 +14,7 @@ import { AlbumContextPressable, NowPlayingContextPressable } from './ContextMenu
|
|||||||
export type HeaderContextItem = Song | AlbumListItem
|
export type HeaderContextItem = Song | AlbumListItem
|
||||||
|
|
||||||
const More = React.memo<{ contextItem?: HeaderContextItem }>(({ contextItem }) => {
|
const More = React.memo<{ contextItem?: HeaderContextItem }>(({ contextItem }) => {
|
||||||
|
const moreIcon = <IconMat name="more-vert" color="white" size={25} />
|
||||||
let context: JSX.Element
|
let context: JSX.Element
|
||||||
switch (contextItem?.itemType) {
|
switch (contextItem?.itemType) {
|
||||||
case 'song':
|
case 'song':
|
||||||
@ -23,7 +24,7 @@ const More = React.memo<{ contextItem?: HeaderContextItem }>(({ contextItem }) =
|
|||||||
triggerWrapperStyle={styles.icons}
|
triggerWrapperStyle={styles.icons}
|
||||||
song={contextItem}
|
song={contextItem}
|
||||||
triggerOnLongPress={false}>
|
triggerOnLongPress={false}>
|
||||||
<IconMat name="more-vert" color="white" size={25} />
|
{moreIcon}
|
||||||
</NowPlayingContextPressable>
|
</NowPlayingContextPressable>
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
@ -34,7 +35,7 @@ const More = React.memo<{ contextItem?: HeaderContextItem }>(({ contextItem }) =
|
|||||||
triggerWrapperStyle={styles.icons}
|
triggerWrapperStyle={styles.icons}
|
||||||
album={contextItem}
|
album={contextItem}
|
||||||
triggerOnLongPress={false}>
|
triggerOnLongPress={false}>
|
||||||
<IconMat name="more-vert" color="white" size={25} />
|
{moreIcon}
|
||||||
</AlbumContextPressable>
|
</AlbumContextPressable>
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
|
|||||||
@ -6,8 +6,8 @@ import { selectTrackPlayer } from '@app/state/trackplayer'
|
|||||||
import colors from '@app/styles/colors'
|
import colors from '@app/styles/colors'
|
||||||
import font from '@app/styles/font'
|
import font from '@app/styles/font'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
import React from 'react'
|
import React, { useCallback } from 'react'
|
||||||
import { Pressable, StyleSheet, Text, View } from 'react-native'
|
import { ActivityIndicator, Pressable, StyleSheet, Text, View } from 'react-native'
|
||||||
import { State } from 'react-native-track-player'
|
import { State } from 'react-native-track-player'
|
||||||
import IconFA5 from 'react-native-vector-icons/FontAwesome5'
|
import IconFA5 from 'react-native-vector-icons/FontAwesome5'
|
||||||
|
|
||||||
@ -41,29 +41,37 @@ const progressStyles = StyleSheet.create({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const Controls = React.memo(() => {
|
const Controls = React.memo(() => {
|
||||||
const playerState = useStore(selectTrackPlayer.playerState)
|
const state = useStore(selectTrackPlayer.playerState)
|
||||||
const play = usePlay()
|
const play = usePlay()
|
||||||
const pause = usePause()
|
const pause = usePause()
|
||||||
|
|
||||||
let playPauseIcon: string
|
let playPauseIcon: string
|
||||||
let playPauseAction: () => void
|
switch (state) {
|
||||||
|
|
||||||
switch (playerState) {
|
|
||||||
case State.Playing:
|
case State.Playing:
|
||||||
playPauseIcon = 'pause'
|
playPauseIcon = 'pause'
|
||||||
playPauseAction = pause
|
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
playPauseIcon = 'play'
|
playPauseIcon = 'play'
|
||||||
playPauseAction = play
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const action = useCallback(() => {
|
||||||
|
if (state === State.Playing) {
|
||||||
|
pause()
|
||||||
|
} else {
|
||||||
|
play()
|
||||||
|
}
|
||||||
|
}, [state, play, pause])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.controls}>
|
<View style={styles.controls}>
|
||||||
<PressableOpacity onPress={playPauseAction} hitSlop={14}>
|
{state === State.Buffering ? (
|
||||||
|
<ActivityIndicator color="white" size="large" animating={true} />
|
||||||
|
) : (
|
||||||
|
<PressableOpacity onPress={action} hitSlop={14}>
|
||||||
<IconFA5 name={playPauseIcon} size={28} color="white" />
|
<IconFA5 name={playPauseIcon} size={28} color="white" />
|
||||||
</PressableOpacity>
|
</PressableOpacity>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -15,7 +15,7 @@ import formatDuration from '@app/util/formatDuration'
|
|||||||
import Slider from '@react-native-community/slider'
|
import Slider from '@react-native-community/slider'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
import React, { useCallback, useEffect, useState } from 'react'
|
import React, { useCallback, useEffect, useState } from 'react'
|
||||||
import { StyleSheet, Text, View } from 'react-native'
|
import { ActivityIndicator, StyleSheet, Text, View } from 'react-native'
|
||||||
import { NativeStackScreenProps } from 'react-native-screens/native-stack'
|
import { NativeStackScreenProps } from 'react-native-screens/native-stack'
|
||||||
import { RepeatMode, State } from 'react-native-track-player'
|
import { RepeatMode, State } from 'react-native-track-player'
|
||||||
import IconFA from 'react-native-vector-icons/FontAwesome'
|
import IconFA from 'react-native-vector-icons/FontAwesome'
|
||||||
@ -280,6 +280,11 @@ const PlayerControls = () => {
|
|||||||
playPauseIcon = 'pause-circle'
|
playPauseIcon = 'pause-circle'
|
||||||
playPauseAction = pause
|
playPauseAction = pause
|
||||||
break
|
break
|
||||||
|
case State.Buffering:
|
||||||
|
disabled = false
|
||||||
|
playPauseIcon = 'circle'
|
||||||
|
playPauseAction = pause
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
disabled = false
|
disabled = false
|
||||||
playPauseIcon = 'play-circle'
|
playPauseIcon = 'play-circle'
|
||||||
@ -303,6 +308,14 @@ const PlayerControls = () => {
|
|||||||
</PressableOpacity>
|
</PressableOpacity>
|
||||||
<PressableOpacity onPress={playPauseAction} disabled={disabled} style={controlsStyles.play}>
|
<PressableOpacity onPress={playPauseAction} disabled={disabled} style={controlsStyles.play}>
|
||||||
<IconFA name={playPauseIcon} size={82} color="white" />
|
<IconFA name={playPauseIcon} size={82} color="white" />
|
||||||
|
{state === State.Buffering && (
|
||||||
|
<ActivityIndicator
|
||||||
|
style={controlsStyles.buffering}
|
||||||
|
color={colors.gradient.low}
|
||||||
|
size="large"
|
||||||
|
animating={true}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</PressableOpacity>
|
</PressableOpacity>
|
||||||
<PressableOpacity onPress={next} disabled={disabled}>
|
<PressableOpacity onPress={next} disabled={disabled}>
|
||||||
<IconFA5 name="step-forward" size={36} color="white" />
|
<IconFA5 name="step-forward" size={36} color="white" />
|
||||||
@ -361,6 +374,9 @@ const controlsStyles = StyleSheet.create({
|
|||||||
top: 26,
|
top: 26,
|
||||||
opacity: 0,
|
opacity: 0,
|
||||||
},
|
},
|
||||||
|
buffering: {
|
||||||
|
position: 'absolute',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
type RootStackParamList = {
|
type RootStackParamList = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user