#94 paint color background during thumbnail hero

This commit is contained in:
Thibault Deckers 2021-10-06 16:45:30 +09:00
parent e3f5e1aaff
commit 51c92fe6ed
2 changed files with 11 additions and 1 deletions

View file

@ -13,6 +13,7 @@ class TransitionImage extends StatefulWidget {
final double? width, height;
final ValueListenable<double> animation;
final bool gaplessPlayback = false;
final Color? background;
const TransitionImage({
Key? key,
@ -20,6 +21,7 @@ class TransitionImage extends StatefulWidget {
required this.animation,
this.width,
this.height,
this.background,
}) : super(key: key);
@override
@ -136,10 +138,10 @@ class _TransitionImageState extends State<TransitionImage> {
valueListenable: widget.animation,
builder: (context, t, child) => CustomPaint(
painter: _TransitionImagePainter(
// AssetImage(name).resolve(configuration)
image: _imageInfo?.image,
scale: _imageInfo?.scale ?? 1.0,
t: t,
background: widget.background,
),
),
);
@ -150,11 +152,13 @@ class _TransitionImagePainter extends CustomPainter {
final ui.Image? image;
final double scale;
final double t;
final Color? background;
const _TransitionImagePainter({
required this.image,
required this.scale,
required this.t,
this.background,
});
@override
@ -185,6 +189,9 @@ class _TransitionImagePainter extends CustomPainter {
sourceSize,
Offset.zero & inputSize,
);
if (background != null) {
canvas.drawRect(destinationRect, Paint()..color = background!);
}
canvas.drawImageRect(image!, sourceRect, destinationRect, paint);
}

View file

@ -232,12 +232,15 @@ class _ThumbnailImageState extends State<ThumbnailImage> {
);
if (animate && widget.heroTag != null) {
final background = settings.imageBackground;
final backgroundColor = background.isColor? background.color : null;
image = Hero(
tag: widget.heroTag!,
flightShuttleBuilder: (flight, animation, direction, fromHero, toHero) {
return TransitionImage(
image: entry.bestCachedThumbnail,
animation: animation,
background: backgroundColor,
);
},
transitionOnUserGestures: true,