Fresco: I'm using the ZoomableDrawieView sample double tap zoom

Created on 3 May 2016  路  2Comments  路  Source: facebook/fresco

How can I implement double tap to zoom in the https://github.com/facebook/fresco/tree/master/samples/zoomable project?

The pinch to zoom works fine, does anyone have a working example?

Most helpful comment

Hi! I haven't checked what modifications you made to the samples code, but all you need to do is implement GestureDetector.SimpleOnGestureListener and set it as a setTapListener to your zoomable Drawee view.

 private void setTapListener(final ZoomableDraweeView view) {
    final AnimatedZoomableController zc = (AnimatedZoomableController) view.getZoomableController();
    view.setTapListener(new GestureDetector.SimpleOnGestureListener() {
      private final PointF mDoubleTapViewPoint = new PointF();
      private final PointF mDoubleTapImagePoint = new PointF();
      @Override
      public boolean onDoubleTapEvent(MotionEvent e) {
        PointF vp = new PointF(e.getX(), e.getY());
        PointF ip = zc.mapViewToImage(vp);
        switch (e.getAction()) {
          case MotionEvent.ACTION_DOWN:
            mDoubleTapViewPoint.set(vp);
            mDoubleTapImagePoint.set(ip);
            break;
          case MotionEvent.ACTION_UP:
            if (zc.getScaleFactor() < 1.5f) {
              zc.zoomToPoint(2.0f, ip, vp, DefaultZoomableController.LIMIT_ALL, 300, null);
            } else {
              zc.zoomToPoint(1.0f, ip, vp, DefaultZoomableController.LIMIT_ALL, 300, null);
            }
            break;
        }
        return true;
      }
    });
  }

All 2 comments

Here is the code for smooth double tap zoom and pinch to zoom for the fresco library
https://github.com/arlindiDev/FrescoDoubleTapZoom

Hi! I haven't checked what modifications you made to the samples code, but all you need to do is implement GestureDetector.SimpleOnGestureListener and set it as a setTapListener to your zoomable Drawee view.

 private void setTapListener(final ZoomableDraweeView view) {
    final AnimatedZoomableController zc = (AnimatedZoomableController) view.getZoomableController();
    view.setTapListener(new GestureDetector.SimpleOnGestureListener() {
      private final PointF mDoubleTapViewPoint = new PointF();
      private final PointF mDoubleTapImagePoint = new PointF();
      @Override
      public boolean onDoubleTapEvent(MotionEvent e) {
        PointF vp = new PointF(e.getX(), e.getY());
        PointF ip = zc.mapViewToImage(vp);
        switch (e.getAction()) {
          case MotionEvent.ACTION_DOWN:
            mDoubleTapViewPoint.set(vp);
            mDoubleTapImagePoint.set(ip);
            break;
          case MotionEvent.ACTION_UP:
            if (zc.getScaleFactor() < 1.5f) {
              zc.zoomToPoint(2.0f, ip, vp, DefaultZoomableController.LIMIT_ALL, 300, null);
            } else {
              zc.zoomToPoint(1.0f, ip, vp, DefaultZoomableController.LIMIT_ALL, 300, null);
            }
            break;
        }
        return true;
      }
    });
  }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

kingty picture kingty  路  4Comments

eldk picture eldk  路  3Comments

goodev picture goodev  路  4Comments

cococool picture cococool  路  4Comments

qiiyue picture qiiyue  路  4Comments