Skip to content

Commit

Permalink
refactor: TrackInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
lovegaoshi committed Sep 23, 2023
1 parent 96dae13 commit d7899a2
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 93 deletions.
3 changes: 2 additions & 1 deletion src/components/background/GroupView.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import { View, StyleSheet } from 'react-native';
import { useNoxSetting } from '@hooks/useSetting';
import { Text } from 'react-native-paper';

interface Props {
title?: string;
children: JSX.Element;
children: React.JSX.Element;
}

export default (props: Props) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/background/MainBackground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const resolveBackgroundImage = async (
}
};

const MainBackground = (props: { children: JSX.Element }) => {
const MainBackground = (props: { children: React.JSX.Element }) => {
const playerStyle = useNoxSetting(state => state.playerStyle);
const isLandscape = useIsLandscape();
const mobileHeight = Dimensions.get('window').height;
Expand Down
2 changes: 1 addition & 1 deletion src/components/player/Lyric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import logger from '@utils/Logger';
const LYRIC_OFFSET_INTERVAL = 0.5;

interface ModalContainerProps {
children: JSX.Element[];
children: React.JSX.Element[];
visible: boolean;
onRequestClose: () => void;
}
Expand Down
94 changes: 12 additions & 82 deletions src/components/player/TrackInfo/TrackInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useCallback, useState, useRef } from 'react';
import React, { useState, useRef } from 'react';
import {
StyleSheet,
Text,
View,
Dimensions,
Animated,
Expand All @@ -10,35 +9,21 @@ import {
import type { Track } from 'react-native-track-player';
import Image from 'react-native-fast-image';

import TrackInfoTemplate from './TrackInfoTemplate';
import { useNoxSetting } from '@hooks/useSetting';
import { getCurrentTPQueue } from '@stores/playingList';
import { LyricView } from '../Lyric';
import SongMenuButton from './SongMenuButton';
import FavReloadButton from './FavReloadButton';

export const TrackInfo: React.FC<{
interface Props {
track?: Track;
}> = ({ track }) => {
windowWidth?: number;
}
const TrackInfo: React.FC<Props> = ({ track, windowWidth }) => {
const playerSetting = useNoxSetting(state => state.playerSetting);
const playerStyle = useNoxSetting(state => state.playerStyle);
const currentPlayingList = useNoxSetting(state => state.currentPlayingList);
const [isImageVisible, setIsImageVisible] = useState(true);
const opacity = useRef(new Animated.Value(1)).current;
const dimension = Dimensions.get('window');
const albumArtSize = Math.min(dimension.width, dimension.height);

const getTrackLocation = () => {
const currentTPQueue = getCurrentTPQueue();
return track?.song
? `#${
currentPlayingList.songList.findIndex(
song => song.id === track.song.id
) + 1
} - ${
currentTPQueue.findIndex(song => song.id === track.song.id) + 1
}/${currentTPQueue.length}`
: '';
};
const albumArtSize =
windowWidth || Math.min(dimension.width, dimension.height);

const onImagePress = () => {
console.log('TrackInfo: Image Clicked - ');
Expand Down Expand Up @@ -69,7 +54,7 @@ export const TrackInfo: React.FC<{
};

return (
<View style={styles.container}>
<TrackInfoTemplate>
<>
<TouchableWithoutFeedback onPress={onImagePress}>
<Animated.View
Expand Down Expand Up @@ -114,38 +99,12 @@ export const TrackInfo: React.FC<{
</View>
</TouchableWithoutFeedback>
</>
<Text style={[styles.titleText, { color: playerStyle.colors.primary }]}>
{track?.title}
</Text>
<View style={styles.infoContainer}>
<View style={styles.favoriteButtonContainer}>
<FavReloadButton track={track} />
</View>
<View style={styles.artistInfoContainer}>
<Text
style={[styles.artistText, { color: playerStyle.colors.secondary }]}
>
{track?.artist}
</Text>
<Text
style={[styles.artistText, { color: playerStyle.colors.secondary }]}
>
{currentPlayingList.title}
</Text>
<Text
style={[styles.artistText, { color: playerStyle.colors.secondary }]}
>
{getTrackLocation()}
</Text>
</View>
<View style={styles.songMenuButtonContainer}>
<SongMenuButton track={track} />
</View>
</View>
</View>
</TrackInfoTemplate>
);
};

export default TrackInfo;

const styles = StyleSheet.create({
container: {
alignItems: 'center',
Expand All @@ -157,33 +116,4 @@ const styles = StyleSheet.create({
lyric: {
opacity: 1,
},
titleText: {
fontSize: 18,
fontWeight: '600',
color: 'grey',
marginTop: 15,
paddingHorizontal: 5,
},
artistText: {
fontSize: 16,
fontWeight: '200',
},
infoContainer: {
flexDirection: 'row',
},
favoriteButtonContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
artistInfoContainer: {
flex: 4,
justifyContent: 'center',
alignItems: 'center',
},
songMenuButtonContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
147 changes: 147 additions & 0 deletions src/components/player/TrackInfo/TrackInfoTemplate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import React from 'react';
import {
StyleSheet,
Text,
View,
Dimensions,
Animated,
TouchableWithoutFeedback,
} from 'react-native';
import type { Track } from 'react-native-track-player';
import Image from 'react-native-fast-image';

import { useNoxSetting } from '@hooks/useSetting';
import { getCurrentTPQueue } from '@stores/playingList';
import SongMenuButton from './SongMenuButton';
import FavReloadButton from './FavReloadButton';

interface Props {
track?: Track;
windowWidth?: number;
onImagePress?: () => void;
children?: React.JSX.Element;
}
const TrackInfoTemplate: React.FC<Props> = ({
track,
windowWidth,
onImagePress = () => undefined,
children,
}) => {
const playerSetting = useNoxSetting(state => state.playerSetting);
const playerStyle = useNoxSetting(state => state.playerStyle);
const currentPlayingList = useNoxSetting(state => state.currentPlayingList);
const dimension = Dimensions.get('window');
const albumArtSize =
windowWidth || Math.min(dimension.width, dimension.height);

const getTrackLocation = () => {
const currentTPQueue = getCurrentTPQueue();
return track?.song
? `#${
currentPlayingList.songList.findIndex(
song => song.id === track.song.id
) + 1
} - ${
currentTPQueue.findIndex(song => song.id === track.song.id) + 1
}/${currentTPQueue.length}`
: '';
};

const AlbumArt = () => (
<TouchableWithoutFeedback onPress={onImagePress}>
<Animated.View style={styles.container}>
<Image
style={[
styles.artwork,
{ width: albumArtSize, height: albumArtSize },
]}
source={
playerSetting.hideCoverInMobile
? 0
: {
uri: `${track?.artwork}`,
}
}
/>
</Animated.View>
</TouchableWithoutFeedback>
);

return (
<View style={styles.container}>
{children || <AlbumArt />}
<Text style={[styles.titleText, { color: playerStyle.colors.primary }]}>
{track?.title}
</Text>
<View style={styles.infoContainer}>
<View style={styles.favoriteButtonContainer}>
<FavReloadButton track={track} />
</View>
<View style={styles.artistInfoContainer}>
<Text
style={[styles.artistText, { color: playerStyle.colors.secondary }]}
>
{track?.artist}
</Text>
<Text
style={[styles.artistText, { color: playerStyle.colors.secondary }]}
>
{currentPlayingList.title}
</Text>
<Text
style={[styles.artistText, { color: playerStyle.colors.secondary }]}
>
{getTrackLocation()}
</Text>
</View>
<View style={styles.songMenuButtonContainer}>
<SongMenuButton track={track} />
</View>
</View>
</View>
);
};

export default TrackInfoTemplate;

const styles = StyleSheet.create({
container: {
alignItems: 'center',
},
artwork: {
marginTop: 15,
opacity: 1,
},
lyric: {
opacity: 1,
},
titleText: {
fontSize: 18,
fontWeight: '600',
color: 'grey',
marginTop: 15,
paddingHorizontal: 5,
},
artistText: {
fontSize: 16,
fontWeight: '200',
},
infoContainer: {
flexDirection: 'row',
},
favoriteButtonContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
artistInfoContainer: {
flex: 4,
justifyContent: 'center',
alignItems: 'center',
},
songMenuButtonContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
2 changes: 1 addition & 1 deletion src/components/player/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ParamListBase } from '@react-navigation/native';
import { DrawerNavigationProp } from '@react-navigation/drawer';
import { useTranslation } from 'react-i18next';

import { TrackInfo } from './';
import TrackInfo from './TrackInfo/TrackInfo';
import { SetupService, AdditionalPlaybackService } from 'services';
import PlayerTopInfo from './PlayerTopInfo';
import { useNoxSetting } from '@hooks/useSetting';
Expand Down
1 change: 0 additions & 1 deletion src/components/player/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './PlayerControls';
export * from './PlayPauseButton';
export * from './Progress';
export * from './TrackInfo/TrackInfo';
2 changes: 1 addition & 1 deletion src/components/playlist/PlaylistList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const { getState } = noxPlayingList;
interface BackgroundProps {
song: NoxMedia.Song;
current?: boolean;
children: JSX.Element;
children: React.JSX.Element;
}
const SongBackground = (props: BackgroundProps) => {
return props.current ? (
Expand Down
2 changes: 1 addition & 1 deletion src/components/setting/appearances/SkinSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const BuiltInThemes: DisplayTheme[] = [
];

const GestureWrapper = (props: {
children: JSX.Element;
children: React.JSX.Element;
gesture: PanGesture;
}) => {
if (Platform.OS === 'ios') {
Expand Down
3 changes: 2 additions & 1 deletion src/components/setting/useRenderSetting.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { View, Text, StyleSheet } from 'react-native';
import {
Expand All @@ -21,7 +22,7 @@ import { SettingEntry } from './SetttingEntries';
* @returns
*/
interface SetttingListInterface {
icon?: string | (() => JSX.Element);
icon?: string | (() => React.JSX.Element);
settingName: string;
onPress: () => void;
settingCategory?: string;
Expand Down
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11108,9 +11108,10 @@ react-is@^17.0.1:
resolved "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==

"react-native-app-auth@git+https://github.com/lovegaoshi/react-native-app-auth.git":
version "7.0.0-rc2"
resolved "git+https://github.com/lovegaoshi/react-native-app-auth.git#687cf242ca4a7708c659552244f65e0fd9b493a0"
react-native-app-auth@^7.0.0:
version "7.0.0"
resolved "https://registry.npmjs.org/react-native-app-auth/-/react-native-app-auth-7.0.0.tgz#12ebbe249c47dd915783ed322785ee5e893dc7bd"
integrity sha512-rJAdt5oG2sV1AJxZJvJnyv/Ecl0xVMGqR40ybvX5YL/RA1nG7FaPvaM9zTrXyajyj/pJR8WaN8EszdW8C3jAgw==
dependencies:
"@changesets/cli" "^2.26.1"
invariant "2.2.4"
Expand Down

0 comments on commit d7899a2

Please sign in to comment.