From 58cee33af7734ff649e64cf362418cf240ade114 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Fri, 20 Aug 2021 09:49:05 +0900 Subject: [PATCH] buffering icon for play buttons --- app/components/HeaderBar.tsx | 5 +++-- app/components/NowPlayingBar.tsx | 30 +++++++++++++++++++----------- app/screens/NowPlayingView.tsx | 18 +++++++++++++++++- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/app/components/HeaderBar.tsx b/app/components/HeaderBar.tsx index 9f40090..1ca4f85 100644 --- a/app/components/HeaderBar.tsx +++ b/app/components/HeaderBar.tsx @@ -14,6 +14,7 @@ import { AlbumContextPressable, NowPlayingContextPressable } from './ContextMenu export type HeaderContextItem = Song | AlbumListItem const More = React.memo<{ contextItem?: HeaderContextItem }>(({ contextItem }) => { + const moreIcon = let context: JSX.Element switch (contextItem?.itemType) { case 'song': @@ -23,7 +24,7 @@ const More = React.memo<{ contextItem?: HeaderContextItem }>(({ contextItem }) = triggerWrapperStyle={styles.icons} song={contextItem} triggerOnLongPress={false}> - + {moreIcon} ) break @@ -34,7 +35,7 @@ const More = React.memo<{ contextItem?: HeaderContextItem }>(({ contextItem }) = triggerWrapperStyle={styles.icons} album={contextItem} triggerOnLongPress={false}> - + {moreIcon} ) break diff --git a/app/components/NowPlayingBar.tsx b/app/components/NowPlayingBar.tsx index 8630f2d..2bcf9b9 100644 --- a/app/components/NowPlayingBar.tsx +++ b/app/components/NowPlayingBar.tsx @@ -6,8 +6,8 @@ import { selectTrackPlayer } from '@app/state/trackplayer' import colors from '@app/styles/colors' import font from '@app/styles/font' import { useNavigation } from '@react-navigation/native' -import React from 'react' -import { Pressable, StyleSheet, Text, View } from 'react-native' +import React, { useCallback } from 'react' +import { ActivityIndicator, Pressable, StyleSheet, Text, View } from 'react-native' import { State } from 'react-native-track-player' import IconFA5 from 'react-native-vector-icons/FontAwesome5' @@ -41,29 +41,37 @@ const progressStyles = StyleSheet.create({ }) const Controls = React.memo(() => { - const playerState = useStore(selectTrackPlayer.playerState) + const state = useStore(selectTrackPlayer.playerState) const play = usePlay() const pause = usePause() let playPauseIcon: string - let playPauseAction: () => void - - switch (playerState) { + switch (state) { case State.Playing: playPauseIcon = 'pause' - playPauseAction = pause break default: playPauseIcon = 'play' - playPauseAction = play break } + const action = useCallback(() => { + if (state === State.Playing) { + pause() + } else { + play() + } + }, [state, play, pause]) + return ( - - - + {state === State.Buffering ? ( + + ) : ( + + + + )} ) }) diff --git a/app/screens/NowPlayingView.tsx b/app/screens/NowPlayingView.tsx index d2fe590..7baeaec 100644 --- a/app/screens/NowPlayingView.tsx +++ b/app/screens/NowPlayingView.tsx @@ -15,7 +15,7 @@ import formatDuration from '@app/util/formatDuration' import Slider from '@react-native-community/slider' import { useNavigation } from '@react-navigation/native' 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 { RepeatMode, State } from 'react-native-track-player' import IconFA from 'react-native-vector-icons/FontAwesome' @@ -280,6 +280,11 @@ const PlayerControls = () => { playPauseIcon = 'pause-circle' playPauseAction = pause break + case State.Buffering: + disabled = false + playPauseIcon = 'circle' + playPauseAction = pause + break default: disabled = false playPauseIcon = 'play-circle' @@ -303,6 +308,14 @@ const PlayerControls = () => { + {state === State.Buffering && ( + + )} @@ -361,6 +374,9 @@ const controlsStyles = StyleSheet.create({ top: 26, opacity: 0, }, + buffering: { + position: 'absolute', + }, }) type RootStackParamList = {