aksos-react-native-epub-reader 0.1.0 → 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.
@@ -1,6 +1,6 @@
1
1
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
- import { Alert, Animated, Linking, Platform, Pressable, Share, StatusBar, StyleSheet, Text, useColorScheme, useWindowDimensions, View } from 'react-native';
3
- import { EpubReader } from './EpubReader';
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
4
  import type { EpubReaderHandle } from './EpubReader';
5
5
  import { chromeColors, DEFAULT_SETTINGS, isDark, themeColors } from './themes';
6
6
  import type {
@@ -13,6 +13,7 @@ import type {
13
13
  PageTurn,
14
14
  ReaderSettings,
15
15
  RelocateEvent,
16
+ SafeInsets,
16
17
  SearchResult,
17
18
  SelectionEvent,
18
19
  TocItem
@@ -21,6 +22,8 @@ import { AppearanceSheet } from './ui/AppearanceSheet';
21
22
  import { ContentsSheet } from './ui/ContentsSheet';
22
23
  import { CustomizeSheet } from './ui/CustomizeSheet';
23
24
  import { playPageTurn } from './sound';
25
+ import { LabelsProvider, mergeLabels, useLabels } from './strings';
26
+ import type { ReaderLabels } from './strings';
24
27
  import { Glass } from './ui/Glass';
25
28
  import { HighlightMenu } from './ui/HighlightMenu';
26
29
  import { Icon } from './ui/Icons';
@@ -33,7 +36,8 @@ export interface EpubReaderViewProps {
33
36
  source: EpubSource;
34
37
  /** shown in the Contents sheet until the book's own title is read */
35
38
  title?: string;
36
- safeInsets?: { top: number; bottom: number };
39
+ /** Space for the status bar / home indicator (and notch in landscape). Use useSafeAreaInsets() from react-native-safe-area-context. */
40
+ safeInsets?: SafeInsets;
37
41
  initialLocation?: BookLocation;
38
42
  initialSettings?: Partial<ReaderSettings>;
39
43
  initialHighlights?: Highlight[];
@@ -46,6 +50,10 @@ export interface EpubReaderViewProps {
46
50
  onMetadata?: (m: BookMetadata) => void;
47
51
  onCover?: (dataUri: string) => void;
48
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;
49
57
  }
50
58
 
51
59
  const RESET_THEME: Partial<ReaderSettings> = {
@@ -69,25 +77,49 @@ try {
69
77
  ScreenOrientation = null;
70
78
  }
71
79
 
72
- const DIM_LABELS: { id: DimLevel; label: string }[] = [
73
- { id: 'high', label: 'High' },
74
- { id: 'medium', label: 'Medium' },
75
- { id: 'low', label: 'Low' },
76
- { id: 'none', label: 'None' }
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' }
77
85
  ];
78
86
 
79
87
  const SAMPLE = 'The reader turned the page slowly, listening to the wind move across the empty hills.';
80
88
  const uid = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
81
89
 
82
- function defaultInsets() {
83
- return Platform.OS === 'ios' ? { top: 50, bottom: 30 } : { top: StatusBar.currentHeight || 24, bottom: 0 };
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 };
84
101
  }
85
102
 
86
103
  type SheetName = null | 'contents' | 'search' | 'appearance' | 'customize';
87
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
+ */
88
109
  export function EpubReaderView(props: EpubReaderViewProps) {
89
- const safe = props.safeInsets || defaultInsets();
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();
90
121
  const screen = useWindowDimensions();
122
+ const safe = props.safeInsets || defaultInsets(screen.width, screen.height);
91
123
  const systemDark = useColorScheme() === 'dark';
92
124
  const reader = useRef<EpubReaderHandle>(null);
93
125
 
@@ -116,10 +148,35 @@ export function EpubReaderView(props: EpubReaderViewProps) {
116
148
  const [results, setResults] = useState<SearchResult[]>([]);
117
149
  const [searching, setSearching] = useState(false);
118
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);
119
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);
120
162
  const seen = useRef<Record<number, { len: number; pc: number }>>({});
121
163
  const layoutKey = useRef('');
122
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
+
123
180
  const dark = isDark(settings, systemDark);
124
181
  const page = themeColors(settings, systemDark);
125
182
  const colors = useMemo(() => chromeColors(page, dark), [page, dark]);
@@ -139,33 +196,26 @@ export function EpubReaderView(props: EpubReaderViewProps) {
139
196
  }, [chrome]);
140
197
 
141
198
  // ----- persistence helpers
142
- const updateHighlights = useCallback(
143
- (fn: (prev: Highlight[]) => Highlight[]) => {
144
- setHighlights((prev) => {
145
- const next = fn(prev);
146
- props.onHighlightsChange?.(next);
147
- return next;
148
- });
149
- },
150
- // eslint-disable-next-line react-hooks/exhaustive-deps
151
- [props.onHighlightsChange]
152
- );
153
- const updateBookmarks = useCallback(
154
- (fn: (prev: Bookmark[]) => Bookmark[]) => {
155
- setBookmarks((prev) => {
156
- const next = fn(prev);
157
- props.onBookmarksChange?.(next);
158
- return next;
159
- });
160
- },
161
- // eslint-disable-next-line react-hooks/exhaustive-deps
162
- [props.onBookmarksChange]
163
- );
164
- const changeSettings = (patch: Partial<ReaderSettings>) => {
165
- const next = { ...settings, ...patch };
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;
166
216
  setSettings(next);
167
- props.onSettingsChange?.(next);
168
- };
217
+ latestProps.current.onSettingsChange?.(next);
218
+ }, []);
169
219
 
