From cfcfbe934b34dca05e3cc8f612753e606215de0f Mon Sep 17 00:00:00 2001 From: LJQ Date: Thu, 23 May 2024 21:40:31 +0800 Subject: [PATCH] Instant scroll when enter webview. Enums to determine --- src/controllers/lyrics.js | 18 ++++++++++++------ src/controllers/lyrics.types.ts | 5 +++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 src/controllers/lyrics.types.ts diff --git a/src/controllers/lyrics.js b/src/controllers/lyrics.js index 499931f73e..c84fb9007b 100644 --- a/src/controllers/lyrics.js +++ b/src/controllers/lyrics.js @@ -13,13 +13,14 @@ import LibraryMenu from '../scripts/libraryMenu'; import Events from '../utils/events.ts'; import '../styles/lyrics.scss'; +import { AutoScrollType } from './lyrics.types'; let currentPlayer; let currentItem; let savedLyrics; let isDynamicLyric = false; -let autoScroll = true; +let autoScroll = AutoScrollType.Smooth; function dynamicLyricHtmlReducer(htmlAccumulator, lyric, index) { if (layoutManager.tv) { @@ -72,9 +73,14 @@ export default function (view) { if (lyric) { lyric.classList.remove('pastLyric'); lyric.classList.remove('futureLyric'); - if (autoScroll) { + if (autoScroll === AutoScrollType.Smooth) { scrollManager.scrollToElement(lyric, true); } + if (autoScroll === AutoScrollType.Instant) { + // instant scroll is used when the view is first loaded + scrollManager.scrollToElement(lyric, false); + autoScroll = AutoScrollType.Smooth; + } } } @@ -184,7 +190,7 @@ export default function (view) { } function onLyricClick(lyricTime) { - autoScroll = true; + autoScroll = AutoScrollType.Smooth; playbackManager.seek(lyricTime); if (playbackManager.paused()) { playbackManager.playPause(currentPlayer); @@ -242,19 +248,19 @@ export default function (view) { } function onWheelOrTouchMove() { - autoScroll = false; + autoScroll = AutoScrollType.None; } function onKeyDown(e) { const key = keyboardNavigation.getKeyName(e); if (key === 'ArrowUp' || key === 'ArrowDown') { - autoScroll = false; + autoScroll = AutoScrollType.None; } } view.addEventListener('viewshow', function () { Events.on(playbackManager, 'playerchange', onPlayerChange); - autoScroll = true; + autoScroll = AutoScrollType.Instant; document.addEventListener('wheel', onWheelOrTouchMove); document.addEventListener('touchmove', onWheelOrTouchMove); document.addEventListener('keydown', onKeyDown); diff --git a/src/controllers/lyrics.types.ts b/src/controllers/lyrics.types.ts new file mode 100644 index 0000000000..88593104de --- /dev/null +++ b/src/controllers/lyrics.types.ts @@ -0,0 +1,5 @@ +export enum AutoScrollType { + None = 0, + Smooth = 1, + Instant = 2 +}