4e0481fd8d
Full screen button in the viewer's bottom bar opens a root full-screen route with the same bar and top bar; exit by the bar, Close, Escape or back. It renders the already fetched bytes, never the system browser. The external Open action is now labelled Open in browser. Native web views claim their gestures (vertical drags inline, every pointer in full screen) so the page swipe no longer starves them. On the web, full screen adds zoom buttons that scale the live sandboxed frame. Links: in-page anchors scroll, http(s)/mailto open outside, everything else is inert. Capture kit: --touch, swipe=, pinch=, tabs=; html=1 fixture artifact.
59 lines
1.9 KiB
Dart
59 lines
1.9 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import '../../../ui/adaptive/host.dart';
|
|
import 'artifact_fullscreen.dart';
|
|
|
|
/// Lets a viewer page open its own content as the full-screen view.
|
|
///
|
|
/// The full-screen route lives on the root navigator, outside the page's
|
|
/// subtree, yet draws from the page's state: [buildFrame] builds either
|
|
/// presentation, and every [setState] redraws the full-screen route too, so
|
|
/// paging, loading and status messages show in both.
|
|
mixin ArtifactFullscreenHost<T extends StatefulWidget> on State<T> {
|
|
final ValueNotifier<int> _revision = ValueNotifier<int>(0);
|
|
|
|
/// The full-screen view's HTML zoom; each full-screen visit starts at 1.
|
|
final ValueNotifier<double> htmlZoom = ValueNotifier<double>(1);
|
|
Route<void>? _fullscreen;
|
|
|
|
/// The page's scaffold, inline or as the full-screen view.
|
|
Widget buildFrame(BuildContext context, {required bool fullscreen});
|
|
|
|
@override
|
|
void setState(VoidCallback fn) {
|
|
super.setState(fn);
|
|
_revision.value++;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// The full-screen route closes with the page, once the tree unlocks.
|
|
final route = _fullscreen;
|
|
if (route != null) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (route.isActive) route.navigator?.removeRoute(route);
|
|
});
|
|
}
|
|
super.dispose();
|
|
}
|
|
|
|
/// Opens the full-screen view; it returns when the view closes.
|
|
Future<void> enterFullscreen() async {
|
|
if (_fullscreen != null) return;
|
|
htmlZoom.value = 1;
|
|
final route = artifactFullscreenRoute(
|
|
cupertino: usesCupertinoHost(context),
|
|
builder: (_) => ArtifactFullscreenScope(
|
|
htmlZoom: htmlZoom,
|
|
child: ListenableBuilder(
|
|
listenable: Listenable.merge([_revision, htmlZoom]),
|
|
builder: (context, _) => buildFrame(context, fullscreen: true),
|
|
),
|
|
),
|
|
);
|
|
_fullscreen = route;
|
|
await Navigator.of(context, rootNavigator: true).push(route);
|
|
_fullscreen = null;
|
|
}
|
|
}
|