fix: LeafViewerHero gates heroes to the settled page (keep-alive neighbours flew too); video controls bar bottom-anchored with natural height (was stretched full-screen, blocking gestures)
This commit is contained in:
1 parent
6f97775990
commit
764c512572
3 files changed
+79
-3
No files matched your search
@@ -94,6 +94,11 @@ class LeafViewer extends StatefulWidget {
|
||||
return LeafViewerScope.maybeOf(context)?.registry.activeController;
|
||||
}
|
||||
|
||||
/// The index of the page this context belongs to, if inside a viewer.
|
||||
static int? pageIndexOf(BuildContext context) {
|
||||
return LeafPageIndexScope.maybeOf(context);
|
||||
}
|
||||
|
||||
/// Reactive index of the currently settled page, if inside a viewer.
|
||||
static ValueListenable<int>? currentIndexListOf(BuildContext context) {
|
||||
return LeafViewerScope.maybeOf(context)?.currentIndex;
|
||||
@@ -393,6 +398,33 @@ class _LeafViewerState extends State<LeafViewer> with TickerProviderStateMixin i
|
||||
}
|
||||
}
|
||||
|
||||
/// A [Hero] that only participates on the viewer's currently active page.
|
||||
///
|
||||
/// LeafViewer keeps neighbour pages alive, so an unconditional hero on every
|
||||
/// page registers several per route — popping the viewer then flies the
|
||||
/// active page AND its neighbours back to the grid. This gates the hero on
|
||||
/// "this page is the settled one", so exactly one flight happens. The child
|
||||
/// instance is passed through untouched, so providers stay stable across
|
||||
/// page changes. Outside a viewer it behaves like a plain [Hero].
|
||||
class LeafViewerHero extends StatelessWidget {
|
||||
const LeafViewerHero({super.key, required this.tag, required this.child});
|
||||
|
||||
final Object tag;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final index = LeafViewer.pageIndexOf(context);
|
||||
final currentIndex = LeafViewer.currentIndexListOf(context);
|
||||
if (index == null || currentIndex == null) return Hero(tag: tag, child: child);
|
||||
return ValueListenableBuilder<int>(
|
||||
valueListenable: currentIndex,
|
||||
child: child,
|
||||
builder: (context, current, child) => current == index ? Hero(tag: tag, child: child!) : child!,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _LeafViewerDefaultControls extends StatelessWidget {
|
||||
const _LeafViewerDefaultControls({required this.controls, this.showPageCounter = true});
|
||||
|
||||
|
||||
Reference in new issue
Block a user