Skip to content

Commit

Permalink
feat: ✨ 增加全屏按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
hymbz committed Dec 24, 2024
1 parent 7acaa9d commit 8cf5069
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"download_completed": "Download completed",
"downloading": "Downloading",
"exit": "Exit",
"fullscreen": "Fullscreen",
"fullscreen_exit": "Exit Fullscreen",
"grid_mode": "Grid mode",
"packaging": "Packaging",
"page_fill": "Page fill",
Expand Down
2 changes: 2 additions & 0 deletions locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"download_completed": "Загрузка завершена",
"downloading": "Скачивание",
"exit": "Выход",
"fullscreen": "полноэкранный",
"fullscreen_exit": "выйти из полноэкранного режима",
"grid_mode": "Режим сетки",
"packaging": "Упаковка",
"page_fill": "Заполнить страницу",
Expand Down
2 changes: 2 additions & 0 deletions locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"download_completed": "下载完成",
"downloading": "下载中",
"exit": "退出",
"fullscreen": "全屏",
"fullscreen_exit": "退出全屏",
"grid_mode": "网格模式",
"packaging": "打包中",
"page_fill": "页面填充",
Expand Down
6 changes: 6 additions & 0 deletions src/components/Manga/actions/switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ export const switchFitToWidth = () => {
});
jump();
};

/** 切换全屏 */
export const switchFullscreen = () => {
if (document.fullscreenElement) document.exitFullscreen();
else refs.root.requestFullscreen();
};
14 changes: 14 additions & 0 deletions src/components/Manga/defaultButtonList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import MdTranslate from '@material-design-icons/svg/round/translate.svg';
import MdGrid from '@material-design-icons/svg/round/grid_4x4.svg';
import MdZoomIn from '@material-design-icons/svg/round/zoom_in.svg';
import MdZoomOut from '@material-design-icons/svg/round/zoom_out.svg';
import MdFullscreen from '@material-design-icons/svg/round/fullscreen.svg';
import MdFullscreenExit from '@material-design-icons/svg/round/fullscreen_exit.svg';
import { createMemo, type Component, createSignal, Show } from 'solid-js';
import { createEffectOn, t } from 'helper';

Expand All @@ -26,6 +28,7 @@ import {
isTranslatingImage,
isOnePageMode,
isScrollMode,
switchFullscreen,
} from './actions';
import classes from './index.module.css';

Expand Down Expand Up @@ -116,6 +119,17 @@ export const defaultButtonList: ToolbarButtonList = [
/>
</Show>
),
// 全屏
() => (
<IconButton
tip={
store.fullscreen ? t('button.fullscreen_exit') : t('button.fullscreen')
}
hidden={!refs.root.requestFullscreen}
onClick={switchFullscreen}
children={store.fullscreen ? <MdFullscreenExit /> : <MdFullscreen />}
/>
),
// 翻译设置
() => (
<IconButton
Expand Down
10 changes: 10 additions & 0 deletions src/components/Manga/hooks/useInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '../actions';
import { defaultOption, type Option } from '../store/option';
import { playAnimation } from '../helper';
import classes from '../index.module.css';

const createComicImg = (src: string): ComicImg => ({
src,
Expand Down Expand Up @@ -232,5 +233,14 @@ export const useInit = (props: MangaProps) => {
_setState('supportWorker', Boolean(new Worker(codeUrl)));
}, 0);

refs.root.addEventListener('fullscreenchange', () => {
if (!document.fullscreenElement) return _setState('fullscreen', false);
if (
document.fullscreenElement.id === 'comicRead' ||
document.fullscreenElement.classList.contains(classes.root)
)
_setState('fullscreen', true);
});

focus();
};
2 changes: 2 additions & 0 deletions src/components/Manga/store/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const otherState = {
* - 在首次触发结束页时开启,一段时间关闭。开启时禁止触发结束页的上下话切换功能。
*/
scrollLock: false,
/** 当前是否处于全屏状态 */
fullscreen: false,

rootSize: { width: 0, height: 0 },
scrollbarSize: { width: 0, height: 0 },
Expand Down

0 comments on commit 8cf5069

Please sign in to comment.