Skip to content
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

[BUG] Custom scale value is overridden by rescale logic during initial widget layout, not able to apply 4 custom parameters during initial image rendering #289

Closed
stepanov-standy opened this issue Jun 18, 2020 · 6 comments
Labels
bug Something isn't working P1
Projects

Comments

@stepanov-standy
Copy link

stepanov-standy commented Jun 18, 2020

Describe the bug
The library is awesome and ideally covers my needs. My use case is to remember image rotation, scale, etc. that are done by user. When user opens the same image again, I would like to show the image with previous values. PhotoViewController is an ideal way for this, but my custom scale value is overridden during initial widget layout. Details below

To Reproduce

Configuration 1

  1. Add PhotoView with image.
  2. Use controller to set initial image parameters including scale.

I see issue in the following method, where delegate forces recalculation for scale due to markNeedsScaleRecalc flag that is true:

double get scale {
    final needsRecalc = markNeedsScaleRecalc &&
        !scaleStateController.scaleState.isScaleStateZooming;
    final scaleExistsOnController = controller.scale != null;
    if (needsRecalc || !scaleExistsOnController) {
      final newScale = getScaleForScaleState(
        scaleStateController.scaleState,
        scaleBoundaries,
      );
      markNeedsScaleRecalc = false;
      scale = newScale;
      return newScale;
    }
    return controller.scale;
  }

What is the current behavior?
All parameters (rotation, position, rotationFocusPoint) except scale are applied. Scale parameter is overridden due to rescale logic.

Expected behavior
Custom scale value is correctly applied to the image.

Configuration 2

  1. Add PhotoView with image.
  2. Use initialScale property to set the scale. Set remaining 3 properties via controller.

What is the current behavior?
Only scale parameter is applied. Rotation, position, rotationFocusPoint are ignored.

Expected behavior
All 4 parameters are applied correctly.

InitialScale looks suitable for this case, moreover it works correctly. I can see that the image is scaled properly, when I set initial scale, but 3 other parameters (rotation, position, rotationFocusPoint) are not applied correctly via controller setMultiply. In other words, I can apply correct scale using initialScale property or I can correctly apply 3 remaining parameters, but only when I do not specify initialScale.

The only workaround that I have is the following. Apply image parameters after build with some delay, but it is bad solution :(

void initState() {
...
WidgetsBinding.instance
        .addPostFrameCallback((_) => applyImageParametersAfterInit(context));
...
}

rotateJumperAfterInit(BuildContext context) {
      Future.delayed(const Duration(milliseconds: 1000), () {
          photoViewController.updateMultiple(
          position: _jumperPosition,
          scale: _jumperScale,
          rotation: _jumperRotation,
          rotationFocusPoint: _jumperRotationFocusPoint);
      });
    }
  }

I am not sure if it is a defect or expected behaviour. If it is expected, please let me know how to supported my use case.

@stepanov-standy stepanov-standy added the bug Something isn't working label Jun 18, 2020
@renancaraujo renancaraujo added this to Todo in Bug solving via automation Aug 11, 2020
@stepanov-standy
Copy link
Author

@renancaraujo I've cloned your repo and tried to force the flag markNeedsScaleRecalc to be false. Unfortunately, it doesn't help. PhotoView still doesn't apply all required modifications (scale, rotation, move) to the image correctly.

@renancaraujo
Copy link
Member

Due to the interaction between the two controllers (scale state controller and the main one) we have this scaling on the mount phase.

What you want is different than initialScale stands for. InitialScale regards the double-tap cycle. This regards a starting state value.

This is a core problem with the controller.

Apparent solution: we have to add a scale to be passed via the controller constructor.

@renancaraujo
Copy link
Member

Could you test this branch if it works for you: #322

In this way you pass the starting scale to the controller constructor.

@renancaraujo renancaraujo moved this from Todo to In progress in Bug solving Nov 15, 2020
@renancaraujo renancaraujo moved this from In progress to Done in Bug solving Nov 15, 2020
@renancaraujo
Copy link
Member

Adde an initial scale option to #322

@renancaraujo renancaraujo moved this from Done to awaiting release in Bug solving Nov 15, 2020
@renancaraujo
Copy link
Member

I guess this is closed now?

@renancaraujo renancaraujo moved this from awaiting release to Done in Bug solving Sep 16, 2021
@renancaraujo renancaraujo moved this from Done to Todo in Bug solving May 24, 2022
@stepanov-standy
Copy link
Author

Dear @renancaraujo, I am so sorry that I've missed this reply from you. Thank you for all your work and great library. I am going to implement supported initial scale in upcoming release! :)

Bug solving automation moved this from Todo to awaiting release Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1
Projects
Bug solving
  
awaiting release
Development

No branches or pull requests

2 participants