fix(ui): keep pushed screens clear of the Android navigation bar
Plezy is edge-to-edge on Android whether it asks to be or not: targetSdk is 36, Android 15 enforces edge-to-edge for apps targeting 35+, and Android 16 disables the windowOptOutEdgeToEdgeEnforcement escape hatch. The only SystemUiMode.edgeToEdge call in the app fires on video-player exit, so on API 35+ the window is edge-to-edge from the first frame and MediaQuery.padding.bottom is a real ~48dp overlap under 3-button navigation. MainScreen's phone layout hides that. It supplies a bottomNavigationBar and never sets extendBody, so Flutter's Scaffold strips padding.bottom from the body MediaQuery and every tab is already safe. Routes pushed on the profile navigator are full-screen siblings of MainScreen with no bottom bar, so they receive the untouched inset and nothing consumes it - the last settings card and the final log lines render under the back, home, and recents buttons. Three shared hosts own most of those routes, so the inset is consumed there: FocusedScrollScaffold (25 screens, counting the SettingsPage wrapper) and FocusableDetailScreenMixin.buildDetailScaffold (4) now append a trailing SliverSystemBottomInset, and the four screens that build their own Scaffold around a CustomScrollView append it directly. The new widget codifies the convention this repository had already written down but open-coded - insets baked into the scroll content rather than a SafeArea around the scroll view - so content still paints under the bar while the scroll extent grows enough to bring the last row above it. It reads padding from its own context and collapses to zero height wherever the inset is already zero: desktop, Android TV, tvOS via _AppleTvScale, and inside MainScreen's tab bodies. No platform branching, and it stacks additively with the music detail screens' existing mini-player spacers, which is correct because the mini-player itself floats above the navigation bar on a pushed route. Scroll views that are not sliver lists take the inset in their own padding: the companion remote's ListView, the auth screen's scroll container, and the two SliverFillRemaining sign-in forms, whose children size themselves from the extent remaining before them and so cannot be helped by a trailing sliver. The logs empty state is left alone for the same reason inverted - it already fills the viewport, and a trailing inset would only add scroll slack. Verified on a Pixel 7 running Android 16 (API 36) with 3-button navigation: Settings, Logs, and Video Playback all end clear of the bar. close #1766
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:plezy/focus/focusable_action_bar.dart';
|
||||
import 'package:plezy/mixins/grid_focus_node_mixin.dart';
|
||||
import 'package:plezy/screens/focusable_detail_screen_mixin.dart';
|
||||
import 'package:plezy/utils/platform_detector.dart';
|
||||
import 'package:plezy/widgets/focused_scroll_scaffold.dart';
|
||||
import 'package:plezy/widgets/system_bottom_inset.dart';
|
||||
|
||||
/// Stand-in for the Android 3-button navigation bar (#1766).
|
||||
const _navBarInset = 48.0;
|
||||
const _viewportHeight = 800.0;
|
||||
const _rowHeight = 100.0;
|
||||
const _rowCount = 20;
|
||||
const _lastRow = 'Row ${_rowCount - 1}';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() {
|
||||
TvDetectionService.debugSetAppleTVOverride(false);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
TvDetectionService.debugSetAppleTVOverride(null);
|
||||
});
|
||||
|
||||
group('SliverSystemBottomInset', () {
|
||||
testWidgets('reserves exactly the system bottom inset as extra scroll extent', (tester) async {
|
||||
await _pump(tester, const _PlainScrollView());
|
||||
|
||||
expect(_position(tester).maxScrollExtent, 1000 - _viewportHeight + _navBarInset);
|
||||
});
|
||||
|
||||
testWidgets('collapses to nothing when the platform reports no bottom inset', (tester) async {
|
||||
await _pump(tester, const _PlainScrollView(), bottomInset: 0);
|
||||
|
||||
expect(_position(tester).maxScrollExtent, 1000 - _viewportHeight);
|
||||
});
|
||||
});
|
||||
|
||||
group('FocusedScrollScaffold', () {
|
||||
testWidgets('scrolls its last row clear of the system navigation bar', (tester) async {
|
||||
await _pump(tester, FocusedScrollScaffold(title: const Text('Settings'), slivers: [_rows()]));
|
||||
await _scrollToEnd(tester);
|
||||
|
||||
expect(tester.getRect(find.text(_lastRow)).bottom, moreOrLessEquals(_viewportHeight - _navBarInset));
|
||||
});
|
||||
|
||||
testWidgets('leaves the last row flush with the viewport when there is no inset', (tester) async {
|
||||
await _pump(tester, FocusedScrollScaffold(title: const Text('Settings'), slivers: [_rows()]), bottomInset: 0);
|
||||
await _scrollToEnd(tester);
|
||||
|
||||
expect(tester.getRect(find.text(_lastRow)).bottom, moreOrLessEquals(_viewportHeight));
|
||||
});
|
||||
});
|
||||
|
||||
group('FocusableDetailScreenMixin.buildDetailScaffold', () {
|
||||
testWidgets('scrolls its last row clear of the system navigation bar', (tester) async {
|
||||
await _pump(tester, const _DetailSurface());
|
||||
await _scrollToEnd(tester);
|
||||
|
||||
expect(tester.getRect(find.text(_lastRow)).bottom, moreOrLessEquals(_viewportHeight - _navBarInset));
|
||||
});
|
||||
|
||||
// The music detail screens append their own spacer to clear the floating
|
||||
// mini-player. That spacer and the system inset must add up, not replace
|
||||
// each other — the mini-player itself already floats above the nav bar.
|
||||
testWidgets('stacks the system inset under a screen-supplied trailing spacer', (tester) async {
|
||||
const spacer = 64.0;
|
||||
await _pump(tester, const _DetailSurface(trailingSpacer: spacer));
|
||||
await _scrollToEnd(tester);
|
||||
|
||||
expect(tester.getRect(find.text(_lastRow)).bottom, moreOrLessEquals(_viewportHeight - _navBarInset - spacer));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _pump(WidgetTester tester, Widget child, {double bottomInset = _navBarInset}) async {
|
||||
tester.view.physicalSize = const Size(400, _viewportHeight);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
// copyWith keeps the real viewport metrics and overrides only the
|
||||
// padding, so layout still sees a 400x800 phone.
|
||||
builder: (context) => MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(padding: EdgeInsets.only(bottom: bottomInset)),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
ScrollPosition _position(WidgetTester tester) => tester.state<ScrollableState>(find.byType(Scrollable)).position;
|
||||
|
||||
Future<void> _scrollToEnd(WidgetTester tester) async {
|
||||
final position = _position(tester);
|
||||
position.jumpTo(position.maxScrollExtent);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Widget _rows() => SliverList.builder(
|
||||
itemCount: _rowCount,
|
||||
itemBuilder: (context, index) => SizedBox(height: _rowHeight, child: Text('Row $index')),
|
||||
);
|
||||
|
||||
class _PlainScrollView extends StatelessWidget {
|
||||
const _PlainScrollView();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(child: SizedBox(height: 1000)),
|
||||
SliverSystemBottomInset(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DetailSurface extends StatefulWidget {
|
||||
const _DetailSurface({this.trailingSpacer = 0});
|
||||
|
||||
final double trailingSpacer;
|
||||
|
||||
@override
|
||||
State<_DetailSurface> createState() => _DetailSurfaceState();
|
||||
}
|
||||
|
||||
class _DetailSurfaceState extends State<_DetailSurface>
|
||||
with GridFocusNodeMixin<_DetailSurface>, FocusableDetailScreenMixin<_DetailSurface> {
|
||||
@override
|
||||
bool get hasItems => true;
|
||||
|
||||
@override
|
||||
List<FocusableAction> getAppBarActions() => const [];
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
disposeFocusResources();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return buildDetailScaffold(
|
||||
slivers: [
|
||||
_rows(),
|
||||
if (widget.trailingSpacer > 0) SliverToBoxAdapter(child: SizedBox(height: widget.trailingSpacer)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user