Skip to content

Commit

Permalink
feat: Add Horizontal Reading Mode (#1021)
Browse files Browse the repository at this point in the history
* Horizontal Reading Mode (#733)

Closes #29
Closes #149

* fixed first few compatibility issues

* added WebView debugging help

* fixed pages logic + open next chapter at end

* hopefully fixed infinity glitch

* removed logs

* fixed small issues

* working page numbering

* double L shape navigation

* changed let to const

* fixed scrollTo function

* cleanup and fixed css issues

* fixed display bug

* fixed settings bug

* added change padding setting

* added strings

* save + scroll on opening chapter logic

* resolved totalpages detection issue

* simplified getInt function

* css cleanup

* removed useless

* fixed padding scaling bug

* deleted debug items

* additional top padding

* smaller chapter height

* fixed contextMenu

* replaced name: readerPages » pageReader

* fixed ReaderSettings Preview Reader behaviour

* cleanup

* ReaderValueChange improvements

* moved page state to js

* fixed type issues

* functionality test

* fix: NaN page on scrollbar

---------

Co-authored-by: nyagami <[email protected]>
  • Loading branch information
CD-Z and nyagami authored Jul 14, 2024
1 parent ea5fde4 commit 31d0aa1
Show file tree
Hide file tree
Showing 51 changed files with 4,537 additions and 5,547 deletions.
25 changes: 25 additions & 0 deletions android/app/src/main/assets/css/horizontal.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
* {
touch-action: none;
}

body {
height: 100vh;
overflow: hidden;
position: relative;
}

html {
height: 100vh;
}

chapter {
/* height: calc(100% - 3% - var(--readerSettings-padding) - 2rem); */
height: 90vh;
display: flexbox;
flex-direction: column;
flex-wrap: wrap;
column-gap: 0;
column-width: 100vw;
transition: 200ms;
padding-top: calc(3% + var(--readerSettings-padding));
}
32 changes: 22 additions & 10 deletions android/app/src/main/assets/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ html {
overflow-x: hidden;
padding-top: var(--StatusBar-currentHeight);
word-wrap: break-word;
padding: 0;
}

::selection {
Expand All @@ -16,8 +17,9 @@ html {
}

body {
padding-left: var(--readerSettings-padding);
padding-right: var(--readerSettings-padding);
margin-left: 0;
margin-right: 0;
padding: 0;
padding-bottom: 40px;

font-size: var(--readerSettings-textSize);
Expand All @@ -29,9 +31,16 @@ body {
}

chapter {
width: 100%;
display: block;
}

chapter > * {
max-width: 100vw;
padding-left: var(--readerSettings-padding);
padding-right: var(--readerSettings-padding);
}

hr {
margin-top: 20px;
margin-bottom: 20px;
Expand Down Expand Up @@ -75,7 +84,9 @@ td {

.nextButton,
.infoText {
width: 100%;
margin-left: var(--readerSettings-padding);
margin-right: var(--readerSettings-padding);
width: calc(100% - var(--readerSettings-padding) * 2);
border-radius: 50px;
border-width: 1;
color: var(--theme-onPrimary);
Expand Down Expand Up @@ -300,9 +311,11 @@ td {
.reader-footer-item {
flex: 1;
}

.reader-footer-item:first-child {
text-align: left;
}

.reader-footer-item:last-child {
text-align: right;
}
Expand All @@ -313,15 +326,14 @@ td {
}

.contextMenu {
position: absolute;
position: fixed;
background: var(--theme-surface-0-9);
height: 0;
top: var(--top);
left: var(--left);
overflow: hidden;
background: var(--theme-surface-0-9);
-webkit-backdrop-filter: blur(1px);
backdrop-filter: blur(1px);
position: fixed;
top: var(--top);
left: var(--left);
-webkit-animation: menuAnimation 0.4s 0s both;
animation: menuAnimation 0.4s 0s both;
transform-origin: left;
Expand All @@ -341,9 +353,8 @@ td {
color: var(--theme-onSurface);
background: 0;
border: 0;
white-space: nowrap;
width: 100%;
border-radius: 4px;
white-space: nowrap;
padding: 6px 24px 6px 7px;
text-align: left;
display: flex;
Expand All @@ -361,6 +372,7 @@ td {
.contextMenu-button svg {
fill: var(--theme-onSurface);
}

.contextMenu-button span {
margin-left: 4px;
}
Expand Down
10 changes: 10 additions & 0 deletions android/app/src/main/assets/js/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const select = key => {
return document.querySelector(key);
};
const chapter = select('chapter');
const getInt = key => {
return parseInt(chapter?.getAttribute('data-' + key), 10);
};
const setAttr = (key, val) => {
chapter?.setAttribute(key, val);
};
65 changes: 65 additions & 0 deletions android/app/src/main/assets/js/horizontalScroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const bounds = document.querySelector('html').getBoundingClientRect();
var page = 0;
var pages = 0;

function setPages(newPages) {
if (newPages) {
pages = newPages;
return;
}
const textWidth = chapter.scrollWidth;
const layoutWidth = parseInt(
document.querySelector('html').getBoundingClientRect().width,
10,
);
pages = Math.round(textWidth / layoutWidth) - 1;
}
function setPage(newPage) {
page = newPage ?? 0;
}
function getPages() {
return pages;
}
function getPage() {
return page;
}
function tapChapter(event) {
const { clientX, clientY } = event;
const { x, y } = { x: clientX / bounds.width, y: clientY / bounds.height };

if (y < 0.2) {
movePage('prev');
} else if (y > 0.8) {
movePage('next');
} else if (x < 0.33) {
movePage('prev');
} else if (x > 0.66) {
movePage('next');
} else {
movePage();
}
}

function movePage(panel) {
switch (panel) {
case 'next':
if (page === pages) {
reader.post({ type: 'next' });
} else {
page++;
}
break;
case 'prev':
if (page === 0) {
reader.post({ type: 'prev' });
} else {
page--;
}
break;
default:
reader.post({ type: 'hide' });
break;
}

chapter.style.transform = 'translate(-' + page * 100 + '%)';
}
Loading

0 comments on commit 31d0aa1

Please sign in to comment.