-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add scrim color parameter to _ZoomEnterTransitionPainter #152815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
Here is the test I have locally, it draws the scrim with the color, that I validated visually, but how do I check it using a test? testWidgets('ZoomPageTransition respects scrim color when set', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => Material(
child: TextButton(
child: const Text('push'),
onPressed: () { Navigator.of(context).pushNamed('/b'); },
),
),
'/b': (BuildContext context) => Container(color: const Color(0xff00ff00)),
};
await tester.pumpWidget(
MaterialApp(
routes: routes,
theme: ThemeData(
pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: ZoomPageTransitionsBuilder(
scrimColor: Color(0xffff0000),
),
},
),
),
),
);
await tester.tap(find.text('push'));
// Jump to the middle of the animation by pumping 8 frames, the scrim should be partially visible
for (int i = 0; i < 8; i++) {
await tester.pump(const Duration(milliseconds: 16));
}
final List<SnapshotWidget> snapshotWidgets = tester.widgetList(find.byType(SnapshotWidget)).cast<SnapshotWidget>().toList();
// Filter only snapshots where the painter is ZoomEnterTransitionPainter going forward
final List<ZoomEnterTransitionPainter> zoomTransitionPainters = snapshotWidgets.where((SnapshotWidget snapshot) {
final SnapshotPainter painter = snapshot.painter;
return painter is ZoomEnterTransitionPainter && !painter.reverse;
}).map((SnapshotWidget snapshot) => snapshot.painter)
.cast<ZoomEnterTransitionPainter>()
.toList();
final TestDisplay display = tester.binding.platformDispatcher.displays.first;
final int width = display.size.width.toInt();
final int height = display.size.height.toInt();
for (final ZoomEnterTransitionPainter painter in zoomTransitionPainters) {
final OffsetLayer offsetLayer = OffsetLayer();
final PaintingContext context = PaintingContext(offsetLayer, Offset.zero & display.size);
await tester.runAsync(() async {
final ui.Image image = (await (await ui.ImageDescriptor.raw(
await ui.ImmutableBuffer.fromUint8List(Uint8List.fromList(List<int>.filled(width * height * 4, 0xFF))),
width: width,
height: height,
pixelFormat: ui.PixelFormat.rgba8888,
).instantiateCodec(targetHeight: height, targetWidth: width)).getNextFrame()).image;
painter.paintSnapshot(context, Offset.zero, display.size, image, display.size, display.devicePixelRatio);
});
}
}, variant: TargetPlatformVariant.only(TargetPlatform.android)); |
|
add tests to packages/flutter/test/material/page_transitions_theme_test.dart |
|
@ElvisOkereke I know where to add them, the issue is that the class is private, I assume |
| const ZoomPageTransitionsBuilder({ | ||
| this.allowSnapshotting = true, | ||
| this.allowEnterRouteSnapshotting = true, | ||
| this.scrimColor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we set the default value here so we don't need to specifically set the color argument in line 927?
|
@QuncCccccc Sorry it took me so long, I changed the default parameter. But the question about the tests still holds. |
|
Ping @QuncCccccc |
Maybe we can provide a golden test so we can visually see the color change for the scrim:) What do you think? |
|
Yes that could be the "get out of jail free" card, however I have not created a golden test for this repository yet. I'll have to look at some existing examples on how the image files are handled. |
|
There's another PR that seems to be fixing the same issue at #154057. |
Ah you can global search "matchesGoldenFile" for some examples:) We probably can wait that PR(#154057) lands first and then add this property. What do you think:)? |
|
I think this PR should wait until the other one lands, then this PR can apply it's property to it, as well as use the test in the other PR as a basis to add another one. |
|
Looks like #154057 is merged:)! @Michal-MK Can you help resolve the conflicts and add the property? |
|
Hey, author of #154057 here! I wouldn't mind helping out with this if you want me to. It was tricky for me to figure how to test a change to an animation like this so I think I can help spare you the pain I went through, even if with that part only 👀 |
|
@dy0gu Hi thanks for the offer, I'll take a look at your test approach and attempt doing it myself (trying to learn, not to dismiss you <3). If I get stuck somewhere I will reach out. Today or over the weekend I'll get the PR ready. |
Thanks @dy0gu for figuring it out, I just took it >:D
|
@dy0gu In the end I just shamelessly copied your test, had no idea that @QuncCccccc I changed the code. |
QuncCccccc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the contribution and the test:)!
|
|
||
| /// The color of the scrim (background) that fades in and out during the transition. | ||
| /// | ||
| /// If not provided, defaults to current theme's surface color. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// If not provided, defaults to current theme's surface color. | |
| /// If not provided, defaults to current theme's [ColorScheme.surface] color. |
|
|
||
| /// The color of the scrim (background) that fades in and out during the transition. | ||
| /// | ||
| /// If not provided, defaults to current theme's surface color. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// If not provided, defaults to current theme's surface color. | |
| /// If not provided, defaults to current theme's [ColorScheme.surface] color. |
|
|
||
| // Pump till animation is half-way through. | ||
| await tester.pump(); | ||
| await tester.pump(const Duration(milliseconds:75)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| await tester.pump(const Duration(milliseconds:75)); | |
| await tester.pump(const Duration(milliseconds: 75)); |
|
|
||
| // Pump till animation is half-way through. | ||
| await tester.pump(); | ||
| await tester.pump(const Duration(milliseconds:125)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| await tester.pump(const Duration(milliseconds:125)); | |
| await tester.pump(const Duration(milliseconds: 125)); |
Implements #152064
Pre-launch Checklist
///).There is currently no test here as I am not sure how to do it efficiently, I tried making the painter public and adding the visibleForTestinhg attribute, but then I need to add comments to everything... And even when I did that I did not know how to test the painter itself maybe via Golden tests? I have not done those in the Flutter repo yet. And if it can be done without them then that is definitely a better way. I'll wait for what the review says I should do.