From acc77594951d06bbc878dbe5557f8dabebd86707 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Mon, 5 Jul 2021 11:50:15 +0900 Subject: [PATCH] basic progress bar --- src/components/NowPlayingLayout.tsx | 72 +++++++++++++++++++++++++++-- src/styles/text.ts | 20 ++++---- src/util.ts | 2 +- 3 files changed, 81 insertions(+), 13 deletions(-) diff --git a/src/components/NowPlayingLayout.tsx b/src/components/NowPlayingLayout.tsx index f466838..7a45de6 100644 --- a/src/components/NowPlayingLayout.tsx +++ b/src/components/NowPlayingLayout.tsx @@ -2,9 +2,11 @@ import { useAtomValue } from 'jotai/utils' import React from 'react' import { Pressable, StatusBar, StyleSheet, Text, useWindowDimensions, View } from 'react-native' import FastImage from 'react-native-fast-image' -import TrackPlayer, { State } from 'react-native-track-player' +import TrackPlayer, { State, useProgress } from 'react-native-track-player' import { currentQueueNameAtom, currentTrackAtom, playerStateAtom } from '../state/trackplayer' -import text from '../styles/text' +import colors from '../styles/colors' +import text, { Font } from '../styles/text' +import { formatDuration } from '../util' import CoverArt from './common/CoverArt' import ImageGradientBackground from './common/ImageGradientBackground' @@ -96,6 +98,69 @@ const infoStyles = StyleSheet.create({ }, }) +const SeekBar = () => { + const { position, duration } = useProgress(250) + + let progress = 0 + if (duration > 0) { + progress = position / duration + } + + return ( + + + + + + + + {formatDuration(position)} + {formatDuration(duration)} + + + ) +} + +const seekStyles = StyleSheet.create({ + container: { + width: '100%', + marginTop: 40, + paddingHorizontal: 20, + }, + barContainer: { + flexDirection: 'row', + alignItems: 'center', + marginBottom: 6, + }, + bars: { + backgroundColor: colors.text.primary, + height: 4, + }, + barLeft: { + marginRight: -6, + }, + barRight: { + opacity: 0.3, + marginLeft: -6, + }, + indicator: { + height: 12, + width: 12, + borderRadius: 6, + backgroundColor: colors.text.primary, + elevation: 1, + }, + textContainer: { + flexDirection: 'row', + justifyContent: 'space-between', + }, + text: { + fontFamily: Font.regular, + fontSize: 15, + color: colors.text.primary, + }, +}) + const PlayerControls = () => { const state = useAtomValue(playerStateAtom) @@ -148,7 +213,7 @@ const controlsStyles = StyleSheet.create({ flexDirection: 'row', alignItems: 'center', justifyContent: 'center', - marginTop: 40, + marginTop: 10, }, skip: { height: 40, @@ -180,6 +245,7 @@ const NowPlayingLayout = () => { + ) diff --git a/src/styles/text.ts b/src/styles/text.ts index bf88119..23ef68e 100644 --- a/src/styles/text.ts +++ b/src/styles/text.ts @@ -1,12 +1,14 @@ import { TextStyle } from 'react-native' import colors from './colors' -const fontRegular = 'Metropolis-Regular' -const fontSemiBold = 'Metropolis-SemiBold' -const fontBold = 'Metropolis-Bold' +export enum Font { + regular = 'Metropolis-Regular', + semiBold = 'Metropolis-SemiBold', + bold = 'Metropolis-Bold', +} const paragraph: TextStyle = { - fontFamily: fontRegular, + fontFamily: Font.regular, fontSize: 16, color: colors.text.primary, } @@ -14,19 +16,19 @@ const paragraph: TextStyle = { const header: TextStyle = { ...paragraph, fontSize: 18, - fontFamily: fontSemiBold, + fontFamily: Font.semiBold, } const title: TextStyle = { ...paragraph, fontSize: 24, - fontFamily: fontBold, + fontFamily: Font.bold, } const itemTitle: TextStyle = { ...paragraph, fontSize: 13, - fontFamily: fontSemiBold, + fontFamily: Font.semiBold, } const itemSubtitle: TextStyle = { @@ -38,7 +40,7 @@ const itemSubtitle: TextStyle = { const songListTitle: TextStyle = { ...paragraph, fontSize: 16, - fontFamily: fontSemiBold, + fontFamily: Font.semiBold, } const songListSubtitle: TextStyle = { @@ -55,7 +57,7 @@ const xsmall: TextStyle = { const button: TextStyle = { ...paragraph, fontSize: 15, - fontFamily: fontBold, + fontFamily: Font.bold, } export default { diff --git a/src/util.ts b/src/util.ts index fe2a803..fd73faa 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,5 +1,5 @@ export function formatDuration(seconds: number): string { - const s = seconds % 60 + const s = Math.floor(seconds) % 60 const m = Math.floor(seconds / 60) % 60 const h = Math.floor(seconds / 60 / 60)