Skip to content

Commit

Permalink
fix: align all album titles in track list view
Browse files Browse the repository at this point in the history
fixes #172
  • Loading branch information
leinelissen committed Jul 21, 2024
1 parent 38ce998 commit 7cdd01e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/screens/Music/stacks/components/TrackListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import { SafeScrollView, useNavigationOffsets } from '@/components/SafeNavigator

const styles = StyleSheet.create({
index: {
marginRight: 12
marginRight: 12,
textAlign: 'right',
},
activeText: {
fontWeight: '500',
Expand Down Expand Up @@ -105,6 +106,26 @@ const TrackListView: React.FC<TrackListViewProps> = ({
const navigation = useNavigation<NavigationProp>();
const dispatch = useAppDispatch();

// Visual helpers
const { indexWidth } = useMemo(() => {
// Retrieve the largest index in the current set of tracks
const largestIndex = trackIds.reduce((max, trackId, i) => {
// Retrieve the index for this trackid, depending on settings
const index = listNumberingStyle === 'index'
? i + 1
: tracks[trackId]?.IndexNumber;

// Check that the current index is larger than the current max.
return index > max ? index: max;
}, 0);

// Retrieve the number of digits in the largest index
const noDigits = largestIndex.toFixed(0).toString().length;

// Set a minWidth proportional to the largest amount of digits in an index
return StyleSheet.create({ indexWidth: { minWidth: noDigits * 8 } });
}, [trackIds, tracks, listNumberingStyle]);

// Setup callbacks
const playEntity = useCallback(() => { playTracks(trackIds); }, [playTracks, trackIds]);
const shuffleEntity = useCallback(() => { playTracks(trackIds, { shuffle: true }); }, [playTracks, trackIds]);
Expand Down Expand Up @@ -162,6 +183,7 @@ const TrackListView: React.FC<TrackListViewProps> = ({
defaultStyles.textQuarterOpacity,
currentTrack?.backendId === trackId && styles.activeText,
currentTrack?.backendId === trackId && defaultStyles.themeColorQuarterOpacity,
indexWidth,
]}
numberOfLines={1}
>
Expand Down

0 comments on commit 7cdd01e

Please sign in to comment.