[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better export to epub #1144

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
switched from px lineheight and textsize to rem for better epub compa…
…tability
  • Loading branch information
CD-Z committed Jul 27, 2024
commit 6b5663654f16e1bc9a4cd55aa064c47cf9f50f3a
4 changes: 2 additions & 2 deletions android/app/src/main/assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Reader {
);
document.documentElement.style.setProperty(
'--readerSettings-textSize',
settings.textSize + 'px',
settings.textSize + 'rem',
);
document.documentElement.style.setProperty(
'--readerSettings-textColor',
Expand All @@ -108,7 +108,7 @@ class Reader {
);
document.documentElement.style.setProperty(
'--readerSettings-lineHeight',
settings.lineHeight,
settings.lineHeight+"rem",
);
document.documentElement.style.setProperty(
'--readerSettings-fontFamily',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import color from 'color';
import SkeletonLines from '../components/SkeletonLines';
import { useChapterReaderSettings } from '@hooks/persisted';

const ChapterLoadingScreen = () => {
const ChapterLoadingScreen = ({ onPress }: { onPress: () => void }) => {
const {
theme: backgroundColor,
padding,
Expand All @@ -14,9 +14,9 @@ const ChapterLoadingScreen = () => {
} = useChapterReaderSettings();

return (
<View style={{ backgroundColor }}>
<View style={{ backgroundColor }} >>
<SkeletonLines
containerMargin={padding + '%'}
containerMargin={`${padding}%`}
containerHeight={'100%'}
containerWidth={'100%'}
color={
Expand Down
25 changes: 12 additions & 13 deletions src/screens/reader/ReaderScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,18 @@ export const ChapterContent = ({
return (
<>
{keepScreenOn ? <KeepScreenAwake /> : null}
{loading ? (
<ChapterLoadingScreen />
) : (
<WebViewReader
html={chapterText}
nextChapter={nextChapter}
webViewRef={webViewRef}
pageReader={pageReader}
saveProgress={saveProgress}
>
navigateChapter={navigateChapter}
/>
)}

<WebViewReader
html={chapterText}
nextChapter={nextChapter}
webViewRef={webViewRef}
pageReader={pageReader}
loading={loading}
saveProgress={saveProgress}
>
navigateChapter={navigateChapter}
/>

<ReaderBottomSheetV2 bottomSheetRef={readerSheetRef} />
{!hidden ? (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const TextSizeSlider: React.FC = () => {
const theme = useTheme();

const { textSize, setChapterReaderSettings } = useChapterReaderSettings();
console.log(textSize);

return (
<View style={styles.container}>
Expand All @@ -20,9 +21,9 @@ const TextSizeSlider: React.FC = () => {
<Slider
style={styles.slider}
value={textSize}
minimumValue={12}
maximumValue={20}
step={1}
minimumValue={0.2}
maximumValue={3}
step={0.1}
minimumTrackTintColor={theme.primary}
maximumTrackTintColor={TRACK_TINT_COLOR}
thumbTintColor={theme.primary}
Expand Down
30 changes: 20 additions & 10 deletions src/screens/reader/components/SkeletonLines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const SkeletonLines = ({
width?: string | number;
lineHeight: number;
textSize: number;
containerWidth: string | number;
containerHeight: string | number;
containerMargin?: string | number;
containerWidth: `${number}%` | number;
containerHeight: `${number}%` | number;
containerMargin?: `${number}%` | number;
color?: string;
highlightColor?: string;
}) => {
Expand All @@ -30,12 +30,19 @@ const SkeletonLines = ({
lineHeight,
textSize,
);
console.log(
containerWidth,
containerHeight,
containerMargin === undefined ? 0 : containerMargin,
lineHeight,
textSize,
);

const createLines = () => {
let availableHeight: number = percentToNumberV(containerHeight) - 10;
let res: boolean[] = [];
let numberOfLongLines = 0;
const height = textSize * lineHeight;
const height = lineHeight * 10;

while (availableHeight > height) {
if (Math.random() * 4 > 1 && numberOfLongLines <= 5) {
Expand All @@ -56,7 +63,9 @@ const SkeletonLines = ({
const skeletonWidth: number = width
? Number(width)
: percentToNumberH('90%');
const skeletonHeight = textSize;
console.log(textSize);

const skeletonHeight = 1.5 * 15;
if (typeof color !== 'string') {
color = '#ebebeb';
}
Expand Down Expand Up @@ -122,9 +131,9 @@ const percentToNumberH = (number: number | string): number => {
};

const createStyleSheet = (
containerWidth: number | string,
containerHeight: number | string,
containerMargin: number | string,
containerWidth: number | `${number}%`,
containerHeight: number | `${number}%`,
containerMargin: number | `${number}%`,
lineHeight: number,
textSize: number,
) => {
Expand All @@ -135,15 +144,16 @@ const createStyleSheet = (
height: containerHeight,
backgroundColor: 'transparent',
margin: containerMargin,
marginTop: '6%',
},
lineDefault: {
marginLeft: 0,
marginRight: 0,
borderRadius: 8,
marginBottom: textSize * (lineHeight - 1),
marginBottom: lineHeight * 10,
},
gap: {
height: textSize * (lineHeight - 1),
height: lineHeight * 10,
margin: 8,
},
});
Expand Down
12 changes: 9 additions & 3 deletions src/screens/reader/components/WebViewReader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import * as Clipboard from 'expo-clipboard';
import { showToast } from '@utils/showToast';
import { PLUGIN_STORAGE } from '@utils/Storages';
import { useChapterContext } from '../ChapterContext';
import ChapterLoadingScreen from '../ChapterLoadingScreen/ChapterLoadingScreen';

type WebViewPostEvent = {
type: string;
Expand All @@ -38,6 +39,7 @@ type WebViewReaderProps = {
html: string;
nextChapter: ChapterInfo;
webViewRef: React.RefObject<WebView>;
loading: boolean;
saveProgress(percentage: number): void;
onPress(): void;
navigateChapter(position: 'NEXT' | 'PREV'): void;
Expand All @@ -62,6 +64,7 @@ const WebViewReader: React.FC<WebViewReaderProps> = props => {
nextChapter,
webViewRef,
pageReader,
loading,
saveProgress,
onPress,
navigateChapter,
Expand Down Expand Up @@ -132,6 +135,11 @@ const WebViewReader: React.FC<WebViewReaderProps> = props => {
mmkvListener.remove();
};
}, []);
console.log(readerSettings.textSize);
if (loading) {
return <ChapterLoadingScreen />;
}

const debugging = `
// Debug
console = new Object();
Expand Down Expand Up @@ -214,9 +222,7 @@ const WebViewReader: React.FC<WebViewReaderProps> = props => {
--StatusBar-currentHeight: ${StatusBar.currentHeight};
--readerSettings-theme: ${readerSettings.theme};
--readerSettings-padding: ${readerSettings.padding}%;
--readerSettings-textSize: ${
readerSettings.textSize / 10
}rem;
--readerSettings-textSize: ${readerSettings.textSize}rem;
--readerSettings-textColor: ${readerSettings.textColor};
--readerSettings-textAlign: ${readerSettings.textAlign};
--readerSettings-lineHeight: ${readerSettings.lineHeight};
Expand Down