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
@@ -109,17 +109,24 @@ class _LeafVideoControlsState extends State<LeafVideoControls> {
|
||||
onDoubleTap: _handleDoubleTap,
|
||||
),
|
||||
),
|
||||
// Bottom bar — fades with the viewer's chrome state.
|
||||
// Bottom bar — fades with the viewer's chrome state. Bottom-anchored
|
||||
// with its natural height: inside a StackFit.expand stack a bare
|
||||
// child stretches full-screen and eats every gesture meant for the
|
||||
// tap detector above it.
|
||||
if (chrome != null)
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: chrome.visibleListenable,
|
||||
builder: (context, visible, _) => IgnorePointer(
|
||||
ignoring: !visible,
|
||||
child: AnimatedOpacity(duration: const Duration(milliseconds: 200), opacity: visible ? 1.0 : 0.0, child: _buildBar(context)),
|
||||
child: AnimatedOpacity(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
opacity: visible ? 1.0 : 0.0,
|
||||
child: Align(alignment: Alignment.bottomCenter, child: SafeArea(child: _buildBar(context))),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
_buildBar(context),
|
||||
Align(alignment: Alignment.bottomCenter, child: SafeArea(child: _buildBar(context))),
|
||||
// Center play badge while paused.
|
||||
Center(
|
||||
child: IgnorePointer(
|
||||
@@ -175,6 +182,7 @@ class _LeafVideoControlsState extends State<LeafVideoControls> {
|
||||
),
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(height: 50),
|
||||
Row(
|
||||
|
||||
@@ -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