multipage: reset magnifier state when page dimensions change
This commit is contained in:
parent
fd8191639b
commit
4d8e2d4123
1 changed files with 27 additions and 5 deletions
|
@ -53,7 +53,7 @@ class EntryPageView extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _EntryPageViewState extends State<EntryPageView> {
|
class _EntryPageViewState extends State<EntryPageView> {
|
||||||
final MagnifierController _magnifierController = MagnifierController();
|
MagnifierController _magnifierController;
|
||||||
final ValueNotifier<ViewState> _viewStateNotifier = ValueNotifier(ViewState.zero);
|
final ValueNotifier<ViewState> _viewStateNotifier = ValueNotifier(ViewState.zero);
|
||||||
final List<StreamSubscription> _subscriptions = [];
|
final List<StreamSubscription> _subscriptions = [];
|
||||||
|
|
||||||
|
@ -64,17 +64,39 @@ class _EntryPageViewState extends State<EntryPageView> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_subscriptions.add(_magnifierController.stateStream.listen(_onViewStateChanged));
|
_registerWidget();
|
||||||
_subscriptions.add(_magnifierController.scaleBoundariesStream.listen(_onViewScaleBoundariesChanged));
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant EntryPageView oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
|
||||||
|
if (oldWidget.entry.displaySize != entry.displaySize) {
|
||||||
|
// do not reset the magnifier view state unless page dimensions change,
|
||||||
|
// in effect locking the zoom & position when browsing entry pages of the same size
|
||||||
|
_unregisterWidget();
|
||||||
|
_registerWidget();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
_unregisterWidget();
|
||||||
|
widget.onDisposed?.call();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _registerWidget() {
|
||||||
|
_viewStateNotifier.value = ViewState.zero;
|
||||||
|
_magnifierController = MagnifierController();
|
||||||
|
_subscriptions.add(_magnifierController.stateStream.listen(_onViewStateChanged));
|
||||||
|
_subscriptions.add(_magnifierController.scaleBoundariesStream.listen(_onViewScaleBoundariesChanged));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _unregisterWidget() {
|
||||||
_subscriptions
|
_subscriptions
|
||||||
..forEach((sub) => sub.cancel())
|
..forEach((sub) => sub.cancel())
|
||||||
..clear();
|
..clear();
|
||||||
widget.onDisposed?.call();
|
|
||||||
super.dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
Loading…
Reference in a new issue