fix(shell): keep the tab destination ready behind pushed pages
This commit is contained in:
@@ -446,10 +446,6 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
final chatRoute = tab(AppDestination.chat);
|
||||
return AdaptiveShell(
|
||||
attentionCount: attentionCount,
|
||||
detailOpen:
|
||||
route.runId != null ||
|
||||
route.chatSessionId != null ||
|
||||
(route.kind == AppRouteKind.pipelines && route.pipelineId != null),
|
||||
cupertino: _cupertino,
|
||||
destination: _destinationOf(route.kind),
|
||||
onDestinationSelected: _selectDestination,
|
||||
|
||||
@@ -15,7 +15,6 @@ class AdaptiveShell extends StatefulWidget {
|
||||
this.onDestinationSelected,
|
||||
this.onSearch,
|
||||
this.attentionCount = 0,
|
||||
this.detailOpen = false,
|
||||
});
|
||||
|
||||
final Map<AppDestination, WidgetBuilder> destinationBodies;
|
||||
@@ -34,10 +33,6 @@ class AdaptiveShell extends StatefulWidget {
|
||||
/// so it stays visible from any destination. Zero shows no badge.
|
||||
final int attentionCount;
|
||||
|
||||
/// A pipeline, run or chat is open: on a phone it takes the whole screen,
|
||||
/// like its own page, and the destination bar steps aside until Back.
|
||||
final bool detailOpen;
|
||||
|
||||
@override
|
||||
State<AdaptiveShell> createState() => _AdaptiveShellState();
|
||||
}
|
||||
@@ -188,19 +183,18 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
: Column(
|
||||
children: [
|
||||
Expanded(child: _destinationStack(contents, index)),
|
||||
if (!widget.detailOpen)
|
||||
CupertinoTabBar(
|
||||
currentIndex: index,
|
||||
onTap: (value) =>
|
||||
_select(AppDestination.values[value]),
|
||||
items: _items((destination) {
|
||||
final item = destinationDetails(destination);
|
||||
return BottomNavigationBarItem(
|
||||
icon: _icon(destination, item.cupertinoIcon),
|
||||
label: item.label,
|
||||
);
|
||||
}),
|
||||
),
|
||||
CupertinoTabBar(
|
||||
currentIndex: index,
|
||||
onTap: (value) =>
|
||||
_select(AppDestination.values[value]),
|
||||
items: _items((destination) {
|
||||
final item = destinationDetails(destination);
|
||||
return BottomNavigationBarItem(
|
||||
icon: _icon(destination, item.cupertinoIcon),
|
||||
label: item.label,
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -256,7 +250,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
Expanded(child: _destinationStack(contents, index)),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: wide || widget.detailOpen
|
||||
bottomNavigationBar: wide
|
||||
? null
|
||||
: NavigationBar(
|
||||
selectedIndex: index,
|
||||
|
||||
@@ -100,22 +100,34 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('an open detail fills a phone screen without the tab bar', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
Widget shell({required bool detail}) => MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destination: AppDestination.runs,
|
||||
detailOpen: detail,
|
||||
destinationBodies: {AppDestination.runs: (_) => const Text('runs')},
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(shell(detail: false));
|
||||
expect(find.byType(NavigationBar), findsOneWidget);
|
||||
await tester.pumpWidget(shell(detail: true));
|
||||
expect(find.byType(NavigationBar), findsNothing);
|
||||
});
|
||||
testWidgets(
|
||||
'a pushed detail covers tabs without unmounting the Back destination',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
Widget shell() => MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destination: AppDestination.runs,
|
||||
destinationBodies: {AppDestination.runs: (_) => const Text('runs')},
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(shell());
|
||||
expect(find.byType(NavigationBar), findsOneWidget);
|
||||
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
|
||||
navigator.push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => const Scaffold(body: Text('detail')),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(NavigationBar), findsNothing);
|
||||
expect(find.byType(NavigationBar, skipOffstage: false), findsOneWidget);
|
||||
await navigator.maybePop();
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
expect(find.byType(NavigationBar), findsOneWidget);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(NavigationBar), findsOneWidget);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user