Add explicit surface visibility signal
Provide composable shown/current visibility for retained surfaces and migrate visibility readers away from TickerMode. This keeps ticker muting separate from painted and current-surface state.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/motion/fade_through_stack.dart';
|
||||
import 'package:pipelines_app/ui/motion/surface_visibility.dart';
|
||||
|
||||
class _Values extends StatelessWidget {
|
||||
const _Values({this.onBuild});
|
||||
|
||||
final VoidCallback? onBuild;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
onBuild?.call();
|
||||
return Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Text(
|
||||
'${SurfaceVisibility.shownOf(context)}:${SurfaceVisibility.currentOf(context)}',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('defaults to shown and current', (tester) async {
|
||||
await tester.pumpWidget(const _Values());
|
||||
expect(find.text('true:true'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('nested visibility combines', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const SurfaceVisibility(
|
||||
shown: false,
|
||||
current: true,
|
||||
child: SurfaceVisibility(shown: true, current: true, child: _Values()),
|
||||
),
|
||||
);
|
||||
expect(find.text('false:false'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('dependents rebuild when visibility changes', (tester) async {
|
||||
var builds = 0;
|
||||
Widget app(bool shown) => SurfaceVisibility(
|
||||
shown: shown,
|
||||
current: shown,
|
||||
child: _Values(onBuild: () => builds++),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(app(true));
|
||||
expect(builds, 1);
|
||||
await tester.pumpWidget(app(false));
|
||||
expect(builds, 2);
|
||||
expect(find.text('false:false'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('FadeThroughStack marks only the active page current', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
const Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: FadeThroughStack(index: 0, children: [_Values(), _Values()]),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('true:true'), findsOneWidget);
|
||||
expect(find.text('false:false', skipOffstage: false), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/motion/surface_visibility.dart';
|
||||
import 'package:pipelines_app/ui/text/elapsed_clock.dart';
|
||||
import 'package:pipelines_app/ui/text/live_elapsed_builder.dart';
|
||||
|
||||
@@ -87,8 +88,9 @@ void main() {
|
||||
textDirection: TextDirection.ltr,
|
||||
child: ElapsedClockScope(
|
||||
clock: clock,
|
||||
child: TickerMode(
|
||||
enabled: shown,
|
||||
child: SurfaceVisibility(
|
||||
shown: shown,
|
||||
current: shown,
|
||||
child: LiveElapsedBuilder(
|
||||
since: start,
|
||||
builder: (context, now) =>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/motion/surface_visibility.dart';
|
||||
import 'package:pipelines_app/ui/text/relative_time.dart';
|
||||
import 'package:pipelines_app/ui/text/relative_time_clock.dart';
|
||||
import 'package:pipelines_app/ui/text/relative_time_label.dart';
|
||||
@@ -62,8 +63,9 @@ void main() {
|
||||
final instant = _minute().subtract(const Duration(minutes: 4));
|
||||
var builds = 0;
|
||||
Widget app(bool enabled) => MaterialApp(
|
||||
home: TickerMode(
|
||||
enabled: enabled,
|
||||
home: SurfaceVisibility(
|
||||
shown: enabled,
|
||||
current: enabled,
|
||||
child: Builder(
|
||||
builder: (_) {
|
||||
builds++;
|
||||
|
||||
Reference in New Issue
Block a user