170
220
  // ----- book page numbers (estimated from characters per page)
171
221
  const onRelocate = (e: RelocateEvent) => {
@@ -184,6 +234,7 @@ export function EpubReaderView(props: EpubReaderViewProps) {
184
234
  const next = pc > 0 && len > 0 ? len / pc : 1200;
185
235
  setCpp((old) => (Math.abs(old - next) / next > 0.01 ? next : old));
186
236
  setLoc(e);
237
+ setLoaded(true);
187
238
  setActive(null);
188
239
  props.onLocationChange?.(e);
189
240
  };
@@ -203,10 +254,10 @@ export function EpubReaderView(props: EpubReaderViewProps) {
203
254
  // header / footer drawn on the page: chapter title + page number, or "N pages left" + "x of y" while the controls are shown
204
255
  useEffect(() => {
205
256
  if (!loc) return;
206
- const header = chrome ? (pagesLeft === 0 ? 'Last page in chapter' : `${pagesLeft} page${pagesLeft === 1 ? '' : 's'} left in chapter`) : loc.chapter;
207
- const footer = chrome ? `${curPage} of ${totalPages}` : `${curPage}`;
257
+ const header = chrome ? (pagesLeft === 0 ? L.lastPageInChapter : L.pagesLeft(pagesLeft)) : loc.chapter;
258
+ const footer = chrome ? L.pageOfTotal(curPage, totalPages) : L.formatNumber(curPage);
208
259
  reader.current?.setLabels(header, footer);
209
- }, [chrome, loc, curPage, totalPages, pagesLeft]);
260
+ }, [chrome, loc, curPage, totalPages, pagesLeft, L]);
210
261
 
211
262
  // ----- bookmarks
