refactored text styles, not enough shared

This commit is contained in:
austinried
2021-07-08 17:56:05 +09:00
parent 3460b4014f
commit fe92c63a60
16 changed files with 358 additions and 346 deletions

View File

@@ -1,13 +1,13 @@
import { useNavigation } from '@react-navigation/native'
import { useAtomValue } from 'jotai/utils'
import React, { useEffect } from 'react'
import { ActivityIndicator, GestureResponderEvent, StyleSheet, Text, useWindowDimensions, View } from 'react-native'
import { ActivityIndicator, GestureResponderEvent, StyleSheet, Text, View } from 'react-native'
import IconFA from 'react-native-vector-icons/FontAwesome'
import IconMat from 'react-native-vector-icons/MaterialIcons'
import { albumAtomFamily } from '@app/state/music'
import { currentTrackAtom, useSetQueue } from '@app/state/trackplayer'
import colors from '@app/styles/colors'
import text, { Font } from '@app/styles/text'
import font from '@app/styles/font'
import AlbumArt from '@app/components/AlbumArt'
import Button from '@app/components/Button'
import GradientBackground from '@app/components/GradientBackground'
@@ -46,7 +46,6 @@ const SongItem: React.FC<{
const songStyles = StyleSheet.create({
container: {
marginTop: 20,
marginLeft: 10,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
@@ -54,14 +53,15 @@ const songStyles = StyleSheet.create({
text: {
flex: 1,
alignItems: 'flex-start',
width: 100,
},
title: {
fontSize: 16,
fontFamily: Font.semiBold,
fontFamily: font.semiBold,
},
subtitle: {
fontSize: 14,
fontFamily: Font.regular,
fontFamily: font.regular,
color: colors.text.secondary,
},
controls: {
@@ -78,101 +78,59 @@ const AlbumDetails: React.FC<{
id: string
}> = ({ id }) => {
const album = useAtomValue(albumAtomFamily(id))
const layout = useWindowDimensions()
const setQueue = useSetQueue()
const coverSize = layout.width - layout.width / 2.5
if (!album) {
return <Text style={text.paragraph}>No Album</Text>
return <></>
}
return (
<ImageGradientScrollView
imageUri={album.coverArtThumbUri}
imageKey={`${album.name}${album.artist}`}
style={{
flex: 1,
}}
contentContainerStyle={{
alignItems: 'center',
paddingTop: coverSize / 8,
}}>
<AlbumArt id={album.id} height={coverSize} width={coverSize} />
<Text
style={{
...text.title,
marginTop: 12,
width: layout.width - layout.width / 8,
textAlign: 'center',
}}>
{album.name}
</Text>
<Text
style={{
...text.itemSubtitle,
fontSize: 14,
marginTop: 4,
marginBottom: 20,
width: layout.width - layout.width / 8,
textAlign: 'center',
}}>
{album.artist}
{album.year ? `${album.year}` : ''}
</Text>
<View
style={{
flexDirection: 'row',
}}>
<Button title="Play Album" onPress={() => setQueue(album.songs, album.name, album.songs[0].id)} />
</View>
<View
style={{
width: layout.width - layout.width / 20,
marginTop: 20,
marginBottom: 30,
}}>
{album.songs
.sort((a, b) => {
if (b.track && a.track) {
return a.track - b.track
} else {
return a.title.localeCompare(b.title)
}
})
.map(s => (
<SongItem
key={s.id}
id={s.id}
title={s.title}
artist={s.artist}
track={s.track}
onPress={() => setQueue(album.songs, album.name, s.id)}
/>
))}
style={styles.container}>
<View style={styles.content}>
<View style={styles.cover}>
<AlbumArt id={album.id} height="100%" width="100%" />
</View>
<Text style={styles.title}>{album.name}</Text>
<Text style={styles.subtitle}>
{album.artist}
{album.year ? `${album.year}` : ''}
</Text>
<View style={styles.controls}>
<Button title="Play Album" onPress={() => setQueue(album.songs, album.name, album.songs[0].id)} />
</View>
<View style={styles.songs}>
{album.songs
.sort((a, b) => {
if (b.track && a.track) {
return a.track - b.track
} else {
return a.title.localeCompare(b.title)
}
})
.map(s => (
<SongItem
key={s.id}
id={s.id}
title={s.title}
artist={s.artist}
track={s.track}
onPress={() => setQueue(album.songs, album.name, s.id)}
/>
))}
</View>
</View>
</ImageGradientScrollView>
)
}
const AlbumViewFallback = () => {
const layout = useWindowDimensions()
const coverSize = layout.width - layout.width / 2.5
return (
<GradientBackground
style={{
alignItems: 'center',
paddingTop: coverSize / 8 + coverSize / 2 - 18,
}}>
<ActivityIndicator size="large" color={colors.accent} />
</GradientBackground>
)
}
const AlbumViewFallback = () => (
<GradientBackground style={styles.fallback}>
<ActivityIndicator size="large" color={colors.accent} />
</GradientBackground>
)
const AlbumView: React.FC<{
id: string
@@ -191,4 +149,46 @@ const AlbumView: React.FC<{
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
content: {
alignItems: 'center',
paddingTop: 10,
paddingHorizontal: 20,
},
title: {
fontSize: 24,
fontFamily: font.bold,
color: colors.text.primary,
marginTop: 12,
textAlign: 'center',
},
subtitle: {
fontFamily: font.regular,
color: colors.text.secondary,
fontSize: 14,
marginTop: 4,
marginBottom: 20,
textAlign: 'center',
},
cover: {
height: 220,
width: 220,
},
controls: {
flexDirection: 'row',
},
songs: {
marginTop: 10,
marginBottom: 30,
width: '100%',
},
fallback: {
alignItems: 'center',
paddingTop: 100,
},
})
export default React.memo(AlbumView)

View File

@@ -1,11 +1,12 @@
import { useNavigation } from '@react-navigation/native'
import { useAtomValue } from 'jotai/utils'
import React, { useEffect } from 'react'
import { Text } from 'react-native'
import { StyleSheet, Text } from 'react-native'
import { artistInfoAtomFamily } from '@app/state/music'
import text from '@app/styles/text'
import ArtistArt from '@app/components/ArtistArt'
import GradientScrollView from '@app/components/GradientScrollView'
import font from '@app/styles/font'
import colors from '@app/styles/colors'
const ArtistDetails: React.FC<{ id: string }> = ({ id }) => {
const artist = useAtomValue(artistInfoAtomFamily(id))
@@ -15,15 +16,8 @@ const ArtistDetails: React.FC<{ id: string }> = ({ id }) => {
}
return (
<GradientScrollView
style={{
flex: 1,
}}
contentContainerStyle={{
alignItems: 'center',
// paddingTop: coverSize / 8,
}}>
<Text style={text.paragraph}>{artist.name}</Text>
<GradientScrollView style={styles.scroll} contentContainerStyle={styles.scrollContent}>
<Text style={styles.title}>{artist.name}</Text>
<ArtistArt id={artist.id} height={200} width={200} />
</GradientScrollView>
)
@@ -46,4 +40,18 @@ const ArtistView: React.FC<{
)
}
const styles = StyleSheet.create({
scroll: {
flex: 1,
},
scrollContent: {
alignItems: 'center',
},
title: {
fontFamily: font.regular,
fontSize: 16,
color: colors.text.primary,
},
})
export default React.memo(ArtistView)

View File

@@ -1,12 +1,13 @@
import { useNavigation } from '@react-navigation/native'
import { useAtomValue } from 'jotai/utils'
import React, { useEffect } from 'react'
import { Pressable, Text, View } from 'react-native'
import { Pressable, StyleSheet, Text, View } from 'react-native'
import { Album } from '@app/models/music'
import { albumsAtom, albumsUpdatingAtom, useUpdateAlbums } from '@app/state/music'
import textStyles from '@app/styles/text'
import font from '@app/styles/font'
import AlbumArt from '@app/components/AlbumArt'
import GradientFlatList from '@app/components/GradientFlatList'
import colors from '@app/styles/colors'
const AlbumItem: React.FC<{
id: string
@@ -15,31 +16,14 @@ const AlbumItem: React.FC<{
}> = ({ id, name, artist }) => {
const navigation = useNavigation()
const size = 125
return (
<Pressable
style={{
alignItems: 'center',
marginVertical: 8,
flex: 1 / 3,
}}
onPress={() => navigation.navigate('AlbumView', { id, title: name })}>
<AlbumArt id={id} height={size} width={size} />
<View
style={{
flex: 1,
width: size,
}}>
<Text
style={{
...textStyles.itemTitle,
marginTop: 4,
}}
numberOfLines={2}>
<Pressable style={styles.item} onPress={() => navigation.navigate('AlbumView', { id, title: name })}>
<AlbumArt id={id} height={styles.art.height} width={styles.art.height} />
<View style={styles.itemDetails}>
<Text style={styles.title} numberOfLines={2}>
{name}
</Text>
<Text style={{ ...textStyles.itemSubtitle }} numberOfLines={1}>
<Text style={styles.subtitle} numberOfLines={1}>
{artist}
</Text>
</View>
@@ -66,7 +50,7 @@ const AlbumsList = () => {
})
return (
<View style={{ flex: 1 }}>
<View style={styles.container}>
<GradientFlatList
data={albumsList}
renderItem={AlbumListRenderItem}
@@ -87,4 +71,33 @@ const AlbumsTab = () => (
</React.Suspense>
)
const styles = StyleSheet.create({
container: {
flex: 1,
},
item: {
alignItems: 'center',
marginVertical: 8,
flex: 1 / 3,
},
art: {
height: 125,
},
itemDetails: {
flex: 1,
width: 125,
},
title: {
fontSize: 13,
fontFamily: font.semiBold,
color: colors.text.primary,
marginTop: 4,
},
subtitle: {
fontSize: 12,
fontFamily: font.regular,
color: colors.text.secondary,
},
})
export default React.memo(AlbumsTab)

View File

@@ -1,34 +1,22 @@
import { useNavigation } from '@react-navigation/native'
import { useAtomValue } from 'jotai/utils'
import React, { useEffect } from 'react'
import { Pressable } from 'react-native'
import { Pressable, StyleSheet } from 'react-native'
import { Text } from 'react-native'
import { Artist } from '@app/models/music'
import { artistsAtom, artistsUpdatingAtom, useUpdateArtists } from '@app/state/music'
import textStyles from '@app/styles/text'
import font from '@app/styles/font'
import ArtistArt from '@app/components/ArtistArt'
import GradientFlatList from '@app/components/GradientFlatList'
import colors from '@app/styles/colors'
const ArtistItem: React.FC<{ item: Artist }> = ({ item }) => {
const navigation = useNavigation()
return (
<Pressable
style={{
flexDirection: 'row',
alignItems: 'center',
marginVertical: 6,
marginLeft: 6,
}}
onPress={() => navigation.navigate('ArtistView', { id: item.id, title: item.name })}>
<Pressable style={styles.item} onPress={() => navigation.navigate('ArtistView', { id: item.id, title: item.name })}>
<ArtistArt id={item.id} width={56} height={56} />
<Text
style={{
...textStyles.paragraph,
marginLeft: 12,
}}>
{item.name}
</Text>
<Text style={styles.title}>{item.name}</Text>
</Pressable>
)
}
@@ -66,4 +54,19 @@ const ArtistsList = () => {
const ArtistsTab = () => <ArtistsList />
const styles = StyleSheet.create({
item: {
flexDirection: 'row',
alignItems: 'center',
marginVertical: 6,
marginLeft: 6,
},
title: {
fontFamily: font.regular,
fontSize: 16,
color: colors.text.primary,
marginLeft: 12,
},
})
export default ArtistsTab

View File

@@ -20,11 +20,12 @@ import {
useProgress,
} from '@app/state/trackplayer'
import colors from '@app/styles/colors'
import { Font } from '@app/styles/text'
import font from '@app/styles/font'
import formatDuration from '@app/util/formatDuration'
import CoverArt from '@app/components/CoverArt'
import ImageGradientBackground from '@app/components/ImageGradientBackground'
import PressableOpacity from '@app/components/PressableOpacity'
import dimensions from '@app/styles/dimensions'
const NowPlayingHeader = () => {
const queueName = useAtomValue(queueNameAtom)
@@ -47,7 +48,7 @@ const NowPlayingHeader = () => {
const headerStyles = StyleSheet.create({
container: {
height: 58,
height: dimensions.header,
width: '100%',
flexDirection: 'row',
alignItems: 'center',
@@ -59,7 +60,7 @@ const headerStyles = StyleSheet.create({
marginHorizontal: 8,
},
queueName: {
fontFamily: Font.bold,
fontFamily: font.bold,
fontSize: 16,
color: colors.text.primary,
flex: 1,
@@ -126,13 +127,13 @@ const infoStyles = StyleSheet.create({
},
title: {
height: 28,
fontFamily: Font.bold,
fontFamily: font.bold,
fontSize: 22,
color: colors.text.primary,
},
artist: {
height: 20,
fontFamily: Font.regular,
fontFamily: font.regular,
fontSize: 16,
color: colors.text.secondary,
},
@@ -194,7 +195,7 @@ const seekStyles = StyleSheet.create({
justifyContent: 'space-between',
},
text: {
fontFamily: Font.regular,
fontFamily: font.regular,
fontSize: 15,
color: colors.text.primary,
},

View File

@@ -2,11 +2,10 @@ import { useNavigation } from '@react-navigation/core'
import { useAtom } from 'jotai'
import md5 from 'md5'
import React from 'react'
import { Button, Text, View } from 'react-native'
import { Button, StyleSheet, Text, View } from 'react-native'
import { v4 as uuidv4 } from 'uuid'
import { appSettingsAtom } from '@app/state/settings'
import { getAllKeys, multiRemove } from '@app/storage/asyncstorage'
import text from '@app/styles/text'
const TestControls = () => {
const navigation = useNavigation()
@@ -57,8 +56,8 @@ const ServerSettingsView = () => {
<Button title="Add default server" onPress={bootstrapServer} />
{appSettings.servers.map(s => (
<View key={s.id}>
<Text style={text.paragraph}>{s.address}</Text>
<Text style={text.paragraph}>{s.username}</Text>
<Text style={styles.text}>{s.address}</Text>
<Text style={styles.text}>{s.username}</Text>
</View>
))}
</View>
@@ -74,4 +73,10 @@ const SettingsView = () => (
</View>
)
const styles = StyleSheet.create({
text: {
color: 'white',
},
})
export default SettingsView