aksos-react-native-epub-reader 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +351 -2
- package/lib/EpubReader.d.ts +76 -0
- package/lib/EpubReader.js +284 -0
- package/lib/EpubReaderView.d.ts +31 -0
- package/lib/EpubReaderView.js +599 -0
- package/lib/assets/page-turn-1.wav +0 -0
- package/lib/assets/page-turn-2.wav +0 -0
- package/lib/assets/page-turn-3.wav +0 -0
- package/lib/assets/page-turn-4.wav +0 -0
- package/lib/engine/html.d.ts +1 -0
- package/lib/engine/html.js +5 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +34 -0
- package/lib/sound.d.ts +1 -0
- package/lib/sound.js +71 -0
- package/lib/strings.d.ts +94 -0
- package/lib/strings.js +96 -0
- package/lib/themes.d.ts +60 -0
- package/lib/themes.js +166 -0
- package/lib/types.d.ts +149 -0
- package/lib/types.js +2 -0
- package/lib/ui/AppearanceSheet.d.ts +15 -0
- package/lib/ui/AppearanceSheet.js +134 -0
- package/lib/ui/ContentsSheet.d.ts +27 -0
- package/lib/ui/ContentsSheet.js +89 -0
- package/lib/ui/CustomizeSheet.d.ts +16 -0
- package/lib/ui/CustomizeSheet.js +141 -0
- package/lib/ui/Glass.d.ts +15 -0
- package/lib/ui/Glass.js +27 -0
- package/lib/ui/HighlightMenu.d.ts +25 -0
- package/lib/ui/HighlightMenu.js +45 -0
- package/lib/ui/Icons.d.ts +17 -0
- package/lib/ui/Icons.js +193 -0
- package/lib/ui/LineGuide.d.ts +21 -0
- package/lib/ui/LineGuide.js +92 -0
- package/lib/ui/NoteEditor.d.ts +12 -0
- package/lib/ui/NoteEditor.js +63 -0
- package/lib/ui/Scrubber.d.ts +15 -0
- package/lib/ui/Scrubber.js +86 -0
- package/lib/ui/SearchSheet.d.ts +14 -0
- package/lib/ui/SearchSheet.js +79 -0
- package/lib/ui/Sheet.d.ts +19 -0
- package/lib/ui/Sheet.js +40 -0
- package/lib/ui/Slider.d.ts +14 -0
- package/lib/ui/Slider.js +53 -0
- package/package.json +76 -6
- package/src/EpubReader.tsx +356 -0
- package/src/EpubReaderView.tsx +865 -0
- package/src/assets/page-turn-1.wav +0 -0
- package/src/assets/page-turn-2.wav +0 -0
- package/src/assets/page-turn-3.wav +0 -0
- package/src/assets/page-turn-4.wav +0 -0
- package/src/engine/html.ts +2 -0
- package/src/engine/reader.js +2047 -0
- package/src/index.ts +9 -0
- package/src/sound.ts +66 -0
- package/src/strings.ts +187 -0
- package/src/themes.ts +188 -0
- package/src/types.ts +154 -0
- package/src/ui/AppearanceSheet.tsx +176 -0
- package/src/ui/ContentsSheet.tsx +146 -0
- package/src/ui/CustomizeSheet.tsx +191 -0
- package/src/ui/Glass.tsx +37 -0
- package/src/ui/HighlightMenu.tsx +66 -0
- package/src/ui/Icons.tsx +246 -0
- package/src/ui/LineGuide.tsx +87 -0
- package/src/ui/NoteEditor.tsx +57 -0
- package/src/ui/Scrubber.tsx +78 -0
- package/src/ui/SearchSheet.tsx +95 -0
- package/src/ui/Sheet.tsx +71 -0
- package/src/ui/Slider.tsx +30 -0
|
@@ -0,0 +1,865 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { AccessibilityInfo, ActivityIndicator, Alert, Animated, Linking, Platform, Pressable, Share, StatusBar, StyleSheet, Text, useColorScheme, useWindowDimensions, View } from 'react-native';
|
|
3
|
+
import { EpubReader, sourceKeyOf } from './EpubReader';
|
|
4
|
+
import type { EpubReaderHandle } from './EpubReader';
|
|
5
|
+
import { chromeColors, DEFAULT_SETTINGS, isDark, themeColors } from './themes';
|
|
6
|
+
import type {
|
|
7
|
+
Bookmark,
|
|
8
|
+
BookLocation,
|
|
9
|
+
BookMetadata,
|
|
10
|
+
EpubSource,
|
|
11
|
+
Highlight,
|
|
12
|
+
HighlightColor,
|
|
13
|
+
PageTurn,
|
|
14
|
+
ReaderSettings,
|
|
15
|
+
RelocateEvent,
|
|
16
|
+
SafeInsets,
|
|
17
|
+
SearchResult,
|
|
18
|
+
SelectionEvent,
|
|
19
|
+
TocItem
|
|
20
|
+
} from './types';
|
|
21
|
+
import { AppearanceSheet } from './ui/AppearanceSheet';
|
|
22
|
+
import { ContentsSheet } from './ui/ContentsSheet';
|
|
23
|
+
import { CustomizeSheet } from './ui/CustomizeSheet';
|
|
24
|
+
import { playPageTurn } from './sound';
|
|
25
|
+
import { LabelsProvider, mergeLabels, useLabels } from './strings';
|
|
26
|
+
import type { ReaderLabels } from './strings';
|
|
27
|
+
import { Glass } from './ui/Glass';
|
|
28
|
+
import { HighlightMenu } from './ui/HighlightMenu';
|
|
29
|
+
import { Icon } from './ui/Icons';
|
|
30
|
+
import { LineGuide } from './ui/LineGuide';
|
|
31
|
+
import type { DimLevel } from './ui/LineGuide';
|
|
32
|
+
import { NoteEditor } from './ui/NoteEditor';
|
|
33
|
+
import { SearchSheet } from './ui/SearchSheet';
|
|
34
|
+
|
|
35
|
+
export interface EpubReaderViewProps {
|
|
36
|
+
source: EpubSource;
|
|
37
|
+
/** shown in the Contents sheet until the book's own title is read */
|
|
38
|
+
title?: string;
|
|
39
|
+
/** Space for the status bar / home indicator (and notch in landscape). Use useSafeAreaInsets() from react-native-safe-area-context. */
|
|
40
|
+
safeInsets?: SafeInsets;
|
|
41
|
+
initialLocation?: BookLocation;
|
|
42
|
+
initialSettings?: Partial<ReaderSettings>;
|
|
43
|
+
initialHighlights?: Highlight[];
|
|
44
|
+
initialBookmarks?: Bookmark[];
|
|
45
|
+
onClose?: () => void;
|
|
46
|
+
onLocationChange?: (e: RelocateEvent) => void;
|
|
47
|
+
onHighlightsChange?: (list: Highlight[]) => void;
|
|
48
|
+
onBookmarksChange?: (list: Bookmark[]) => void;
|
|
49
|
+
onSettingsChange?: (s: ReaderSettings) => void;
|
|
50
|
+
onMetadata?: (m: BookMetadata) => void;
|
|
51
|
+
onCover?: (dataUri: string) => void;
|
|
52
|
+
onError?: (message: string) => void;
|
|
53
|
+
/** Texts of the interface; leave out what you do not translate (see ReaderLabels). */
|
|
54
|
+
labels?: Partial<ReaderLabels>;
|
|
55
|
+
/** Largest EPUB in bytes that will be opened (default 150 MB, 0 = no limit). */
|
|
56
|
+
maxFileSize?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const RESET_THEME: Partial<ReaderSettings> = {
|
|
60
|
+
fontId: 'original',
|
|
61
|
+
bold: false,
|
|
62
|
+
customize: false,
|
|
63
|
+
lineHeight: 1.5,
|
|
64
|
+
letterSpacing: 0,
|
|
65
|
+
wordSpacing: 0,
|
|
66
|
+
margins: 0,
|
|
67
|
+
columns: 'auto',
|
|
68
|
+
justify: false
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// expo-screen-orientation is optional (needed for the rotation lock button)
|
|
72
|
+
let ScreenOrientation: any = null;
|
|
73
|
+
try {
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
75
|
+
ScreenOrientation = require('expo-screen-orientation');
|
|
76
|
+
} catch {
|
|
77
|
+
ScreenOrientation = null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const DIM_IDS: { id: DimLevel; label: 'dimHigh' | 'dimMedium' | 'dimLow' | 'dimNone' }[] = [
|
|
81
|
+
{ id: 'high', label: 'dimHigh' },
|
|
82
|
+
{ id: 'medium', label: 'dimMedium' },
|
|
83
|
+
{ id: 'low', label: 'dimLow' },
|
|
84
|
+
{ id: 'none', label: 'dimNone' }
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
const SAMPLE = 'The reader turned the page slowly, listening to the wind move across the empty hills.';
|
|
88
|
+
const uid = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
|
|
89
|
+
|
|
90
|
+
// Used when the host passes no safeInsets. A guess from the screen size; the exact values come from react-native-safe-area-context.
|
|
91
|
+
function defaultInsets(width: number, height: number): SafeInsets {
|
|
92
|
+
if (Platform.OS !== 'ios') return { top: StatusBar.currentHeight || 24, bottom: 0 };
|
|
93
|
+
const long = Math.max(width, height);
|
|
94
|
+
const landscape = width > height;
|
|
95
|
+
const notch = long >= 812; // iPhone X and later (iPads are larger but have no notch: they are caught by the short side)
|
|
96
|
+
const phone = Math.min(width, height) < 600;
|
|
97
|
+
if (!phone) return { top: 24, bottom: 20 };
|
|
98
|
+
if (!notch) return { top: 20, bottom: 0 };
|
|
99
|
+
const top = long >= 852 ? 59 : 47;
|
|
100
|
+
return landscape ? { top: 0, bottom: 21, left: top, right: top } : { top, bottom: 34 };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
type SheetName = null | 'contents' | 'search' | 'appearance' | 'customize';
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Full reader screen. A different `source` (or Try again after an error) starts a fresh screen, so highlights,
|
|
107
|
+
* bookmarks and position of one book can never leak into another.
|
|
108
|
+
*/
|
|
109
|
+
export function EpubReaderView(props: EpubReaderViewProps) {
|
|
110
|
+
const [attempt, setAttempt] = useState(0);
|
|
111
|
+
const labels = useMemo(() => mergeLabels(props.labels), [props.labels]);
|
|
112
|
+
return (
|
|
113
|
+
<LabelsProvider value={labels}>
|
|
114
|
+
<ReaderScreen key={`${sourceKeyOf(props.source)}#${attempt}`} {...props} onRetry={() => setAttempt((a) => a + 1)} />
|
|
115
|
+
</LabelsProvider>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function ReaderScreen(props: EpubReaderViewProps & { onRetry: () => void }) {
|
|
120
|
+
const L = useLabels();
|
|
121
|
+
const screen = useWindowDimensions();
|
|
122
|
+
const safe = props.safeInsets || defaultInsets(screen.width, screen.height);
|
|
123
|
+
const systemDark = useColorScheme() === 'dark';
|
|
124
|
+
const reader = useRef<EpubReaderHandle>(null);
|
|
125
|
+
|
|
126
|
+
const [settings, setSettings] = useState<ReaderSettings>({ ...DEFAULT_SETTINGS, ...props.initialSettings });
|
|
127
|
+
const [highlights, setHighlights] = useState<Highlight[]>(props.initialHighlights || []);
|
|
128
|
+
const [bookmarks, setBookmarks] = useState<Bookmark[]>(props.initialBookmarks || []);
|
|
129
|
+
const [toc, setToc] = useState<TocItem[]>([]);
|
|
130
|
+
const [meta, setMeta] = useState<BookMetadata | null>(null);
|
|
131
|
+
const [rtl, setRtl] = useState(false);
|
|
132
|
+
const [loc, setLoc] = useState<RelocateEvent | null>(null);
|
|
133
|
+
const [index, setIndex] = useState<{ totalLength: number; cum: number[] } | null>(null);
|
|
134
|
+
const [cpp, setCpp] = useState(1200); // characters per page, measured from the chapters seen so far
|
|
135
|
+
// reading starts with nothing but the running header/footer; a tap shows the close button and the menu button
|
|
136
|
+
const [chrome, setChrome] = useState(false);
|
|
137
|
+
const [menuOpen, setMenuOpen] = useState(false);
|
|
138
|
+
const [pillW, setPillW] = useState(0);
|
|
139
|
+
const [lineGuide, setLineGuide] = useState(false);
|
|
140
|
+
const [dimLevel, setDimLevel] = useState<DimLevel>('high');
|
|
141
|
+
const [lineMenu, setLineMenu] = useState(false);
|
|
142
|
+
const [rotLocked, setRotLocked] = useState(false);
|
|
143
|
+
const [returnTo, setReturnTo] = useState<{ spine: number; offset: number; page: number } | null>(null);
|
|
144
|
+
const [sheet, setSheet] = useState<SheetName>(null);
|
|
145
|
+
const [active, setActive] = useState<{ id: string; rect: SelectionEvent['rect'] } | null>(null);
|
|
146
|
+
const [selection, setSelection] = useState<SelectionEvent | null>(null);
|
|
147
|
+
const [noteFor, setNoteFor] = useState<string | null>(null);
|
|
148
|
+
const [results, setResults] = useState<SearchResult[]>([]);
|
|
149
|
+
const [searching, setSearching] = useState(false);
|
|
150
|
+
const [error, setError] = useState<string | null>(null);
|
|
151
|
+
// the book could not be opened (or the reader engine stopped): a full screen with a way out
|
|
152
|
+
const [fatal, setFatal] = useState<string | null>(null);
|
|
153
|
+
const [loaded, setLoaded] = useState(false);
|
|
154
|
+
const [reduceMotion, setReduceMotion] = useState(false);
|
|
155
|
+
const searchId = useRef(0);
|
|
156
|
+
const latestProps = useRef(props);
|
|
157
|
+
latestProps.current = props;
|
|
158
|
+
const settingsRef = useRef(settings);
|
|
159
|
+
const highlightsRef = useRef(highlights);
|
|
160
|
+
const bookmarksRef = useRef(bookmarks);
|
|
161
|
+
const lockedByUs = useRef(false);
|
|
162
|
+
const seen = useRef<Record<number, { len: number; pc: number }>>({});
|
|
163
|
+
const layoutKey = useRef('');
|
|
164
|
+
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
let on = true;
|
|
167
|
+
AccessibilityInfo.isReduceMotionEnabled?.().then((v) => on && setReduceMotion(!!v)).catch(() => undefined);
|
|
168
|
+
const sub = AccessibilityInfo.addEventListener?.('reduceMotionChanged', (v: boolean) => setReduceMotion(!!v));
|
|
169
|
+
return () => {
|
|
170
|
+
on = false;
|
|
171
|
+
sub?.remove?.();
|
|
172
|
+
};
|
|
173
|
+
}, []);
|
|
174
|
+
// people who asked for less motion get the fade instead of the curl or slide
|
|
175
|
+
const readerSettings = useMemo(
|
|
176
|
+
() => (reduceMotion && (settings.pageTurn === 'curl' || settings.pageTurn === 'slide') ? { ...settings, pageTurn: 'fade' as PageTurn } : settings),
|
|
177
|
+
[settings, reduceMotion]
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const dark = isDark(settings, systemDark);
|
|
181
|
+
const page = themeColors(settings, systemDark);
|
|
182
|
+
const colors = useMemo(() => chromeColors(page, dark), [page, dark]);
|
|
183
|
+
|
|
184
|
+
// ----- chrome visibility animation
|
|
185
|
+
const fade = useRef(new Animated.Value(1)).current;
|
|
186
|
+
useEffect(() => {
|
|
187
|
+
Animated.timing(fade, { toValue: chrome ? 1 : 0, duration: 180, useNativeDriver: true }).start();
|
|
188
|
+
}, [chrome, fade]);
|
|
189
|
+
const fadeOut = fade.interpolate({ inputRange: [0, 1], outputRange: [1, 0] });
|
|
190
|
+
const menuFade = useRef(new Animated.Value(0)).current;
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
Animated.timing(menuFade, { toValue: menuOpen ? 1 : 0, duration: 160, useNativeDriver: true }).start();
|
|
193
|
+
}, [menuOpen, menuFade]);
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
if (!chrome) setMenuOpen(false);
|
|
196
|
+
}, [chrome]);
|
|
197
|
+
|
|
198
|
+
// ----- persistence helpers
|
|
199
|
+
// The next list is computed from a ref and the host is told outside of any state updater, so a callback
|
|
200
|
+
// never runs during render (StrictMode runs updaters twice) and quick successive edits never lose each other.
|
|
201
|
+
const updateHighlights = useCallback((fn: (prev: Highlight[]) => Highlight[]) => {
|
|
202
|
+
const next = fn(highlightsRef.current);
|
|
203
|
+
highlightsRef.current = next;
|
|
204
|
+
setHighlights(next);
|
|
205
|
+
latestProps.current.onHighlightsChange?.(next);
|
|
206
|
+
}, []);
|
|
207
|
+
const updateBookmarks = useCallback((fn: (prev: Bookmark[]) => Bookmark[]) => {
|
|
208
|
+
const next = fn(bookmarksRef.current);
|
|
209
|
+
bookmarksRef.current = next;
|
|
210
|
+
setBookmarks(next);
|
|
211
|
+
latestProps.current.onBookmarksChange?.(next);
|
|
212
|
+
}, []);
|
|
213
|
+
const changeSettings = useCallback((patch: Partial<ReaderSettings>) => {
|
|
214
|
+
const next = { ...settingsRef.current, ...patch };
|
|
215
|
+
settingsRef.current = next;
|
|
216
|
+
setSettings(next);
|
|
217
|
+
latestProps.current.onSettingsChange?.(next);
|
|
218
|
+
}, []);
|
|
219
|
+
|
|
220
|
+
// ----- book page numbers (estimated from characters per page)
|
|
221
|
+
const onRelocate = (e: RelocateEvent) => {
|
|
222
|
+
const key = [settings.fontSize, settings.fontId, settings.lineHeight, settings.letterSpacing, settings.wordSpacing, settings.margins, settings.customize, settings.columns, settings.bold, settings.pageTurn === 'scroll'].join('|');
|
|
223
|
+
if (key !== layoutKey.current) {
|
|
224
|
+
layoutKey.current = key;
|
|
225
|
+
seen.current = {};
|
|
226
|
+
}
|
|
227
|
+
seen.current[e.spine] = { len: e.textLength, pc: e.pageCount };
|
|
228
|
+
let len = 0;
|
|
229
|
+
let pc = 0;
|
|
230
|
+
Object.values(seen.current).forEach((v) => {
|
|
231
|
+
len += v.len;
|
|
232
|
+
pc += v.pc;
|
|
233
|
+
});
|
|
234
|
+
const next = pc > 0 && len > 0 ? len / pc : 1200;
|
|
235
|
+
setCpp((old) => (Math.abs(old - next) / next > 0.01 ? next : old));
|
|
236
|
+
setLoc(e);
|
|
237
|
+
setLoaded(true);
|
|
238
|
+
setActive(null);
|
|
239
|
+
props.onLocationChange?.(e);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const pageOf = useCallback(
|
|
243
|
+
(spine: number, offset: number) => {
|
|
244
|
+
if (!index) return spine + 1;
|
|
245
|
+
return Math.round(((index.cum[spine] || 0) + offset) / cpp) + 1;
|
|
246
|
+
},
|
|
247
|
+
[index, cpp]
|
|
248
|
+
);
|
|
249
|
+
const totalPages = index ? Math.max(1, Math.round(index.totalLength / cpp)) : loc ? loc.pageCount * loc.spineCount : 1;
|
|
250
|
+
const curPage = loc ? Math.min(totalPages, pageOf(loc.spine, loc.offset)) : 1;
|
|
251
|
+
const percent = Math.round((loc?.progress ?? 0) * 100);
|
|
252
|
+
const pagesLeft = loc ? Math.max(0, loc.pageCount - loc.page - 1) : 0;
|
|
253
|
+
|
|
254
|
+
// header / footer drawn on the page: chapter title + page number, or "N pages left" + "x of y" while the controls are shown
|
|
255
|
+
useEffect(() => {
|
|
256
|
+
if (!loc) return;
|
|
257
|
+
const header = chrome ? (pagesLeft === 0 ? L.lastPageInChapter : L.pagesLeft(pagesLeft)) : loc.chapter;
|
|
258
|
+
const footer = chrome ? L.pageOfTotal(curPage, totalPages) : L.formatNumber(curPage);
|
|
259
|
+
reader.current?.setLabels(header, footer);
|
|
260
|
+
}, [chrome, loc, curPage, totalPages, pagesLeft, L]);
|
|
261
|
+
|
|
262
|
+
// ----- bookmarks
|
|
263
|
+
const bookmarkHere = useMemo(
|
|
264
|
+
() => (loc ? bookmarks.filter((b) => b.spine === loc.spine && b.offset >= loc.offset && b.offset < Math.max(loc.end, loc.offset + 1)) : []),
|
|
265
|
+
[bookmarks, loc]
|
|
266
|
+
);
|
|
267
|
+
const toggleBookmark = () => {
|
|
268
|
+
if (!loc) return;
|
|
269
|
+
if (bookmarkHere.length) {
|
|
270
|
+
const ids = new Set(bookmarkHere.map((b) => b.id));
|
|
271
|
+
updateBookmarks((prev) => prev.filter((b) => !ids.has(b.id)));
|
|
272
|
+
} else {
|
|
273
|
+
updateBookmarks((prev) => [
|
|
274
|
+
...prev,
|
|
275
|
+
{ id: uid(), spine: loc.spine, offset: loc.offset, chapter: loc.chapter, excerpt: loc.excerpt, progress: loc.progress, createdAt: Date.now() }
|
|
276
|
+
]);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// ----- highlights
|
|
281
|
+
const createHighlight = (sel: SelectionEvent, withNote: boolean) => {
|
|
282
|
+
setSelection(null);
|
|
283
|
+
const h: Highlight = {
|
|
284
|
+
id: uid(),
|
|
285
|
+
spine: sel.spine,
|
|
286
|
+
start: sel.start,
|
|
287
|
+
end: sel.end,
|
|
288
|
+
text: sel.text.replace(/\s+/g, ' ').trim(),
|
|
289
|
+
color: 'yellow',
|
|
290
|
+
chapter: loc?.chapter,
|
|
291
|
+
createdAt: Date.now()
|
|
292
|
+
};
|
|
293
|
+
updateHighlights((prev) => [...prev, h]);
|
|
294
|
+
reader.current?.clearSelection();
|
|
295
|
+
if (withNote) setNoteFor(h.id);
|
|
296
|
+
else setActive({ id: h.id, rect: sel.rect });
|
|
297
|
+
};
|
|
298
|
+
const patchHighlight = (id: string, patch: Partial<Highlight>) =>
|
|
299
|
+
updateHighlights((prev) => prev.map((h) => (h.id === id ? { ...h, ...patch } : h)));
|
|
300
|
+
const removeHighlight = (id: string) => {
|
|
301
|
+
updateHighlights((prev) => prev.filter((h) => h.id !== id));
|
|
302
|
+
setActive(null);
|
|
303
|
+
};
|
|
304
|
+
const activeHighlight = active ? highlights.find((h) => h.id === active.id) : undefined;
|
|
305
|
+
const noteHighlight = noteFor ? highlights.find((h) => h.id === noteFor) : undefined;
|
|
306
|
+
|
|
307
|
+
// ----- search
|
|
308
|
+
const runSearch = (q: string) => {
|
|
309
|
+
const id = ++searchId.current;
|
|
310
|
+
setResults([]);
|
|
311
|
+
if (q.trim().length < 2) {
|
|
312
|
+
setSearching(false);
|
|
313
|
+
reader.current?.cancelSearch(id);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
setSearching(true);
|
|
317
|
+
reader.current?.search(q, id);
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const closeSheet = () => setSheet(null);
|
|
321
|
+
// remember where we were so the "back" pill can return after a jump (contents, search, bookmark ...)
|
|
322
|
+
const jump = (to: Parameters<EpubReaderHandle['goTo']>[0]) => {
|
|
323
|
+
if (loc) setReturnTo({ spine: loc.spine, offset: loc.offset, page: curPage });
|
|
324
|
+
setChrome(false);
|
|
325
|
+
reader.current?.goTo(to);
|
|
326
|
+
};
|
|
327
|
+
// two modals cannot be presented at once on iOS, so switch sheets after the first one is gone
|
|
328
|
+
const switchSheet = (to: SheetName) => {
|
|
329
|
+
setSheet(null);
|
|
330
|
+
setTimeout(() => setSheet(to), 380);
|
|
331
|
+
};
|
|
332
|
+
const toggleRotationLock = async () => {
|
|
333
|
+
if (!ScreenOrientation) {
|
|
334
|
+
Alert.alert(L.rotationLock, L.rotationLockNeedsPackage);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
try {
|
|
338
|
+
if (rotLocked) {
|
|
339
|
+
await ScreenOrientation.unlockAsync();
|
|
340
|
+
lockedByUs.current = false;
|
|
341
|
+
setRotLocked(false);
|
|
342
|
+
} else {
|
|
343
|
+
const o = await ScreenOrientation.getOrientationAsync();
|
|
344
|
+
const O = ScreenOrientation.Orientation;
|
|
345
|
+
const L = ScreenOrientation.OrientationLock;
|
|
346
|
+
await ScreenOrientation.lockAsync(o === O.LANDSCAPE_LEFT ? L.LANDSCAPE_LEFT : o === O.LANDSCAPE_RIGHT ? L.LANDSCAPE_RIGHT : L.PORTRAIT_UP);
|
|
347
|
+
lockedByUs.current = true;
|
|
348
|
+
setRotLocked(true);
|
|
349
|
+
}
|
|
350
|
+
} catch {
|
|
351
|
+
// not supported on this device
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
useEffect(
|
|
355
|
+
() => () => {
|
|
356
|
+
// only release a lock this reader set: the host app may have its own orientation policy
|
|
357
|
+
if (ScreenOrientation && lockedByUs.current) ScreenOrientation.unlockAsync().catch(() => undefined);
|
|
358
|
+
},
|
|
359
|
+
[]
|
|
360
|
+
);
|
|
361
|
+
const onLineGuideButton = () => {
|
|
362
|
+
setMenuOpen(false);
|
|
363
|
+
if (!lineGuide) {
|
|
364
|
+
setLineGuide(true);
|
|
365
|
+
setChrome(false);
|
|
366
|
+
} else setLineMenu(true);
|
|
367
|
+
};
|
|
368
|
+
const openLink = (href: string) => {
|
|
369
|
+
if (!/^(https?|mailto):/i.test(href)) return;
|
|
370
|
+
Alert.alert(L.openLink, href, [
|
|
371
|
+
{ text: L.cancel, style: 'cancel' },
|
|
372
|
+
{ text: L.open, onPress: () => Linking.openURL(href).catch(() => undefined) }
|
|
373
|
+
]);
|
|
374
|
+
};
|
|
375
|
+
const share = () => {
|
|
376
|
+
const text = [loc?.excerpt, meta?.title && `— ${meta.title}`].filter(Boolean).join(' ');
|
|
377
|
+
Share.share({ message: text || meta?.title || '' }).catch(() => undefined);
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const progressFill = Math.max(0, Math.min(1, loc?.progress ?? 0));
|
|
381
|
+
const tx = colors.text;
|
|
382
|
+
|
|
383
|
+
return (
|
|
384
|
+
<View style={[styles.root, { backgroundColor: page.bg }]}>
|
|
385
|
+
<EpubReader
|
|
386
|
+
ref={reader}
|
|
387
|
+
source={props.source}
|
|
388
|
+
settings={readerSettings}
|
|
389
|
+
systemDark={systemDark}
|
|
390
|
+
safeInsets={safe}
|
|
391
|
+
initialLocation={props.initialLocation}
|
|
392
|
+
highlights={highlights}
|
|
393
|
+
maxFileSize={props.maxFileSize}
|
|
394
|
+
onReady={({ metadata, rtl: isRtl }) => {
|
|
395
|
+
setMeta(metadata);
|
|
396
|
+
setRtl(isRtl);
|
|
397
|
+
props.onMetadata?.(metadata);
|
|
398
|
+
}}
|
|
399
|
+
onToc={setToc}
|
|
400
|
+
onCover={props.onCover}
|
|
401
|
+
onIndexed={setIndex}
|
|
402
|
+
onRelocate={onRelocate}
|
|
403
|
+
onPageTurn={() => {
|
|
404
|
+
if (settings.pageSound) playPageTurn();
|
|
405
|
+
}}
|
|
406
|
+
onTap={() => {
|
|
407
|
+
if (active) setActive(null);
|
|
408
|
+
else if (menuOpen) setMenuOpen(false);
|
|
409
|
+
else setChrome((c) => !c);
|
|
410
|
+
}}
|
|
411
|
+
onHighlightTap={(id, rect) => setActive({ id, rect })}
|
|
412
|
+
onSelection={(sel) => {
|
|
413
|
+
setSelection(sel);
|
|
414
|
+
if (sel) {
|
|
415
|
+
setChrome(false);
|
|
416
|
+
setActive(null);
|
|
417
|
+
}
|
|
418
|
+
}}
|
|
419
|
+
onLink={openLink}
|
|
420
|
+
onLinkJump={(from) => setReturnTo({ spine: from.spine, offset: from.offset, page: pageOf(from.spine, from.offset) })}
|
|
421
|
+
onDirectionChange={setRtl}
|
|
422
|
+
onSearchResults={(id, found, done) => {
|
|
423
|
+
if (id !== searchId.current) return;
|
|
424
|
+
setResults((prev) => prev.concat(found));
|
|
425
|
+
if (done) setSearching(false);
|
|
426
|
+
}}
|
|
427
|
+
onError={(m, info) => {
|
|
428
|
+
if (info.fatal || !loaded) setFatal(m);
|
|
429
|
+
else setError(m);
|
|
430
|
+
props.onError?.(m);
|
|
431
|
+
}}
|
|
432
|
+
/>
|
|
433
|
+
|
|
434
|
+
{/* screen readers cannot tap the page: this reveals the controls and turns pages */}
|
|
435
|
+
{!chrome && (
|
|
436
|
+
<View
|
|
437
|
+
pointerEvents="none"
|
|
438
|
+
accessible
|
|
439
|
+
accessibilityRole="button"
|
|
440
|
+
accessibilityLabel={L.readerMenu}
|
|
441
|
+
accessibilityActions={[
|
|
442
|
+
{ name: 'activate', label: L.readerMenu },
|
|
443
|
+
{ name: 'increment', label: 'Next page' },
|
|
444
|
+
{ name: 'decrement', label: 'Previous page' }
|
|
445
|
+
]}
|
|
446
|
+
onAccessibilityAction={(e) => {
|
|
447
|
+
const a = e.nativeEvent.actionName;
|
|
448
|
+
if (a === 'increment') reader.current?.next();
|
|
449
|
+
else if (a === 'decrement') reader.current?.prev();
|
|
450
|
+
else setChrome(true);
|
|
451
|
+
}}
|
|
452
|
+
style={[styles.a11yHandle, { bottom: safe.bottom, left: safe.left || 0 }]}
|
|
453
|
+
/>
|
|
454
|
+
)}
|
|
455
|
+
|
|
456
|
+
{/* page brightness */}
|
|
457
|
+
<View pointerEvents="none" style={[StyleSheet.absoluteFill, { backgroundColor: '#000000', opacity: (1 - settings.brightness) * 0.75 }]} />
|
|
458
|
+
|
|
459
|
+
{/* line guide */}
|
|
460
|
+
{lineGuide && (
|
|
461
|
+
<LineGuide
|
|
462
|
+
bg={page.bg}
|
|
463
|
+
dark={dark}
|
|
464
|
+
dim={dimLevel}
|
|
465
|
+
lineHeight={settings.fontSize * (settings.customize ? settings.lineHeight : 1.5)}
|
|
466
|
+
minY={safe.top + 30}
|
|
467
|
+
maxY={screen.height - safe.bottom - 30}
|
|
468
|
+
/>
|
|
469
|
+
)}
|
|
470
|
+
|
|
471
|
+
{/* bookmark ribbon while the controls are hidden */}
|
|
472
|
+
{bookmarkHere.length > 0 && (
|
|
473
|
+
<Animated.View pointerEvents="none" style={[styles.ribbon, { right: 22, opacity: fadeOut }]}>
|
|
474
|
+
<View style={styles.ribbonBody} />
|
|
475
|
+
<View style={styles.ribbonNotch} />
|
|
476
|
+
</Animated.View>
|
|
477
|
+
)}
|
|
478
|
+
|
|
479
|
+
{/* close */}
|
|
480
|
+
<Animated.View pointerEvents={chrome ? 'auto' : 'none'} {...hiddenA11y(!chrome)} style={[styles.closeWrap, { top: safe.top + 2, right: 16 + (safe.right || 0), opacity: fade }]}>
|
|
481
|
+
<Pressable onPress={props.onClose} hitSlop={10} accessibilityRole="button" accessibilityLabel={L.closeBook}>
|
|
482
|
+
<Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.circle}>
|
|
483
|
+
<Icon name="close" color={tx} size={22} />
|
|
484
|
+
</Glass>
|
|
485
|
+
</Pressable>
|
|
486
|
+
</Animated.View>
|
|
487
|
+
|
|
488
|
+
{/* back to where we came from, like the "193" pill in Books */}
|
|
489
|
+
{returnTo && (
|
|
490
|
+
<Animated.View pointerEvents={chrome ? 'auto' : 'none'} {...hiddenA11y(!chrome)} style={[styles.returnWrap, { top: safe.top + 2, left: 16 + (safe.left || 0), opacity: fade }]}>
|
|
491
|
+
<Pressable
|
|
492
|
+
onPress={() => {
|
|
493
|
+
reader.current?.goTo({ spine: returnTo.spine, offset: returnTo.offset });
|
|
494
|
+
setReturnTo(null);
|
|
495
|
+
}}
|
|
496
|
+
hitSlop={8}
|
|
497
|
+
accessibilityRole="button"
|
|
498
|
+
accessibilityLabel={L.returnToPage(returnTo.page)}
|
|
499
|
+
>
|
|
500
|
+
<Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.returnPill}>
|
|
501
|
+
<Icon name="undo" color={tx} size={22} />
|
|
502
|
+
<Text style={{ color: tx, fontSize: 20, marginStart: 8 }} maxFontSizeMultiplier={1.3}>{L.formatNumber(returnTo.page)}</Text>
|
|
503
|
+
</Glass>
|
|
504
|
+
</Pressable>
|
|
505
|
+
</Animated.View>
|
|
506
|
+
)}
|
|
507
|
+
|
|
508
|
+
{/* menu button (collapsed) */}
|
|
509
|
+
<Animated.View
|
|
510
|
+
pointerEvents={chrome && !menuOpen ? 'auto' : 'none'}
|
|
511
|
+
{...hiddenA11y(!(chrome && !menuOpen))}
|
|
512
|
+
style={[styles.menuBtnWrap, { bottom: safe.bottom + 14, right: 16 + (safe.right || 0), opacity: Animated.multiply(fade, Animated.subtract(1, menuFade)) }]}
|
|
513
|
+
>
|
|
514
|
+
<Pressable onPress={() => setMenuOpen(true)} accessibilityRole="button" accessibilityLabel={L.readerMenu}>
|
|
515
|
+
<Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.menuBtn}>
|
|
516
|
+
<Icon name="list" color={tx} size={24} />
|
|
517
|
+
</Glass>
|
|
518
|
+
</Pressable>
|
|
519
|
+
</Animated.View>
|
|
520
|
+
|
|
521
|
+
{/* floating controls (expanded menu) */}
|
|
522
|
+
<Animated.View pointerEvents={chrome && menuOpen ? 'box-none' : 'none'} {...hiddenA11y(!(chrome && menuOpen))} style={[styles.controls, { bottom: safe.bottom + 44, right: 16 + (safe.right || 0), opacity: menuFade }]}>
|
|
523
|
+
<Pressable
|
|
524
|
+
onPress={() => {
|
|
525
|
+
setMenuOpen(false);
|
|
526
|
+
setSheet('contents');
|
|
527
|
+
}}
|
|
528
|
+
accessibilityRole="button"
|
|
529
|
+
accessibilityLabel={L.contents}
|
|
530
|
+
style={styles.pillWrap}
|
|
531
|
+
>
|
|
532
|
+
<Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.pill}>
|
|
533
|
+
<View style={styles.pillRow} onLayout={(e) => setPillW(e.nativeEvent.layout.width)}>
|
|
534
|
+
<Text style={[styles.pillText, { color: tx }]} maxFontSizeMultiplier={1.3}>{L.contents} • {L.formatNumber(percent)}%</Text>
|
|
535
|
+
<Icon name="list" color={tx} size={24} />
|
|
536
|
+
</View>
|
|
537
|
+
{/* progress fill with inverted text on top of it */}
|
|
538
|
+
<View
|
|
539
|
+
pointerEvents="none"
|
|
540
|
+
style={[styles.fill, { width: progressFill * pillW, backgroundColor: dark ? 'rgba(255,255,255,0.35)' : '#1c1408', [rtl ? 'right' : 'left']: 0 }]}
|
|
541
|
+
>
|
|
542
|
+
<View style={[styles.pillRow, { position: 'absolute', top: 0, width: pillW, [rtl ? 'right' : 'left']: 0 }]}>
|
|
543
|
+
<Text style={[styles.pillText, { color: dark ? tx : '#ffffff' }]} maxFontSizeMultiplier={1.3}>{L.contents} • {L.formatNumber(percent)}%</Text>
|
|
544
|
+
<Icon name="list" color={dark ? tx : '#ffffff'} size={24} />
|
|
545
|
+
</View>
|
|
546
|
+
</View>
|
|
547
|
+
</Glass>
|
|
548
|
+
</Pressable>
|
|
549
|
+
|
|
550
|
+
<Pressable
|
|
551
|
+
onPress={() => {
|
|
552
|
+
setMenuOpen(false);
|
|
553
|
+
setSheet('search');
|
|
554
|
+
}}
|
|
555
|
+
accessibilityRole="button"
|
|
556
|
+
accessibilityLabel={L.searchBook}
|
|
557
|
+
style={styles.pillWrap}
|
|
558
|
+
>
|
|
559
|
+
<Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.pill}>
|
|
560
|
+
<View style={styles.pillRow}>
|
|
561
|
+
<Text style={[styles.pillText, { color: tx }]} maxFontSizeMultiplier={1.3}>{L.searchBook}</Text>
|
|
562
|
+
<Icon name="search" color={tx} size={24} />
|
|
563
|
+
</View>
|
|
564
|
+
</Glass>
|
|
565
|
+
</Pressable>
|
|
566
|
+
|
|
567
|
+
<Pressable
|
|
568
|
+
onPress={() => {
|
|
569
|
+
setMenuOpen(false);
|
|
570
|
+
setSheet('appearance');
|
|
571
|
+
}}
|
|
572
|
+
accessibilityRole="button"
|
|
573
|
+
accessibilityLabel={L.themesSettings}
|
|
574
|
+
style={styles.pillWrap}
|
|
575
|
+
>
|
|
576
|
+
<Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.pill}>
|
|
577
|
+
<View style={styles.pillRow}>
|
|
578
|
+
<Text style={[styles.pillText, { color: tx }]} maxFontSizeMultiplier={1.3}>{L.themesSettings}</Text>
|
|
579
|
+
<Icon name="textSize" color={tx} size={26} />
|
|
580
|
+
</View>
|
|
581
|
+
</Glass>
|
|
582
|
+
</Pressable>
|
|
583
|
+
|
|
584
|
+
<View style={styles.roundRow}>
|
|
585
|
+
<Pressable onPress={share} style={styles.roundWrap} accessibilityRole="button" accessibilityLabel={L.share}>
|
|
586
|
+
<Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.round}>
|
|
587
|
+
<Icon name="share" color={tx} size={24} />
|
|
588
|
+
</Glass>
|
|
589
|
+
</Pressable>
|
|
590
|
+
<Pressable onPress={toggleRotationLock} style={styles.roundWrap} accessibilityRole="button" accessibilityLabel={L.rotationLock} accessibilityState={{ selected: rotLocked }}>
|
|
591
|
+
<Glass dark={dark} background={rotLocked ? (dark ? 'rgba(255,255,255,0.35)' : 'rgba(0,0,0,0.18)') : colors.glass} border={colors.glassBorder} style={styles.round}>
|
|
592
|
+
<Icon name="rotationLock" color={tx} size={26} active={rotLocked} />
|
|
593
|
+
</Glass>
|
|
594
|
+
</Pressable>
|
|
595
|
+
<Pressable onPress={onLineGuideButton} style={styles.roundWrap} accessibilityRole="button" accessibilityLabel={L.lineGuide} accessibilityState={{ selected: lineGuide }}>
|
|
596
|
+
<Glass dark={dark} background={lineGuide ? (dark ? 'rgba(255,255,255,0.35)' : 'rgba(0,0,0,0.18)') : colors.glass} border={colors.glassBorder} style={styles.round}>
|
|
597
|
+
<Icon name="lineGuide" color={tx} size={26} active={lineGuide} />
|
|
598
|
+
</Glass>
|
|
599
|
+
</Pressable>
|
|
600
|
+
<Pressable onPress={toggleBookmark} style={styles.roundWrap} accessibilityRole="button" accessibilityLabel={L.bookmarkPage} accessibilityState={{ selected: bookmarkHere.length > 0 }}>
|
|
601
|
+
<Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.round}>
|
|
602
|
+
<Icon name="bookmark" color={tx} size={24} active={bookmarkHere.length > 0} />
|
|
603
|
+
</Glass>
|
|
604
|
+
</Pressable>
|
|
605
|
+
</View>
|
|
606
|
+
</Animated.View>
|
|
607
|
+
|
|
608
|
+
{selection && !active && !noteFor && (() => {
|
|
609
|
+
const w = Math.min(Math.max(214, screen.width * 0.5), screen.width - 16);
|
|
610
|
+
const r = selection.rect;
|
|
611
|
+
const left = Math.max(8, Math.min(screen.width - w - 8, r.x + r.width / 2 - w / 2));
|
|
612
|
+
// the system callout (Copy / Look Up) sits above the selection, so ours goes below it
|
|
613
|
+
const below = r.y + r.height + 16;
|
|
614
|
+
const top = below + 54 > screen.height - safe.bottom ? Math.max(safe.top + 8, r.y - 120) : below;
|
|
615
|
+
return (
|
|
616
|
+
<Glass dark={dark} background={colors.sheetGlass} border={colors.glassBorder} intensity={55} style={[styles.selBar, { left, top, width: w }]}>
|
|
617
|
+
<Pressable
|
|
618
|
+
style={styles.selBtn}
|
|
619
|
+
onPress={() => createHighlight(selection, false)}
|
|
620
|
+
accessibilityRole="button"
|
|
621
|
+
accessibilityLabel={L.highlight}
|
|
622
|
+
>
|
|
623
|
+
<Icon name="highlighter" color={tx} size={22} />
|
|
624
|
+
<Text style={[styles.selText, { color: tx }]} numberOfLines={1} maxFontSizeMultiplier={1.2}>{L.highlight}</Text>
|
|
625
|
+
</Pressable>
|
|
626
|
+
<View style={[styles.selSep, { backgroundColor: colors.separator }]} />
|
|
627
|
+
<Pressable
|
|
628
|
+
style={styles.selBtn}
|
|
629
|
+
onPress={() => createHighlight(selection, true)}
|
|
630
|
+
accessibilityRole="button"
|
|
631
|
+
accessibilityLabel={L.addNote}
|
|
632
|
+
>
|
|
633
|
+
<Icon name="pencil" color={tx} size={22} />
|
|
634
|
+
<Text style={[styles.selText, { color: tx }]} numberOfLines={1} maxFontSizeMultiplier={1.2}>{L.note}</Text>
|
|
635
|
+
</Pressable>
|
|
636
|
+
</Glass>
|
|
637
|
+
);
|
|
638
|
+
})()}
|
|
639
|
+
|
|
640
|
+
{activeHighlight && active && (
|
|
641
|
+
<HighlightMenu
|
|
642
|
+
highlight={activeHighlight}
|
|
643
|
+
rect={active.rect}
|
|
644
|
+
screen={screen}
|
|
645
|
+
colors={colors}
|
|
646
|
+
onColor={(c: HighlightColor) => patchHighlight(activeHighlight.id, { color: c })}
|
|
647
|
+
onToggleUnderline={() => patchHighlight(activeHighlight.id, { style: activeHighlight.style === 'underline' ? 'highlight' : 'underline' })}
|
|
648
|
+
onNote={() => {
|
|
649
|
+
setNoteFor(activeHighlight.id);
|
|
650
|
+
setActive(null);
|
|
651
|
+
}}
|
|
652
|
+
onDelete={() => removeHighlight(activeHighlight.id)}
|
|
653
|
+
onDismiss={() => setActive(null)}
|
|
654
|
+
/>
|
|
655
|
+
)}
|
|
656
|
+
|
|
657
|
+
{/* opening the book: shown until the first page is there */}
|
|
658
|
+
{!loaded && !fatal && (
|
|
659
|
+
<View style={[StyleSheet.absoluteFill, styles.splash, { backgroundColor: page.bg }]} pointerEvents="box-none">
|
|
660
|
+
<ActivityIndicator color={page.fg} />
|
|
661
|
+
<Text style={{ color: page.fg, opacity: 0.6, marginTop: 12, fontSize: 15 }} maxFontSizeMultiplier={1.3}>
|
|
662
|
+
{L.loading}
|
|
663
|
+
</Text>
|
|
664
|
+
<Pressable
|
|
665
|
+
onPress={props.onClose}
|
|
666
|
+
hitSlop={10}
|
|
667
|
+
accessibilityRole="button"
|
|
668
|
+
accessibilityLabel={L.closeBook}
|
|
669
|
+
style={[styles.splashClose, { top: safe.top + 2, right: 16 + (safe.right || 0) }]}
|
|
670
|
+
>
|
|
671
|
+
<Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.circle}>
|
|
672
|
+
<Icon name="close" color={tx} size={22} />
|
|
673
|
+
</Glass>
|
|
674
|
+
</Pressable>
|
|
675
|
+
</View>
|
|
676
|
+
)}
|
|
677
|
+
|
|
678
|
+
{/* the book cannot be shown: always a way back */}
|
|
679
|
+
{!!fatal && (
|
|
680
|
+
<View style={[StyleSheet.absoluteFill, styles.splash, { backgroundColor: page.bg }]} accessibilityViewIsModal>
|
|
681
|
+
<Text style={{ color: page.fg, fontSize: 18, fontWeight: '600', textAlign: 'center' }} accessibilityRole="header">
|
|
682
|
+
{L.couldNotOpen}
|
|
683
|
+
</Text>
|
|
684
|
+
<Text style={{ color: page.fg, opacity: 0.7, fontSize: 15, textAlign: 'center', marginTop: 10 }} accessibilityRole="alert">
|
|
685
|
+
{fatal}
|
|
686
|
+
</Text>
|
|
687
|
+
<View style={styles.fatalButtons}>
|
|
688
|
+
<Pressable onPress={props.onRetry} style={[styles.fatalBtn, { backgroundColor: colors.accent }]} accessibilityRole="button">
|
|
689
|
+
<Text style={{ color: '#ffffff', fontSize: 16, fontWeight: '600' }}>{L.tryAgain}</Text>
|
|
690
|
+
</Pressable>
|
|
691
|
+
{!!props.onClose && (
|
|
692
|
+
<Pressable onPress={props.onClose} style={[styles.fatalBtn, { backgroundColor: colors.card }]} accessibilityRole="button">
|
|
693
|
+
<Text style={{ color: tx, fontSize: 16, fontWeight: '600' }}>{L.close}</Text>
|
|
694
|
+
</Pressable>
|
|
695
|
+
)}
|
|
696
|
+
</View>
|
|
697
|
+
</View>
|
|
698
|
+
)}
|
|
699
|
+
|
|
700
|
+
{error && !fatal && (
|
|
701
|
+
<View style={[styles.error, { backgroundColor: colors.sheet }]} accessibilityRole="alert">
|
|
702
|
+
<Text style={{ color: colors.text, fontSize: 15, textAlign: 'center' }}>{error}</Text>
|
|
703
|
+
<Pressable onPress={() => setError(null)} style={{ marginTop: 12, padding: 8 }} accessibilityRole="button">
|
|
704
|
+
<Text style={{ color: colors.accent, fontSize: 16 }}>{L.ok}</Text>
|
|
705
|
+
</Pressable>
|
|
706
|
+
</View>
|
|
707
|
+
)}
|
|
708
|
+
|
|
709
|
+
{lineMenu && (
|
|
710
|
+
<>
|
|
711
|
+
<Pressable style={StyleSheet.absoluteFill} onPress={() => setLineMenu(false)} accessibilityLabel={L.dismiss} />
|
|
712
|
+
<View style={[styles.lineMenu, { bottom: safe.bottom + 20, backgroundColor: colors.dark ? '#4a4742' : '#ffffff', borderColor: colors.glassBorder }]}>
|
|
713
|
+
<Text style={[styles.lineMenuHead, { color: colors.subtext }]}>{L.backgroundDimming}</Text>
|
|
714
|
+
{DIM_IDS.map((d) => (
|
|
715
|
+
<Pressable
|
|
716
|
+
key={d.id}
|
|
717
|
+
style={styles.lineItem}
|
|
718
|
+
accessibilityRole="button"
|
|
719
|
+
accessibilityState={{ selected: dimLevel === d.id }}
|
|
720
|
+
onPress={() => {
|
|
721
|
+
setDimLevel(d.id);
|
|
722
|
+
setLineMenu(false);
|
|
723
|
+
}}
|
|
724
|
+
>
|
|
725
|
+
<View style={styles.lineCheck}>{dimLevel === d.id && <Icon name="check" color={tx} size={20} />}</View>
|
|
726
|
+
<Text style={{ color: tx, fontSize: 19 }}>{L[d.label]}</Text>
|
|
727
|
+
</Pressable>
|
|
728
|
+
))}
|
|
729
|
+
<View style={[styles.lineSep, { backgroundColor: colors.separator }]} />
|
|
730
|
+
<Pressable
|
|
731
|
+
style={styles.lineItem}
|
|
732
|
+
accessibilityRole="button"
|
|
733
|
+
onPress={() => {
|
|
734
|
+
setLineGuide(false);
|
|
735
|
+
setLineMenu(false);
|
|
736
|
+
}}
|
|
737
|
+
>
|
|
738
|
+
<View style={styles.lineCheck} />
|
|
739
|
+
<Text style={{ color: tx, fontSize: 19 }}>{L.turnOffLineGuide}</Text>
|
|
740
|
+
</Pressable>
|
|
741
|
+
</View>
|
|
742
|
+
</>
|
|
743
|
+
)}
|
|
744
|
+
|
|
745
|
+
<ContentsSheet
|
|
746
|
+
visible={sheet === 'contents'}
|
|
747
|
+
colors={colors}
|
|
748
|
+
title={meta?.title || props.title || ''}
|
|
749
|
+
subtitle={L.pageOfTotalLong(curPage, totalPages)}
|
|
750
|
+
toc={toc}
|
|
751
|
+
currentSpine={loc?.spine ?? 0}
|
|
752
|
+
pageOf={pageOf}
|
|
753
|
+
bookmarks={bookmarks}
|
|
754
|
+
highlights={highlights}
|
|
755
|
+
onClose={closeSheet}
|
|
756
|
+
onGoToc={(item) => {
|
|
757
|
+
closeSheet();
|
|
758
|
+
jump({ spine: item.spine, fragment: item.fragment });
|
|
759
|
+
}}
|
|
760
|
+
onGoBookmark={(b) => {
|
|
761
|
+
closeSheet();
|
|
762
|
+
jump({ spine: b.spine, offset: b.offset });
|
|
763
|
+
}}
|
|
764
|
+
onGoHighlight={(h) => {
|
|
765
|
+
closeSheet();
|
|
766
|
+
jump({ spine: h.spine, offset: h.start });
|
|
767
|
+
}}
|
|
768
|
+
onDeleteBookmark={(id) => updateBookmarks((prev) => prev.filter((b) => b.id !== id))}
|
|
769
|
+
onDeleteHighlight={(id) => updateHighlights((prev) => prev.filter((h) => h.id !== id))}
|
|
770
|
+
/>
|
|
771
|
+
<SearchSheet
|
|
772
|
+
visible={sheet === 'search'}
|
|
773
|
+
colors={colors}
|
|
774
|
+
results={results}
|
|
775
|
+
searching={searching}
|
|
776
|
+
onClose={closeSheet}
|
|
777
|
+
onSearch={runSearch}
|
|
778
|
+
onPick={(r) => {
|
|
779
|
+
closeSheet();
|
|
780
|
+
if (loc) setReturnTo({ spine: loc.spine, offset: loc.offset, page: curPage });
|
|
781
|
+
setChrome(false);
|
|
782
|
+
reader.current?.showSearchResult(r);
|
|
783
|
+
}}
|
|
784
|
+
/>
|
|
785
|
+
<AppearanceSheet
|
|
786
|
+
visible={sheet === 'appearance'}
|
|
787
|
+
colors={colors}
|
|
788
|
+
settings={settings}
|
|
789
|
+
systemDark={systemDark}
|
|
790
|
+
onChange={changeSettings}
|
|
791
|
+
onCustomize={() => switchSheet('customize')}
|
|
792
|
+
onClose={closeSheet}
|
|
793
|
+
/>
|
|
794
|
+
<CustomizeSheet
|
|
795
|
+
visible={sheet === 'customize'}
|
|
796
|
+
colors={colors}
|
|
797
|
+
page={page}
|
|
798
|
+
settings={settings}
|
|
799
|
+
sample={loc?.excerpt || SAMPLE}
|
|
800
|
+
onChange={changeSettings}
|
|
801
|
+
onReset={() => changeSettings(RESET_THEME)}
|
|
802
|
+
onClose={() => switchSheet('appearance')}
|
|
803
|
+
/>
|
|
804
|
+
<NoteEditor
|
|
805
|
+
visible={!!noteHighlight}
|
|
806
|
+
quote={noteHighlight?.text || ''}
|
|
807
|
+
initial={noteHighlight?.note || ''}
|
|
808
|
+
colors={colors}
|
|
809
|
+
onCancel={() => setNoteFor(null)}
|
|
810
|
+
onSave={(text) => {
|
|
811
|
+
if (noteFor) patchHighlight(noteFor, { note: text || undefined });
|
|
812
|
+
setNoteFor(null);
|
|
813
|
+
}}
|
|
814
|
+
/>
|
|
815
|
+
</View>
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
const styles = StyleSheet.create({
|
|
820
|
+
root: { flex: 1 },
|
|
821
|
+
closeWrap: { position: 'absolute' },
|
|
822
|
+
circle: { width: 42, height: 42, borderRadius: 21, alignItems: 'center', justifyContent: 'center' },
|
|
823
|
+
controls: { position: 'absolute', width: '68%', minWidth: 260, maxWidth: 420 },
|
|
824
|
+
selBar: { position: 'absolute', height: 48, borderRadius: 24, flexDirection: 'row', alignItems: 'center' },
|
|
825
|
+
selBtn: { flex: 1, height: '100%', flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 6 },
|
|
826
|
+
selText: { fontSize: 15, fontWeight: '600' },
|
|
827
|
+
selSep: { width: StyleSheet.hairlineWidth, height: 24 },
|
|
828
|
+
lineMenu: {
|
|
829
|
+
position: 'absolute', left: 16, width: 290, borderRadius: 28, paddingVertical: 10, borderWidth: StyleSheet.hairlineWidth,
|
|
830
|
+
shadowColor: '#000', shadowOpacity: 0.3, shadowRadius: 16, shadowOffset: { width: 0, height: 6 }, elevation: 12
|
|
831
|
+
},
|
|
832
|
+
lineMenuHead: { fontSize: 15, fontWeight: '600', marginStart: 52, marginTop: 8, marginBottom: 4 },
|
|
833
|
+
lineItem: { flexDirection: 'row', alignItems: 'center', paddingVertical: 12, paddingHorizontal: 18 },
|
|
834
|
+
lineCheck: { width: 34 },
|
|
835
|
+
lineSep: { height: StyleSheet.hairlineWidth, marginVertical: 6, marginHorizontal: 18 },
|
|
836
|
+
menuBtnWrap: { position: 'absolute' },
|
|
837
|
+
menuBtn: { width: 54, height: 54, borderRadius: 27, alignItems: 'center', justifyContent: 'center' },
|
|
838
|
+
returnWrap: { position: 'absolute' },
|
|
839
|
+
returnPill: { height: 46, borderRadius: 23, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 16 },
|
|
840
|
+
pillRow: { height: 50, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 22 },
|
|
841
|
+
pillWrap: { marginBottom: 8 },
|
|
842
|
+
pill: { height: 50, borderRadius: 25 },
|
|
843
|
+
pillText: { fontSize: 17, fontWeight: '500' },
|
|
844
|
+
fill: { position: 'absolute', top: 0, bottom: 0, overflow: 'hidden' },
|
|
845
|
+
roundRow: { flexDirection: 'row', gap: 8 },
|
|
846
|
+
roundWrap: { flex: 1 },
|
|
847
|
+
round: { height: 50, borderRadius: 25, alignItems: 'center', justifyContent: 'center' },
|
|
848
|
+
ribbon: { position: 'absolute', top: 0, width: 16 },
|
|
849
|
+
ribbonBody: { height: 26, backgroundColor: '#ff3b30' },
|
|
850
|
+
ribbonNotch: {
|
|
851
|
+
width: 0, height: 0, borderLeftWidth: 8, borderRightWidth: 8, borderBottomWidth: 7,
|
|
852
|
+
borderLeftColor: '#ff3b30', borderRightColor: '#ff3b30', borderBottomColor: 'transparent'
|
|
853
|
+
},
|
|
854
|
+
error: { position: 'absolute', left: 24, right: 24, top: '40%', padding: 20, borderRadius: 14, alignItems: 'center', elevation: 10 },
|
|
855
|
+
splash: { alignItems: 'center', justifyContent: 'center', paddingHorizontal: 32 },
|
|
856
|
+
splashClose: { position: 'absolute' },
|
|
857
|
+
fatalButtons: { flexDirection: 'row', gap: 12, marginTop: 24 },
|
|
858
|
+
fatalBtn: { minWidth: 110, height: 46, borderRadius: 23, alignItems: 'center', justifyContent: 'center', paddingHorizontal: 20 },
|
|
859
|
+
a11yHandle: { position: 'absolute', width: 48, height: 48, backgroundColor: 'transparent' }
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
// controls that are faded out must not stay reachable for VoiceOver / TalkBack
|
|
863
|
+
function hiddenA11y(hidden: boolean) {
|
|
864
|
+
return { accessibilityElementsHidden: hidden, importantForAccessibility: (hidden ? 'no-hide-descendants' : 'auto') as 'no-hide-descendants' | 'auto' };
|
|
865
|
+
}
|