212
263
  const bookmarkHere = useMemo(
@@ -280,18 +331,20 @@ export function EpubReaderView(props: EpubReaderViewProps) {
280
331
  };
281
332
  const toggleRotationLock = async () => {
282
333
  if (!ScreenOrientation) {
283
- Alert.alert('Rotation lock', 'Install expo-screen-orientation to enable the rotation lock.');
334
+ Alert.alert(L.rotationLock, L.rotationLockNeedsPackage);
284
335
  return;
285
336
  }
286
337
  try {
287
338
  if (rotLocked) {
288
339
  await ScreenOrientation.unlockAsync();
340
+ lockedByUs.current = false;
289
341
  setRotLocked(false);
290
342
  } else {
291
343
  const o = await ScreenOrientation.getOrientationAsync();
292
344
  const O = ScreenOrientation.Orientation;
293
345
  const L = ScreenOrientation.OrientationLock;
294
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;
295
348
  setRotLocked(true);
296
349
  }
297
350
  } catch {
@@ -300,7 +353,8 @@ export function EpubReaderView(props: EpubReaderViewProps) {
300
353
  };
301
354
  useEffect(
302
355
  () => () => {
303
- if (ScreenOrientation) ScreenOrientation.unlockAsync().catch(() => undefined);
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);
304
358
  },
305
359
  []
306
360
  );
@@ -311,6 +365,13 @@ export function EpubReaderView(props: EpubReaderViewProps) {
311
365
  setChrome(false);
312
366
  } else setLineMenu(true);
313
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
+ };
314
375
  const share = () => {
315
376
  const text = [loc?.excerpt, meta?.title && `— ${meta.title}`].filter(Boolean).join(' ');
316
377
  Share.share({ message: text || meta?.title || '' }).catch(() => undefined);
@@ -324,11 +385,12 @@ export function EpubReaderView(props: EpubReaderViewProps) {
324
385
  <EpubReader
325
386
  ref={reader}
326
387
  source={props.source}
327
- settings={settings}
388
+ settings={readerSettings}
328
389
  systemDark={systemDark}
329
390
  safeInsets={safe}
330
391
  initialLocation={props.initialLocation}
331
392
  highlights={highlights}
393
+ maxFileSize={props.maxFileSize}
332
394
  onReady={({ metadata, rtl: isRtl }) => {
333
395
  setMeta(metadata);
334
396
  setRtl(isRtl);
@@ -354,18 +416,43 @@ export function EpubReaderView(props: EpubReaderViewProps) {
354
416
  setActive(null);
355
417
  }
356
418
  }}
357
- onLink={(href) => Linking.openURL(href).catch(() => undefined)}
419
+ onLink={openLink}
420
+ onLinkJump={(from) => setReturnTo({ spine: from.spine, offset: from.offset, page: pageOf(from.spine, from.offset) })}
421
+ onDirectionChange={setRtl}
358
422
  onSearchResults={(id, found, done) => {
359
423
  if (id !== searchId.current) return;
360
424
  setResults((prev) => prev.concat(found));
361
425
  if (done) setSearching(false);
362
426
  }}
363
- onError={(m) => {
364
- setError(m);
427
+ onError={(m, info) => {
428
+ if (info.fatal || !loaded) setFatal(m);
429
+ else setError(m);
365
430
  props.onError?.(m);
366
431
  }}
367
432
  />
368
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
+
369
456
  {/* page brightness */}
370
457
  <View pointerEvents="none" style={[StyleSheet.absoluteFill, { backgroundColor: '#000000', opacity: (1 - settings.brightness) * 0.75 }]} />
371
458
 
@@ -390,8 +477,8 @@ export function EpubReaderView(props: EpubReaderViewProps) {
390
477
  )}
391
478
 
392
479
  {/* close */}
393
- <Animated.View pointerEvents={chrome ? 'auto' : 'none'} style={[styles.closeWrap, { top: safe.top + 2, opacity: fade }]}>
394
- <Pressable onPress={props.onClose} hitSlop={10} accessibilityRole="button" accessibilityLabel="Close book">
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}>
395
482
  <Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.circle}>
396
483
  <Icon name="close" color={tx} size={22} />
397
484
  </Glass>
@@ -400,7 +487,7 @@ export function EpubReaderView(props: EpubReaderViewProps) {
400
487
 
401
488
  {/* back to where we came from, like the "193" pill in Books */}
402
489
  {returnTo && (
403
- <Animated.View pointerEvents={chrome ? 'auto' : 'none'} style={[styles.returnWrap, { top: safe.top + 2, opacity: fade }]}>
490
+ <Animated.View pointerEvents={chrome ? 'auto' : 'none'} {...hiddenA11y(!chrome)} style={[styles.returnWrap, { top: safe.top + 2, left: 16 + (safe.left || 0), opacity: fade }]}>
404
491
  <Pressable
405
492
  onPress={() => {
406
493
  reader.current?.goTo({ spine: returnTo.spine, offset: returnTo.offset });
@@ -408,11 +495,11 @@ export function EpubReaderView(props: EpubReaderViewProps) {
408
495
  }}
409
496
  hitSlop={8}
410
497
  accessibilityRole="button"
411
- accessibilityLabel={`Return to page ${returnTo.page}`}
498
+ accessibilityLabel={L.returnToPage(returnTo.page)}
412
499
  >
413
500
  <Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.returnPill}>
414
501
  <Icon name="undo" color={tx} size={22} />
415
- <Text style={{ color: tx, fontSize: 20, marginStart: 8 }}>{returnTo.page}</Text>
502
+ <Text style={{ color: tx, fontSize: 20, marginStart: 8 }} maxFontSizeMultiplier={1.3}>{L.formatNumber(returnTo.page)}</Text>
416
503
  </Glass>
417
504
  </Pressable>
418
505
  </Animated.View>
@@ -421,9 +508,10 @@ export function EpubReaderView(props: EpubReaderViewProps) {
421
508
  {/* menu button (collapsed) */}
422
509
  <Animated.View
423
510
  pointerEvents={chrome && !menuOpen ? 'auto' : 'none'}
424
- style={[styles.menuBtnWrap, { bottom: safe.bottom + 14, opacity: Animated.multiply(fade, Animated.subtract(1, menuFade)) }]}
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)) }]}
425
513
  >
426
- <Pressable onPress={() => setMenuOpen(true)} accessibilityRole="button" accessibilityLabel="Reader menu">
514
+ <Pressable onPress={() => setMenuOpen(true)} accessibilityRole="button" accessibilityLabel={L.readerMenu}>
427
515
  <Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.menuBtn}>
