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

Is there a way to make PhotoView work with Fresco? #178

Closed
shen0834 opened this issue Apr 22, 2015 · 9 comments
Closed

Is there a way to make PhotoView work with Fresco? #178

shen0834 opened this issue Apr 22, 2015 · 9 comments
Assignees

Comments

@shen0834
Copy link

https://github.com/chrisbanes/PhotoView/blob/master/library/src/main/java/uk/co/senab/photoview/PhotoView.java

i'm trying to use fresco replace the imageloder ,
i'm trying to let PhotoView extends SimpleDraweeView , override the method onDraw and onTouchEvent,but PhotoView It doesn't work

Is there a way to make PhotoView work with Fresco?
Thanks!

@plamenko
Copy link
Contributor

The most likely reason why it doesn't work is because the drawable used by Drawee doesn't expose its intrinsic dimensions (i.e. it always returns -1). Because of that PhotoViewAttacher cannot determine the size of the image.
The reason why Drawee top-level-drawable doesn't expose its intrinsic dimensions is because intrinsic dimensions change when the image loads. In particular, first the placeholder drawable is displayed and therefore the intrinsic dimensions should be that of the placeholder drawable. Then once the actual image loads, for a brief period of time, during the fade animatiom, both placeholder and the actual image are visible. It is not clear what intrinsic dimensions should be reported at that time (perhaps max of the two?). Finally, once the fade animation is over, the intrinsic dimensions should be that of the actual image. Drawee knows how to handle those changes gracefully, but we cannot assume the same for the containing image view. Therefore, we decided not to return intrinsic dimensions and to handle scaling internally instead.

I don't think PhotoView / PhotoViewAttacher can easily be made work with Fresco because PhotoViewAttacher relies on ImageView and Drawee doesn't support ImageView attributes. For example, PhotoViewAttacher sets MATRIX scale type and then tries to set the matrix to the ImageView.

There is however a way to make Drawee work with some zoomble logic. First, you need to specify a controller listener while building the controller, so that you can intercept the load events (onFinalImageSet for example). See http://frescolib.org/docs/listening-download-events.html#_
Then, when the image gets loaded, you can enable your zoomable logic and inform it about the image dimensions. To get the bounds of the image in the view, see GenericDraweeHierarchy.getActualImageBounds.

@shen0834
Copy link
Author

thinks your help!

https://github.com/shen0834/wangyue-learngit/blob/master/SimplePhotoView.java

I made a simple implementation, if some one also have the same problem, you can refer to

@tyronen tyronen closed this as completed Apr 24, 2015
@tyronen tyronen mentioned this issue Apr 24, 2015
@chongivan
Copy link

@shen0834
Copy link
Author

i will add description provided 6 hours later ,now it's working time

@chongivan
Copy link

@shen0834 have a nice day =)

@kunny
Copy link
Contributor

kunny commented Jun 16, 2015

It seems Fresco now supports pinch-to-zoom feature, with ZoomableDraweeView.
See commit 4e516e7 for the details, and those who are interested to its usage, see ZoomableDraweeView-sample on GitHub.

@ffelini
Copy link

ffelini commented Sep 28, 2015

Hey guys. If anyone still interested in how to use PhotoViewAttacher with Fresco here is my solution.

public class PhotoViewDraweeAttacher extends PhotoViewAttacher<SimpleDraweeView> {

    private RectF displayRect;

    public PhotoViewDraweeAttacher(SimpleDraweeView imageView) {
        super(imageView);
    }

    public RectF getActualImageBounds() {
        try {
            if(displayRect==null) {
                displayRect = new RectF();
            }
            getImageView().getHierarchy().getActualImageBounds(displayRect);
        } catch (Exception e) {
        }
        return displayRect;
    }

    @Override
    protected int getImageViewWidth(SimpleDraweeView imageView) {
        displayRect = getActualImageBounds();
        if (!displayRect.isEmpty()) {
            return ((int) displayRect.width());
        }
        return super.getImageViewWidth(imageView);
    }

    @Override
    protected int getImageViewHeight(SimpleDraweeView imageView) {
        displayRect = getActualImageBounds();
        if (!displayRect.isEmpty()) {
            return ((int) displayRect.height());
        }
        return super.getImageViewHeight(imageView);
    }

    @Override
    protected int getIntrinsicWidth(SimpleDraweeView imageView) {
        displayRect = getActualImageBounds();
        if (!displayRect.isEmpty()) {
            return ((int) displayRect.width());
        }
        return super.getIntrinsicWidth(imageView);
    }

    @Override
    protected int getIntrinsicHeight(SimpleDraweeView imageView) {
        displayRect = getActualImageBounds();
        if (!displayRect.isEmpty()) {
            return ((int) displayRect.height());
        }
        return super.getIntrinsicHeight(imageView);
    }
}

@ffelini
Copy link

ffelini commented Oct 6, 2015

If anyone still interested in PhotoView version that works with Fresco here is my fork https://github.com/namshi/PhotoView/tree/fresco_refactoring

Rotation feature not working properly yet.

@bastiotutuama
Copy link

Hey @ffelini, thanks for your fork. It works well, but the picture does not stay centered while zooming. I did not investigate it further, but i found another working solution, which does the job. See here: https://github.com/06peng/FrescoDemo/tree/master/app/src/main/java/uk/co/senab/photoview.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants