Skip to content

Commit

Permalink
Merge pull request #706 from lovegaoshi/dev
Browse files Browse the repository at this point in the history
fix: scrollto position
  • Loading branch information
lovegaoshi authored Jan 4, 2025
2 parents 707b432 + c6c5a5f commit 52fe2fc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/components/playlist/SongList/SongList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ const PlaylistList = () => {
const [contentViewHeight, setContentViewHeight] = useState(0);
const [scrollPositionY, setScrollPositionY] = useState(0);

useEffect(() => scrollTo(-1, true), [songListScrollCounter]);
useEffect(
() => scrollTo({ toIndex: -1, reset: true }),
[songListScrollCounter],
);

useFocusEffect(
React.useCallback(() => {
Expand All @@ -64,7 +67,10 @@ const PlaylistList = () => {
return (
<View style={stylesLocal.mainContainer}>
<View style={[styles.topBarContainer, { top: 10 }]}>
<PlaylistInfo onPressed={() => scrollTo()} usePlaylist={usedPlaylist} />
<PlaylistInfo
onPressed={() => scrollTo({ viewPosition: 0.5 })}
usePlaylist={usedPlaylist}
/>
<View style={stylesLocal.container}>
{checking && (
<IconButton
Expand Down
14 changes: 12 additions & 2 deletions src/components/playlist/usePlaylistRN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import { setPlayingList } from '@stores/playingList';
import { clearPlaylistUninterrupted } from '@utils/RNTPUtils';
import { execWhenTrue } from '@utils/Utils';

interface ScrollTo {
toIndex?: number;
reset?: boolean;
viewPosition?: number; // toIndex = -1, reset = false, viewPosition = -4
}

export default (playlist: NoxMedia.Playlist) => {
const { t } = useTranslation();
const setSnack = useSnack(state => state.setSnack);
Expand Down Expand Up @@ -118,7 +124,11 @@ export default (playlist: NoxMedia.Playlist) => {
);
};

const scrollTo = (toIndex = -1, reset = false) => {
const scrollTo = ({
toIndex = -1,
reset = false,
viewPosition = -4,
}: ScrollTo) => {
let currentIndex =
toIndex < 0
? playlist.songList.findIndex(song => song.id === currentPlayingId)
Expand All @@ -129,7 +139,7 @@ export default (playlist: NoxMedia.Playlist) => {
executeFn: () =>
playlistRef.current?.scrollToIndex({
index: currentIndex,
viewPosition: -4,
viewPosition: viewPosition,
animated: false,
}),
// @ts-expect-error detect if flashlist is rendered
Expand Down

0 comments on commit 52fe2fc

Please sign in to comment.