428
516
  <Icon name="list" color={tx} size={24} />
429
517
  </Glass>
@@ -431,19 +519,19 @@ export function EpubReaderView(props: EpubReaderViewProps) {
431
519
  </Animated.View>
432
520
 
433
521
  {/* floating controls (expanded menu) */}
434
- <Animated.View pointerEvents={chrome && menuOpen ? 'box-none' : 'none'} style={[styles.controls, { bottom: safe.bottom + 44, opacity: menuFade }]}>
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 }]}>
435
523
  <Pressable
436
524
  onPress={() => {
437
525
  setMenuOpen(false);
438
526
  setSheet('contents');
439
527
  }}
440
528
  accessibilityRole="button"
441
- accessibilityLabel="Contents"
529
+ accessibilityLabel={L.contents}
442
530
  style={styles.pillWrap}
443
531
  >
444
532
  <Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.pill}>
445
533
  <View style={styles.pillRow} onLayout={(e) => setPillW(e.nativeEvent.layout.width)}>
446
- <Text style={[styles.pillText, { color: tx }]}>Contents • {percent}%</Text>
534
+ <Text style={[styles.pillText, { color: tx }]} maxFontSizeMultiplier={1.3}>{L.contents} • {L.formatNumber(percent)}%</Text>
447
535
  <Icon name="list" color={tx} size={24} />
448
536
  </View>
449
537
  {/* progress fill with inverted text on top of it */}
@@ -452,7 +540,7 @@ export function EpubReaderView(props: EpubReaderViewProps) {
452
540
  style={[styles.fill, { width: progressFill * pillW, backgroundColor: dark ? 'rgba(255,255,255,0.35)' : '#1c1408', [rtl ? 'right' : 'left']: 0 }]}
453
541
  >
454
542
  <View style={[styles.pillRow, { position: 'absolute', top: 0, width: pillW, [rtl ? 'right' : 'left']: 0 }]}>
455
- <Text style={[styles.pillText, { color: dark ? tx : '#ffffff' }]}>Contents • {percent}%</Text>
543
+ <Text style={[styles.pillText, { color: dark ? tx : '#ffffff' }]} maxFontSizeMultiplier={1.3}>{L.contents} • {L.formatNumber(percent)}%</Text>
456
544
  <Icon name="list" color={dark ? tx : '#ffffff'} size={24} />
457
545
  </View>
458
546
  </View>
@@ -465,12 +553,12 @@ export function EpubReaderView(props: EpubReaderViewProps) {
465
553
  setSheet('search');
466
554
  }}
