mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-28 17:19:27 +01:00
move header into its own component
This commit is contained in:
parent
16b753e2bb
commit
187cce16d9
79
app/components/HeaderBar.tsx
Normal file
79
app/components/HeaderBar.tsx
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
import colors from '@app/styles/colors'
|
||||||
|
import dimensions from '@app/styles/dimensions'
|
||||||
|
import font from '@app/styles/font'
|
||||||
|
import { useNavigation } from '@react-navigation/core'
|
||||||
|
import React, { useCallback } from 'react'
|
||||||
|
import { View, StatusBar, Text, StyleSheet, ViewStyle } from 'react-native'
|
||||||
|
import Animated from 'react-native-reanimated'
|
||||||
|
import PressableOpacity from './PressableOpacity'
|
||||||
|
import IconMat from 'react-native-vector-icons/MaterialIcons'
|
||||||
|
import { ReactComponentLike } from 'prop-types'
|
||||||
|
|
||||||
|
const HeaderBar = React.memo<{
|
||||||
|
title?: string
|
||||||
|
headerStyle?: Animated.AnimatedStyleProp<ViewStyle> | Animated.AnimatedStyleProp<ViewStyle>[]
|
||||||
|
HeaderCenter?: ReactComponentLike
|
||||||
|
onMore?: () => void
|
||||||
|
}>(({ title, headerStyle, HeaderCenter, onMore }) => {
|
||||||
|
const navigation = useNavigation()
|
||||||
|
|
||||||
|
const back = useCallback(() => {
|
||||||
|
navigation.goBack()
|
||||||
|
}, [navigation])
|
||||||
|
|
||||||
|
const _headerStyle = Array.isArray(headerStyle) ? headerStyle : [headerStyle]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Animated.View style={[styles.container, ..._headerStyle]}>
|
||||||
|
<PressableOpacity onPress={back} style={styles.icons} ripple={true}>
|
||||||
|
<IconMat name="arrow-back" color="white" size={25} />
|
||||||
|
</PressableOpacity>
|
||||||
|
<View style={styles.center}>
|
||||||
|
{HeaderCenter ? (
|
||||||
|
<HeaderCenter />
|
||||||
|
) : (
|
||||||
|
<Text numberOfLines={1} style={styles.title}>
|
||||||
|
{title}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
{onMore ? (
|
||||||
|
<PressableOpacity style={styles.icons} ripple={true} onPress={onMore}>
|
||||||
|
<IconMat name="more-vert" color="white" size={25} />
|
||||||
|
</PressableOpacity>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
|
</Animated.View>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
height: dimensions.top(),
|
||||||
|
paddingTop: StatusBar.currentHeight,
|
||||||
|
backgroundColor: colors.gradient.high,
|
||||||
|
width: '100%',
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
},
|
||||||
|
icons: {
|
||||||
|
height: 42,
|
||||||
|
width: 42,
|
||||||
|
marginHorizontal: 8,
|
||||||
|
},
|
||||||
|
center: {
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
fontFamily: font.semiBold,
|
||||||
|
fontSize: 18,
|
||||||
|
color: colors.text.primary,
|
||||||
|
flex: 1,
|
||||||
|
textAlignVertical: 'center',
|
||||||
|
paddingLeft: 14,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default HeaderBar
|
||||||
@ -3,8 +3,8 @@ import CoverArt from '@app/components/CoverArt'
|
|||||||
import GradientBackground from '@app/components/GradientBackground'
|
import GradientBackground from '@app/components/GradientBackground'
|
||||||
import GradientScrollView from '@app/components/GradientScrollView'
|
import GradientScrollView from '@app/components/GradientScrollView'
|
||||||
import Header from '@app/components/Header'
|
import Header from '@app/components/Header'
|
||||||
|
import HeaderBar from '@app/components/HeaderBar'
|
||||||
import ListItem from '@app/components/ListItem'
|
import ListItem from '@app/components/ListItem'
|
||||||
import PressableOpacity from '@app/components/PressableOpacity'
|
|
||||||
import { useArtistInfo } from '@app/hooks/music'
|
import { useArtistInfo } from '@app/hooks/music'
|
||||||
import { useSetQueue } from '@app/hooks/trackplayer'
|
import { useSetQueue } from '@app/hooks/trackplayer'
|
||||||
import { Album, Song } from '@app/models/music'
|
import { Album, Song } from '@app/models/music'
|
||||||
@ -13,11 +13,10 @@ import dimensions from '@app/styles/dimensions'
|
|||||||
import font from '@app/styles/font'
|
import font from '@app/styles/font'
|
||||||
import { useLayout } from '@react-native-community/hooks'
|
import { useLayout } from '@react-native-community/hooks'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
import React, { useCallback } from 'react'
|
import React from 'react'
|
||||||
import { ActivityIndicator, StatusBar, StyleSheet, Text, View } from 'react-native'
|
import { ActivityIndicator, StyleSheet, Text, View } from 'react-native'
|
||||||
import FastImage from 'react-native-fast-image'
|
import FastImage from 'react-native-fast-image'
|
||||||
import Animated, { useAnimatedScrollHandler, useAnimatedStyle, useSharedValue } from 'react-native-reanimated'
|
import { useAnimatedScrollHandler, useAnimatedStyle, useSharedValue } from 'react-native-reanimated'
|
||||||
import IconMat from 'react-native-vector-icons/MaterialIcons'
|
|
||||||
|
|
||||||
const AlbumItem = React.memo<{
|
const AlbumItem = React.memo<{
|
||||||
album: Album
|
album: Album
|
||||||
@ -74,62 +73,6 @@ const ArtistDetailsFallback = React.memo(() => (
|
|||||||
</GradientBackground>
|
</GradientBackground>
|
||||||
))
|
))
|
||||||
|
|
||||||
const NowPlayingHeader = React.memo<{ title: string; animatedOpacity: { opacity: number } }>(
|
|
||||||
({ title, animatedOpacity }) => {
|
|
||||||
const navigation = useNavigation()
|
|
||||||
|
|
||||||
const back = useCallback(() => {
|
|
||||||
navigation.goBack()
|
|
||||||
}, [navigation])
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Animated.View style={[headerStyles.container, animatedOpacity]}>
|
|
||||||
<PressableOpacity onPress={back} style={headerStyles.icons} ripple={true}>
|
|
||||||
<IconMat name="arrow-back" color="white" size={25} />
|
|
||||||
</PressableOpacity>
|
|
||||||
<View style={headerStyles.center}>
|
|
||||||
<Text numberOfLines={1} style={headerStyles.queueName}>
|
|
||||||
{title}
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
{/* <PressableOpacity style={headerStyles.icons} ripple={true}>
|
|
||||||
<IconMat name="more-vert" color="white" size={25} />
|
|
||||||
</PressableOpacity> */}
|
|
||||||
</Animated.View>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
const headerStyles = StyleSheet.create({
|
|
||||||
container: {
|
|
||||||
height: dimensions.top(),
|
|
||||||
paddingTop: StatusBar.currentHeight,
|
|
||||||
backgroundColor: colors.gradient.high,
|
|
||||||
width: '100%',
|
|
||||||
position: 'absolute',
|
|
||||||
zIndex: 1,
|
|
||||||
flexDirection: 'row',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
},
|
|
||||||
icons: {
|
|
||||||
height: 42,
|
|
||||||
width: 42,
|
|
||||||
marginHorizontal: 8,
|
|
||||||
},
|
|
||||||
center: {
|
|
||||||
flex: 1,
|
|
||||||
},
|
|
||||||
queueName: {
|
|
||||||
fontFamily: font.semiBold,
|
|
||||||
fontSize: 18,
|
|
||||||
color: colors.text.primary,
|
|
||||||
flex: 1,
|
|
||||||
textAlignVertical: 'center',
|
|
||||||
paddingLeft: 14,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const ArtistView = React.memo<{ id: string; title: string }>(({ id, title }) => {
|
const ArtistView = React.memo<{ id: string; title: string }>(({ id, title }) => {
|
||||||
const artist = useArtistInfo(id)
|
const artist = useArtistInfo(id)
|
||||||
const albumsLayout = useLayout()
|
const albumsLayout = useLayout()
|
||||||
@ -160,7 +103,7 @@ const ArtistView = React.memo<{ id: string; title: string }>(({ id, title }) =>
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<View style={{ flex: 1 }}>
|
||||||
<NowPlayingHeader title={title} animatedOpacity={animatedOpacity} />
|
<HeaderBar title={title} headerStyle={[styles.header, animatedOpacity]} />
|
||||||
<GradientScrollView
|
<GradientScrollView
|
||||||
onLayout={coverLayout.onLayout}
|
onLayout={coverLayout.onLayout}
|
||||||
offset={artistCoverHeight}
|
offset={artistCoverHeight}
|
||||||
@ -198,13 +141,9 @@ const ArtistView = React.memo<{ id: string; title: string }>(({ id, title }) =>
|
|||||||
const artistCoverHeight = 350
|
const artistCoverHeight = 350
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
headerText: {
|
header: {
|
||||||
flex: 1,
|
position: 'absolute',
|
||||||
textAlign: 'center',
|
zIndex: 1,
|
||||||
textAlignVertical: 'center',
|
|
||||||
fontFamily: font.semiBold,
|
|
||||||
fontSize: 22,
|
|
||||||
color: colors.text.primary,
|
|
||||||
},
|
},
|
||||||
scroll: {
|
scroll: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import CoverArt from '@app/components/CoverArt'
|
import CoverArt from '@app/components/CoverArt'
|
||||||
|
import HeaderBar from '@app/components/HeaderBar'
|
||||||
import ImageGradientBackground from '@app/components/ImageGradientBackground'
|
import ImageGradientBackground from '@app/components/ImageGradientBackground'
|
||||||
import PressableOpacity from '@app/components/PressableOpacity'
|
import PressableOpacity from '@app/components/PressableOpacity'
|
||||||
import Star from '@app/components/Star'
|
import Star from '@app/components/Star'
|
||||||
@ -16,20 +17,18 @@ import { selectMusic } from '@app/state/music'
|
|||||||
import { useStore } from '@app/state/store'
|
import { useStore } from '@app/state/store'
|
||||||
import { QueueContextType, selectTrackPlayer } from '@app/state/trackplayer'
|
import { QueueContextType, selectTrackPlayer } from '@app/state/trackplayer'
|
||||||
import colors from '@app/styles/colors'
|
import colors from '@app/styles/colors'
|
||||||
import dimensions from '@app/styles/dimensions'
|
|
||||||
import font from '@app/styles/font'
|
import font from '@app/styles/font'
|
||||||
import formatDuration from '@app/util/formatDuration'
|
import formatDuration from '@app/util/formatDuration'
|
||||||
|
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 { StatusBar, StyleSheet, Text, View } from 'react-native'
|
import { 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'
|
||||||
import IconFA5 from 'react-native-vector-icons/FontAwesome5'
|
import IconFA5 from 'react-native-vector-icons/FontAwesome5'
|
||||||
import Icon from 'react-native-vector-icons/Ionicons'
|
import Icon from 'react-native-vector-icons/Ionicons'
|
||||||
import IconMatCom from 'react-native-vector-icons/MaterialCommunityIcons'
|
import IconMatCom from 'react-native-vector-icons/MaterialCommunityIcons'
|
||||||
import IconMat from 'react-native-vector-icons/MaterialIcons'
|
|
||||||
import Slider from '@react-native-community/slider'
|
|
||||||
|
|
||||||
function getContextName(type?: QueueContextType) {
|
function getContextName(type?: QueueContextType) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -54,10 +53,6 @@ const NowPlayingHeader = React.memo(() => {
|
|||||||
|
|
||||||
let contextName = getContextName(queueContextType)
|
let contextName = getContextName(queueContextType)
|
||||||
|
|
||||||
const back = useCallback(() => {
|
|
||||||
navigation.navigate('top')
|
|
||||||
}, [navigation])
|
|
||||||
|
|
||||||
const goToContext = useCallback(() => {
|
const goToContext = useCallback(() => {
|
||||||
if (!queueContextType || !queueContextId || queueContextType === 'song') {
|
if (!queueContextType || !queueContextId || queueContextType === 'song') {
|
||||||
return
|
return
|
||||||
@ -67,61 +62,42 @@ const NowPlayingHeader = React.memo(() => {
|
|||||||
}, [navigation, queueContextId, queueContextType, queueName])
|
}, [navigation, queueContextId, queueContextType, queueName])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={headerStyles.container}>
|
<HeaderBar
|
||||||
<PressableOpacity onPress={back} style={headerStyles.icons} ripple={true}>
|
headerStyle={{ backgroundColor: 'transparent' }}
|
||||||
<IconMat name="arrow-back" color="white" size={25} />
|
onMore={goToContext}
|
||||||
</PressableOpacity>
|
HeaderCenter={() => (
|
||||||
<View style={headerStyles.center}>
|
<View style={headerStyles.center}>
|
||||||
{contextName ? (
|
{contextName ? (
|
||||||
<Text numberOfLines={1} style={headerStyles.queueType}>
|
<Text numberOfLines={1} style={headerStyles.queueType}>
|
||||||
{contextName}
|
{contextName}
|
||||||
|
</Text>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
|
<Text numberOfLines={1} style={headerStyles.queueName}>
|
||||||
|
{queueName || 'Nothing playing...'}
|
||||||
</Text>
|
</Text>
|
||||||
) : (
|
</View>
|
||||||
<></>
|
)}
|
||||||
)}
|
/>
|
||||||
<Text numberOfLines={1} style={headerStyles.queueName}>
|
|
||||||
{queueName || 'Nothing playing...'}
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
<PressableOpacity
|
|
||||||
onPress={goToContext}
|
|
||||||
style={headerStyles.icons}
|
|
||||||
disabled={queueContextType === 'song'}
|
|
||||||
ripple={true}>
|
|
||||||
<IconMat name="more-vert" color="white" size={25} />
|
|
||||||
</PressableOpacity>
|
|
||||||
</View>
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const headerStyles = StyleSheet.create({
|
const headerStyles = StyleSheet.create({
|
||||||
container: {
|
|
||||||
height: dimensions.header,
|
|
||||||
width: '100%',
|
|
||||||
flexDirection: 'row',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
},
|
|
||||||
icons: {
|
|
||||||
height: 42,
|
|
||||||
width: 42,
|
|
||||||
marginHorizontal: 8,
|
|
||||||
},
|
|
||||||
center: {
|
center: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
justifyContent: 'center',
|
||||||
},
|
},
|
||||||
queueType: {
|
queueType: {
|
||||||
fontFamily: font.regular,
|
fontFamily: font.regular,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: colors.text.primary,
|
color: colors.text.primary,
|
||||||
// flex: 1,
|
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
},
|
},
|
||||||
queueName: {
|
queueName: {
|
||||||
fontFamily: font.bold,
|
fontFamily: font.bold,
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
color: colors.text.primary,
|
color: colors.text.primary,
|
||||||
// flex: 1,
|
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -431,7 +407,7 @@ const NowPlayingView: React.FC<NowPlayingProps> = ({ navigation }) => {
|
|||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
paddingTop: StatusBar.currentHeight,
|
// paddingTop: StatusBar.currentHeight,
|
||||||
},
|
},
|
||||||
content: {
|
content: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user