fixed minimap for untiled raw images with different decoded image size

This commit is contained in:
Thibault Deckers 2020-11-12 11:57:39 +09:00
parent c410f83b6d
commit b89e5d6c3f
3 changed files with 19 additions and 9 deletions

View file

@ -41,6 +41,7 @@ class _ImageViewState extends State<ImageView> {
final PhotoViewController _photoViewController = PhotoViewController();
final ValueNotifier<ViewState> _viewStateNotifier = ValueNotifier<ViewState>(ViewState.zero);
StreamSubscription<PhotoViewControllerValue> _subscription;
Size _photoViewChildSize;
static const backgroundDecoration = BoxDecoration(color: Colors.transparent);
static const maxScale = 2.0;
@ -53,6 +54,9 @@ class _ImageViewState extends State<ImageView> {
void initState() {
super.initState();
_subscription = _photoViewController.outputStateStream.listen(_onViewChanged);
if (entry.isVideo || (!entry.isSvg && entry.canDecode && useTile)) {
_photoViewChildSize = entry.displaySize;
}
}
@override
@ -140,6 +144,10 @@ class _ImageViewState extends State<ImageView> {
),
loadFailedChild: _buildError(),
backgroundDecoration: backgroundDecoration,
imageSizedCallback: (size) {
// do not directly update the `ViewState` notifier as this callback is called during build
_photoViewChildSize = size;
},
controller: _photoViewController,
maxScale: maxScale,
minScale: PhotoViewComputedScale.contained,
@ -229,7 +237,7 @@ class _ImageViewState extends State<ImageView> {
);
void _onViewChanged(PhotoViewControllerValue v) {
final viewState = ViewState(v.position, v.scale);
final viewState = ViewState(v.position, v.scale, _photoViewChildSize);
_viewStateNotifier.value = viewState;
ViewStateNotification(entry.uri, viewState).dispatch(context);
}
@ -238,14 +246,15 @@ class _ImageViewState extends State<ImageView> {
class ViewState {
final Offset position;
final double scale;
final Size size;
static const ViewState zero = ViewState(Offset(0.0, 0.0), 0);
static const ViewState zero = ViewState(Offset(0.0, 0.0), 0, null);
const ViewState(this.position, this.scale);
const ViewState(this.position, this.scale, this.size);
@override
String toString() {
return '$runtimeType#${shortHash(this)}{position=$position, scale=$scale}';
return '$runtimeType#${shortHash(this)}{position=$position, scale=$scale, size=$size}';
}
}

View file

@ -27,12 +27,13 @@ class Minimap extends StatelessWidget {
return AnimatedBuilder(
animation: viewStateNotifier,
builder: (context, child) {
final viewState = viewStateNotifier.value;
return CustomPaint(
painter: MinimapPainter(
entrySize: entry.displaySize,
viewportSize: mqSize,
viewCenterOffset: viewStateNotifier.value.position,
viewScale: viewStateNotifier.value.scale,
entrySize: viewState.size ?? entry.displaySize,
viewCenterOffset: viewState.position,
viewScale: viewState.scale,
minimapBorderColor: Colors.white30,
),
size: size,
@ -49,8 +50,8 @@ class MinimapPainter extends CustomPainter {
final Color minimapBorderColor, viewportBorderColor;
const MinimapPainter({
@required this.entrySize,
@required this.viewportSize,
@required this.entrySize,
@required this.viewCenterOffset,
@required this.viewScale,
this.minimapBorderColor = Colors.white,

View file

@ -674,7 +674,7 @@ packages:
description:
path: "."
ref: HEAD
resolved-ref: "79a3c20ee7f01e6ffb71464000c2ca8f1e28ec44"
resolved-ref: aa6400bbc85bf6ce953c4609d126796cdb4ca3c2
url: "git://github.com/deckerst/photo_view.git"
source: git
version: "0.9.2"