467
555
  accessibilityRole="button"
468
- accessibilityLabel="Search book"
556
+ accessibilityLabel={L.searchBook}
469
557
  style={styles.pillWrap}
470
558
  >
471
559
  <Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.pill}>
472
560
  <View style={styles.pillRow}>
473
- <Text style={[styles.pillText, { color: tx }]}>Search Book</Text>
561
+ <Text style={[styles.pillText, { color: tx }]} maxFontSizeMultiplier={1.3}>{L.searchBook}</Text>
474
562
  <Icon name="search" color={tx} size={24} />
475
563
  </View>
476
564
  </Glass>
@@ -482,34 +570,34 @@ export function EpubReaderView(props: EpubReaderViewProps) {
482
570
  setSheet('appearance');
483
571
  }}
484
572
  accessibilityRole="button"
485
- accessibilityLabel="Themes and settings"
573
+ accessibilityLabel={L.themesSettings}
486
574
  style={styles.pillWrap}
487
575
  >
488
576
  <Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.pill}>
489
577
  <View style={styles.pillRow}>
490
- <Text style={[styles.pillText, { color: tx }]}>Themes & Settings</Text>
578
+ <Text style={[styles.pillText, { color: tx }]} maxFontSizeMultiplier={1.3}>{L.themesSettings}</Text>
491
579
  <Icon name="textSize" color={tx} size={26} />
492
580
  </View>
493
581
  </Glass>
494
582
  </Pressable>
495
583
 
496
584
  <View style={styles.roundRow}>
497
- <Pressable onPress={share} style={styles.roundWrap} accessibilityRole="button" accessibilityLabel="Share">
585
+ <Pressable onPress={share} style={styles.roundWrap} accessibilityRole="button" accessibilityLabel={L.share}>
498
586
  <Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.round}>
499
587
  <Icon name="share" color={tx} size={24} />
500
588
  </Glass>
501
589
  </Pressable>
502
- <Pressable onPress={toggleRotationLock} style={styles.roundWrap} accessibilityRole="button" accessibilityLabel="Rotation lock" accessibilityState={{ selected: rotLocked }}>
590
+ <Pressable onPress={toggleRotationLock} style={styles.roundWrap} accessibilityRole="button" accessibilityLabel={L.rotationLock} accessibilityState={{ selected: rotLocked }}>
503
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}>
504
592
  <Icon name="rotationLock" color={tx} size={26} active={rotLocked} />
505
593
  </Glass>
506
594
  </Pressable>
507
- <Pressable onPress={onLineGuideButton} style={styles.roundWrap} accessibilityRole="button" accessibilityLabel="Line guide" accessibilityState={{ selected: lineGuide }}>
595
+ <Pressable onPress={onLineGuideButton} style={styles.roundWrap} accessibilityRole="button" accessibilityLabel={L.lineGuide} accessibilityState={{ selected: lineGuide }}>
508
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}>
509
597
  <Icon name="lineGuide" color={tx} size={26} active={lineGuide} />
510
598
  </Glass>
511
599
  </Pressable>
512
- <Pressable onPress={toggleBookmark} style={styles.roundWrap} accessibilityRole="button" accessibilityLabel="Bookmark this page" accessibilityState={{ selected: bookmarkHere.length > 0 }}>
600
+ <Pressable onPress={toggleBookmark} style={styles.roundWrap} accessibilityRole="button" accessibilityLabel={L.bookmarkPage} accessibilityState={{ selected: bookmarkHere.length > 0 }}>
513
601
  <Glass dark={dark} background={colors.glass} border={colors.glassBorder} style={styles.round}>
514
602
  <Icon name="bookmark" color={tx} size={24} active={bookmarkHere.length > 0} />
515
603
  </Glass>
