Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 97 additions & 70 deletions packages/app-expo/assets/reader/reader.html

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions packages/app-expo/assets/reader/reader.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
let currentCustomFontFaceCSS = '';
let currentCustomFontFamily = '';
let currentUseBookFonts = true;
let currentSmoothReading = false;
let tapNavigationInFlight = false;
let tapNavigationResetTimer = null;
let readerElement = null;
Expand Down Expand Up @@ -333,6 +334,21 @@
}
}

// Smooth reading ("平滑阅读"): one toggle drives both the foliate
// `animated` page-turn transition and the `scroll-inertia` finger-flick
// physics. The attributes are inert until the renderer handles them, so
// this is safe to toggle at any time (load, viewMode change, or live).
function syncSmoothReadingAttribute(renderer) {
if (!renderer) return;
if (currentSmoothReading) {
renderer.setAttribute('animated', '');
renderer.setAttribute('scroll-inertia', '');
} else {
renderer.removeAttribute('animated');
renderer.removeAttribute('scroll-inertia');
}
}

function getTransformViewportSize() {
const root = document.documentElement;
const viewport = window.visualViewport;
Expand Down Expand Up @@ -1812,6 +1828,10 @@
if (settings.justifyBodyText !== undefined) {
currentJustifyBodyText = settings.justifyBodyText !== false;
}
if (settings.smoothReading !== undefined) {
currentSmoothReading = settings.smoothReading === true;
syncSmoothReadingAttribute(renderer);
}
// PDF pages are fixed-layout canvases. Reader font, line-height, custom
// font and paragraph-spacing rules would move the transparent text layer
// away from the canvas and render a second, misaligned copy of the text.
Expand Down
3 changes: 3 additions & 0 deletions packages/app-expo/src/hooks/use-reader-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export interface ReaderInitialSettings {
useBookFonts?: boolean;
viewMode?: "paginated" | "scroll";
paginatedLayout?: "single" | "double";
/** Smooth reading: foliate `animated` page-turn + `scroll-inertia` physics */
smoothReading?: boolean;
}

function withJustifiedTextSetting(settings: ReaderInitialSettings = {}): ReaderInitialSettings {
Expand Down Expand Up @@ -286,6 +288,7 @@ export function useReaderBridge(callbacks: ReaderBridgeCallbacks) {
paginatedLayout?: "single" | "double";
customFontFaceCSS?: string;
customFontFamily?: string;
smoothReading?: boolean;
}) => {
const msg = JSON.stringify({
type: "applySettings",
Expand Down
2 changes: 2 additions & 0 deletions packages/app-expo/src/screens/ReaderScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ export function ReaderScreen({ route, navigation }: Props) {
useBookFonts: settings.useBookFonts,
viewMode: settings.viewMode,
paginatedLayout: settings.paginatedLayout,
smoothReading: settings.smoothReading === true,
customFontFaceCSS: fontCSS,
customFontFamily: fontFamily ?? "",
});
Expand Down Expand Up @@ -1144,6 +1145,7 @@ export function ReaderScreen({ route, navigation }: Props) {
useBookFonts: readSettings.useBookFonts,
viewMode: readSettings.viewMode,
paginatedLayout: readSettings.paginatedLayout,
smoothReading: readSettings.smoothReading === true,
},
});

Expand Down
18 changes: 18 additions & 0 deletions packages/app-expo/src/screens/reader/ReaderSettingsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function ReaderSettingsPanel({ visible, readSettings, bookId, onClose, on
pageMargin: settingPageMargin,
viewMode: settingViewMode,
volumeButtonsPageTurn,
smoothReading,
showTopTitleProgress,
showBottomTimeBattery,
followSystemFontScale,
Expand Down Expand Up @@ -261,6 +262,23 @@ export function ReaderSettingsPanel({ visible, readSettings, bookId, onClose, on
</TouchableOpacity>
</View>
</View>
{/* Smooth reading: animated page turns + scroll inertia */}
<View style={s.settingRow}>
<View style={s.settingLabelBlock}>
<Text style={s.settingLabel}>{t("settings.smoothReading")}</Text>
<Text style={s.settingHint}>
{t("settings.smoothReadingDesc", "开启翻页过渡动画与滚动惯性,关闭可提升低性能设备流畅度")}
</Text>
</View>
<TouchableOpacity
style={[s.settingToggleBtn, !!smoothReading && s.settingToggleBtnActive]}
onPress={() => onUpdateSetting("smoothReading", !smoothReading)}
>
<Text style={[s.settingToggleText, !!smoothReading && s.settingToggleTextActive]}>
{smoothReading ? t("settings.enabled") : t("settings.disabled")}
</Text>
</TouchableOpacity>
</View>
{Platform.OS === "android" && (
<View style={s.settingRow}>
<View style={s.settingLabelBlock}>
Expand Down
1 change: 1 addition & 0 deletions packages/app-expo/src/stores/settings-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const defaultReadSettings: ReadSettings = {
showTopTitleProgress: true,
showBottomTimeBattery: true,
volumeButtonsPageTurn: false,
smoothReading: false,
defaultHighlightColor: "yellow",
};

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"showBottomTimeBattery": "Bottom Time & Battery",
"volumeButtonsPageTurn": "Volume Buttons Turn Pages",
"volumeButtonsPageTurnDesc": "While reading, volume keys turn pages",
"smoothReading": "Smooth Reading",
"smoothReadingDesc": "Enable page-turn transition animation and scroll inertia. Disable for better performance on low-end devices",
"followSystemFontScale": "Follow System Font Scale",
"followSystemFontScaleDesc": "Auto-scale by the OS accessibility font size",
"fixedLayoutNotice": "PDF is a fixed layout format. Font and layout settings are not available.",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/es/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"showBottomTimeBattery": "Hora y batería inferior",
"volumeButtonsPageTurn": "Botones de volumen cambian página",
"volumeButtonsPageTurnDesc": "Durante la lectura, los botones de volumen pasan página",
"smoothReading": "Lectura fluida",
"smoothReadingDesc": "Activa la animación de transición de página y la inercia de desplazamiento. Desactívelo para mejor rendimiento en dispositivos básicos",
"followSystemFontScale": "Seguir escala de fuente del sistema",
"followSystemFontScaleDesc": "Escalar automáticamente según el tamaño de fuente de accesibilidad del SO",
"fixedLayoutNotice": "PDF es un formato de diseño fijo. Los ajustes de fuente y diseño no están disponibles.",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/fr/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"showBottomTimeBattery": "Heure et batterie en bas",
"volumeButtonsPageTurn": "Tourner les pages avec les boutons de volume",
"volumeButtonsPageTurnDesc": "En lecture, les boutons de volume tournent les pages",
"smoothReading": "Lecture fluide",
"smoothReadingDesc": "Active l'animation de transition de page et l'inertie de défilement. Désactivez pour de meilleures performances sur les appareils modestes",
"followSystemFontScale": "Suivre l'échelle de police système",
"followSystemFontScaleDesc": "Mise à l'échelle auto selon la taille de police d'accessibilité du système",
"fixedLayoutNotice": "Le PDF est un format à mise en page fixe. Les paramètres de police et mise en page ne sont pas disponibles.",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/ja/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"showBottomTimeBattery": "下部時刻&バッテリー表示",
"volumeButtonsPageTurn": "音量ボタンでページ送り",
"volumeButtonsPageTurnDesc": "読書中は音量ボタンでページ送りします",
"smoothReading": "スムーズリーディング",
"smoothReadingDesc": "ページめくりアニメーションとスクロール慣性を有効化。低スペック端末ではオフにすると快適です",
"followSystemFontScale": "システムフォントサイズに従う",
"followSystemFontScaleDesc": "OSのアクセシビリティフォントサイズで自動調整",
"fixedLayoutNotice": "PDFは固定レイアウト形式です。フォントとレイアウト設定は利用できません。",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/ko/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"showBottomTimeBattery": "하단 시간 및 배터리",
"volumeButtonsPageTurn": "볼륨 버튼으로 페이지 넘기기",
"volumeButtonsPageTurnDesc": "독서 중 볼륨 버튼으로 페이지를 넘깁니다",
"smoothReading": "부드러운 읽기",
"smoothReadingDesc": "페이지 넘김 전환 애니메이션과 스크롤 관성을 켭니다. 저사양 기기에서는 끄면 더 부드럽습니다",
"followSystemFontScale": "시스템 글꼴 크기 따르기",
"followSystemFontScaleDesc": "OS 접근성 글꼴 크기에 따라 자동 조정",
"fixedLayoutNotice": "PDF는 고정 레이아웃 형식이에요. 글꼴 및 레이아웃 설정을 사용할 수 없어요.",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/zh-TW/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"showBottomTimeBattery": "底部時間與電量",
"volumeButtonsPageTurn": "音量鍵翻頁",
"volumeButtonsPageTurnDesc": "開啟後閱讀時音量鍵用於上下翻頁",
"smoothReading": "平滑閱讀",
"smoothReadingDesc": "開啟翻頁過渡動畫與滾動慣性,關閉可提升低效能裝置流暢度",
"followSystemFontScale": "跟隨系統字型大小",
"followSystemFontScaleDesc": "按系統輔助功能字型大小自動放大",
"fixedLayoutNotice": "PDF 為固定排版格式,字型和排版設定不可用。",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/zh/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"showBottomTimeBattery": "底部时间与电量",
"volumeButtonsPageTurn": "音量键翻页",
"volumeButtonsPageTurnDesc": "开启后阅读时音量键用于上下翻页",
"smoothReading": "平滑阅读",
"smoothReadingDesc": "开启翻页过渡动画与滚动惯性,关闭可提升低性能设备流畅度",
"followSystemFontScale": "跟随系统字号",
"followSystemFontScaleDesc": "按系统辅助功能字号自动放大",
"fixedLayoutNotice": "PDF 为固定布局格式,字体和排版设置不可用。",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/stores/settings-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const defaultReadSettings: ReadSettings = {
showTopTitleProgress: true,
showBottomTimeBattery: true,
volumeButtonsPageTurn: false,
smoothReading: false,
defaultHighlightColor: "yellow",
followSystemFontScale: false,
};
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/types/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ export interface ReadSettings extends ViewSettings {
showBottomTimeBattery: boolean;
volumeButtonsPageTurn: boolean;
defaultHighlightColor?: HighlightColor;
/**
* Mobile-only opt-in: smooth reading — enables the foliate `animated`
* page-turn transition and the `scroll-inertia` finger-flick physics.
* Default false so existing users keep the current (performance-first)
* rendering path. Optional so existing persisted settings deserialize
* cleanly.
*/
smoothReading?: boolean;
/**
* Mobile-only opt-in: when true, the reader scales fontSize by the OS
* accessibility font scale (PixelRatio.getFontScale()) before rendering.
Expand Down
Loading