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
20 changes: 14 additions & 6 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,21 @@ In paginated text formats, mouse drags starting in blank space, including the
outer window margins, turn pages;
drags starting on rendered text remain selection gestures. Mouse turns use the
same page controller as touch and can interrupt an unfinished turn.
Wheel input turns paginated pages immediately without changing the animation
preference. Small nonzero deltas count as a turn; same-direction bursts are
limited to one turn per 120 ms, while reversing direction responds immediately.
Wheel input turns paginated text pages immediately: small nonzero deltas count
as a turn, same-direction bursts are limited to one turn per 120 ms, and reversing
direction responds immediately. Paginated PDFs, including converted comic archives,
accumulate scroll distance before turning, with an axis lock to tolerate diagonal
touchpad drift. Resistance feedback
persists between samples, uses theme colors, and clears the measured top and bottom
controls without resizing the viewport. It is hidden when page-turn animation or
system motion is disabled. Continued deliberate input can build one subsequent
turn while navigation completes. After a turn, a decaying wheel tail is consumed;
a fresh impulse, direction change, or quiet gap releases the momentum filter.
This is a heuristic because browser wheel events do not identify momentum phases.
Zoomed PDFs pan within the current spread; scrolling outward at its top or bottom
turns the page without animation. Forward turns open at the top, backward turns
at the bottom, preserving zoom. Horizontal zoomed panning, continuous readers,
and modifier-key zoom retain native wheel input.
builds resistance before turning without animation. Forward turns open at the top,
backward turns at the bottom, preserving zoom. Horizontal zoomed panning,
continuous readers, and modifier-key zoom retain native wheel input.
Continuous EPUB uses a full-width scroll surface with centered text and a viewport-edge
scrollbar. Its chunk extents use the rendered fragment heights, including text reshaping
at paragraph cuts. Outward wheel input at a chapter edge opens the adjacent chapter;
Expand Down
4 changes: 4 additions & 0 deletions lib/src/engine/pdf/pdf_facade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,10 @@ final class _PdfrxFacade extends PdfReaderTools