@@ -518,7 +606,7 @@ export function EpubReaderView(props: EpubReaderViewProps) {
518
606
  </Animated.View>
519
607
 
520
608
  {selection && !active && !noteFor && (() => {
521
- const w = 214;
609
+ const w = Math.min(Math.max(214, screen.width * 0.5), screen.width - 16);
522
610
  const r = selection.rect;
523
611
  const left = Math.max(8, Math.min(screen.width - w - 8, r.x + r.width / 2 - w / 2));
524
612
  // the system callout (Copy / Look Up) sits above the selection, so ours goes below it
@@ -530,20 +618,20 @@ export function EpubReaderView(props: EpubReaderViewProps) {
530
618
  style={styles.selBtn}
531
619
  onPress={() => createHighlight(selection, false)}
532
620
  accessibilityRole="button"
533
- accessibilityLabel="Highlight"
621
+ accessibilityLabel={L.highlight}
534
622
  >
535
623
  <Icon name="highlighter" color={tx} size={22} />
536
- <Text style={[styles.selText, { color: tx }]}>Highlight</Text>
624
+ <Text style={[styles.selText, { color: tx }]} numberOfLines={1} maxFontSizeMultiplier={1.2}>{L.highlight}</Text>
537
625
  </Pressable>
538
626
  <View style={[styles.selSep, { backgroundColor: colors.separator }]} />
539
627
  <Pressable
540
628
  style={styles.selBtn}
541
629
  onPress={() => createHighlight(selection, true)}
542
630
  accessibilityRole="button"
543
- accessibilityLabel="Add note"
631
+ accessibilityLabel={L.addNote}
544
632
  >
545
633
  <Icon name="pencil" color={tx} size={22} />
546
- <Text style={[styles.selText, { color: tx }]}>Note</Text>
634
+ <Text style={[styles.selText, { color: tx }]} numberOfLines={1} maxFontSizeMultiplier={1.2}>{L.note}</Text>
547
635
  </Pressable>
548
636
  </Glass>
549
637
  );
@@ -566,43 +654,89 @@ export function EpubReaderView(props: EpubReaderViewProps) {
566
654
  />
567
655
  )}
568
656
 
569
- {error && (
570
- <View style={[styles.error, { backgroundColor: colors.sheet }]}>
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">
571
702
  <Text style={{ color: colors.text, fontSize: 15, textAlign: 'center' }}>{error}</Text>
572
- <Pressable onPress={() => setError(null)} style={{ marginTop: 12 }}>
573
- <Text style={{ color: colors.accent, fontSize: 16 }}>OK</Text>
703
+ <Pressable onPress={() => setError(null)} style={{ marginTop: 12, padding: 8 }} accessibilityRole="button">
704
+ <Text style={{ color: colors.accent, fontSize: 16 }}>{L.ok}</Text>
574
705
  </Pressable>
575
706
  </View>
576
707
  )}
577
708
 
578
709
  {lineMenu && (
579
710
  <>
580
- <Pressable style={StyleSheet.absoluteFill} onPress={() => setLineMenu(false)} accessibilityLabel="Dismiss" />
711
+ <Pressable style={StyleSheet.absoluteFill} onPress={() => setLineMenu(false)} accessibilityLabel={L.dismiss} />
581
712
  <View style={[styles.lineMenu, { bottom: safe.bottom + 20, backgroundColor: colors.dark ? '#4a4742' : '#ffffff', borderColor: colors.glassBorder }]}>
582
- <Text style={[styles.lineMenuHead, { color: colors.subtext }]}>Background Dimming</Text>
583
- {DIM_LABELS.map((d) => (
713
+ <Text style={[styles.lineMenuHead, { color: colors.subtext }]}>{L.backgroundDimming}</Text>
714
+ {DIM_IDS.map((d) => (
584
715
  <Pressable
585
716
  key={d.id}
586
717
  style={styles.lineItem}
718
+ accessibilityRole="button"
719
+ accessibilityState={{ selected: dimLevel === d.id }}
587
720
  onPress={() => {
588
721
  setDimLevel(d.id);
589
722
  setLineMenu(false);
590
723
  }}
591
724
  >
592
725
  <View style={styles.lineCheck}>{dimLevel === d.id && <Icon name="check" color={tx} size={20} />}</View>
593
- <Text style={{ color: tx, fontSize: 19 }}>{d.label}</Text>
726
+ <Text style={{ color: tx, fontSize: 19 }}>{L[d.label]}</Text>
594
727
  </Pressable>
595
728
  ))}
596
729
  <View style={[styles.lineSep, { backgroundColor: colors.separator }]} />
597
730
  <Pressable
598
731
  style={styles.lineItem}
732
+ accessibilityRole="button"
599
733
  onPress={() => {
600
734
  setLineGuide(false);
601
735
  setLineMenu(false);
602
736
  }}
603
737
  >
604
738
  <View style={styles.lineCheck} />
605
- <Text style={{ color: tx, fontSize: 19 }}>Turn Off Line Guide</Text>
739
+ <Text style={{ color: tx, fontSize: 19 }}>{L.turnOffLineGuide}</Text>
606
740
  </Pressable>
607
741
  </View>
608
742
  </>
@@ -612,7 +746,7 @@ export function EpubReaderView(props: EpubReaderViewProps) {
612
746
  visible={sheet === 'contents'}
613
747
  colors={colors}
614
748
  title={meta?.title || props.title || ''}
615
- subtitle={`Page ${curPage} of ${totalPages}`}
749
+ subtitle={L.pageOfTotalLong(curPage, totalPages)}
616
750
  toc={toc}
617
751
  currentSpine={loc?.spine ?? 0}
618
752
  pageOf={pageOf}
@@ -684,9 +818,9 @@ export function EpubReaderView(props: EpubReaderViewProps) {
684
818
 
685
819
  const styles = StyleSheet.create({
686
820
  root: { flex: 1 },
687
- closeWrap: { position: 'absolute', right: 16 },
821
+ closeWrap: { position: 'absolute' },
688
822
  circle: { width: 42, height: 42, borderRadius: 21, alignItems: 'center', justifyContent: 'center' },
689
- controls: { position: 'absolute', right: 16, width: '68%' },
823
+ controls: { position: 'absolute', width: '68%', minWidth: 260, maxWidth: 420 },
690
824
  selBar: { position: 'absolute', height: 48, borderRadius: 24, flexDirection: 'row', alignItems: 'center' },
691
825
  selBtn: { flex: 1, height: '100%', flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 6 },
692
826
  selText: { fontSize: 15, fontWeight: '600' },
@@ -699,9 +833,9 @@ const styles = StyleSheet.create({
699
833
  lineItem: { flexDirection: 'row', alignItems: 'center', paddingVertical: 12, paddingHorizontal: 18 },
700
834
  lineCheck: { width: 34 },
701
835
  lineSep: { height: StyleSheet.hairlineWidth, marginVertical: 6, marginHorizontal: 18 },
702
- menuBtnWrap: { position: 'absolute', right: 16 },
836
+ menuBtnWrap: { position: 'absolute' },
703
837
  menuBtn: { width: 54, height: 54, borderRadius: 27, alignItems: 'center', justifyContent: 'center' },
704
- returnWrap: { position: 'absolute', left: 16 },
838
+ returnWrap: { position: 'absolute' },
705
839
  returnPill: { height: 46, borderRadius: 23, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 16 },
706
840
  pillRow: { height: 50, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 22 },
707
841
  pillWrap: { marginBottom: 8 },
@@ -717,5 +851,15 @@ const styles = StyleSheet.create({
717
851
  width: 0, height: 0, borderLeftWidth: 8, borderRightWidth: 8, borderBottomWidth: 7,
718
852
  borderLeftColor: '#ff3b30', borderRightColor: '#ff3b30', borderBottomColor: 'transparent'
719
853
  },
720
- error: { position: 'absolute', left: 24, right: 24, top: '40%', padding: 20, borderRadius: 14, alignItems: 'center', elevation: 10 }
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' }
721
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
+ }