final pages = _pagesController;
return ReaderPageWheel(
resistance: configuration.layoutMode == ReaderLayoutMode.paginated,
showResistance:
configuration.pageTurnAnimation &&
!MediaQuery.disableAnimationsOf(context),
canTurn: _canTurnWithWheel,
onTurn: (direction) => _turnSpread(direction, fromWheel: true),
child: applyPdfBrightness(
Expand Down
192 changes: 121 additions & 71 deletions lib/src/presentation/papyrus_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import '../domain/reader_types.dart';
import '../engine/reader_engine_registry.dart';
import 'reader_material_theme.dart';
import 'reader_controls.dart';
import 'reader_chrome_insets.dart';
import 'reader_pdf_search_panel.dart';
import 'reader_surface.dart';
import 'reader_contents_panel.dart';
Expand Down Expand Up @@ -82,6 +83,10 @@ final class _PapyrusReaderState extends State<PapyrusReader> {
bool _hasReadableContent = false;
_ReaderPanel _panel = _ReaderPanel.none;
bool _controlsVisible = false;
final GlobalKey _toolbarBounds = GlobalKey();
final GlobalKey _progressBounds = GlobalKey();
EdgeInsets _chromeInsets = EdgeInsets.zero;
bool _chromeMeasurementScheduled = false;
double? _dragProgress;
bool _draggingProgress = false;
int _seekRevision = 0;
Expand Down Expand Up @@ -645,6 +650,7 @@ final class _PapyrusReaderState extends State<PapyrusReader> {
) {
return LayoutBuilder(
builder: (context, constraints) {
_scheduleChromeMeasurement();
final isWide = constraints.maxWidth >= theme.compactBreakpoint;
final compactPdf =
_controller.pdfTools != null &&
Expand Down Expand Up @@ -684,96 +690,109 @@ final class _PapyrusReaderState extends State<PapyrusReader> {
key: const ValueKey('reader-content'),
child: FocusTraversalOrder(
order: const NumericFocusOrder(3),
child: _readingSurface(context, snapshot, isWide),
child: ReaderChromeInsets(
insets: _controlsVisible
? _chromeInsets
: EdgeInsets.zero,
child: _readingSurface(context, snapshot, isWide),
),
),
),
PositionedDirectional(
bottom: 0,
start: 0,
end: 0,
child: _chromeVisibility(
child: _overlayBar(
theme,
Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 1000),
child: FocusTraversalOrder(
key: const ValueKey('reader-progress-controls'),
order: const NumericFocusOrder(4),
child: ReaderProgressControls(
progress:
_dragProgress ??
_progressOf(snapshot.locator),
locationLabel: _controller.pdfTools == null
? snapshot.locationLabel
: null,
onProgressChangeStart: _startProgressDrag,
onProgressChanged: (value) => setState(() {
_draggingProgress = true;
_dragProgress = value;
}),
onProgressChangeEnd: _goToProgress,
onPrevious: _goPrevious,
onNext: _goNext,
enabled: true,
theme: theme,
child: _measuredChrome(
_progressBounds,
_chromeVisibility(
child: _overlayBar(
theme,
Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 1000),
child: FocusTraversalOrder(
key: const ValueKey('reader-progress-controls'),
order: const NumericFocusOrder(4),
child: ReaderProgressControls(
progress:
_dragProgress ??
_progressOf(snapshot.locator),
locationLabel: _controller.pdfTools == null
? snapshot.locationLabel
: null,
onProgressChangeStart: _startProgressDrag,
onProgressChanged: (value) => setState(() {
_draggingProgress = true;
_dragProgress = value;
}),
onProgressChangeEnd: _goToProgress,
onPrevious: _goPrevious,
onNext: _goNext,
enabled: true,
theme: theme,
),
),
),
),
),
border: Border(
top: BorderSide(color: theme.dividerColor),
border: Border(
top: BorderSide(color: theme.dividerColor),
),
),
),
),
),
Positioned.fill(
child: Column(
children: [
_chromeVisibility(
child: FocusTraversalOrder(
key: const ValueKey('reader-toolbar'),
order: const NumericFocusOrder(1),
child: _overlayBar(
theme,
Column(
mainAxisSize: MainAxisSize.min,
children: [
toolbar ??
ReaderToolbar(
document: widget.document,
actions: actions,
pdfTools: _controller.pdfTools,
compactPdf: compactPdf,
onSearch: _openPdfSearch,
onBack: widget.onBack,
onTableOfContents: () => _openPanel(
context,
_ReaderPanel.tableOfContents,
isWide,
theme,
_measuredChrome(
_toolbarBounds,
_chromeVisibility(
child: FocusTraversalOrder(
key: const ValueKey('reader-toolbar'),
order: const NumericFocusOrder(1),
child: _overlayBar(
theme,
Column(
mainAxisSize: MainAxisSize.min,
children: [
toolbar ??
ReaderToolbar(
document: widget.document,
actions: actions,
pdfTools: _controller.pdfTools,
compactPdf: compactPdf,
onSearch: _openPdfSearch,
onBack: widget.onBack,
onTableOfContents: () => _openPanel(
context,
_ReaderPanel.tableOfContents,
isWide,
theme,
),
onSettings: () => _openPanel(
context,
_ReaderPanel.settings,
isWide,
theme,
),
tocFocusNode: _tocButtonFocusNode,
settingsFocusNode:
_settingsButtonFocusNode,
theme: theme,
isWide: isWide,
),
onSettings: () => _openPanel(
context,
_ReaderPanel.settings,
isWide,
theme,
if (_showBusy)
const LinearProgressIndicator(
key: ValueKey(
'reader-command-progress',
),
tocFocusNode: _tocButtonFocusNode,
settingsFocusNode:
_settingsButtonFocusNode,
theme: theme,
isWide: isWide,
minHeight: 2,
),
if (_showBusy)
const LinearProgressIndicator(
key: ValueKey('reader-command-progress'),
minHeight: 2,
),
],
),
border: Border(
bottom: BorderSide(color: theme.dividerColor),
],
),
border: Border(
bottom: BorderSide(color: theme.dividerColor),
),
),
),
),
Expand Down Expand Up @@ -860,6 +879,37 @@ final class _PapyrusReaderState extends State<PapyrusReader> {
);
}

void _scheduleChromeMeasurement() {
if (_chromeMeasurementScheduled) return;

_chromeMeasurementScheduled = true;
WidgetsBinding.instance.addPostFrameCallback((_) {
_chromeMeasurementScheduled = false;

if (!mounted) return;

final insets = _controlsVisible
? EdgeInsets.only(
top: _toolbarBounds.currentContext?.size?.height ?? 0,
bottom: _progressBounds.currentContext?.size?.height ?? 0,
)
: EdgeInsets.zero;

if (insets != _chromeInsets) {
setState(() => _chromeInsets = insets);
}
});
}

Widget _measuredChrome(GlobalKey key, Widget child) =>
NotificationListener<SizeChangedLayoutNotification>(
onNotification: (_) {
_scheduleChromeMeasurement();
return false;
},
child: SizeChangedLayoutNotifier(key: key, child: child),
);

Widget _chromeVisibility({required Widget child}) => Visibility(
visible: _controlsVisible,
maintainState: true,
Expand Down
23 changes: 23 additions & 0 deletions lib/src/presentation/reader_chrome_insets.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/widgets.dart';

/// Space obscured by reader controls, for feedback that overlays the viewport.
/// Reading content keeps its full size when the controls appear.
final class ReaderChromeInsets extends InheritedWidget {
const ReaderChromeInsets({
required this.insets,
required super.child,
super.key,
});

final EdgeInsets insets;

static EdgeInsets of(BuildContext context) =>
context
.dependOnInheritedWidgetOfExactType<ReaderChromeInsets>()
?.insets ??
EdgeInsets.zero;

@override
bool updateShouldNotify(ReaderChromeInsets oldWidget) =>
insets != oldWidget.insets;
}
Loading
Loading