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

Android zoom issues #270

Closed
AlexV525 opened this issue Jan 25, 2020 · 3 comments
Closed

Android zoom issues #270

AlexV525 opened this issue Jan 25, 2020 · 3 comments

Comments

@AlexV525
Copy link
Contributor

AlexV525 commented Jan 25, 2020

Environment

Flutter version: 1.12.13+hotfix.5
Plugin version: 3.0.0 9c7ac0d
Android version: Android 8/ 10
Device information: Emulator, OnePlus 3, OnePlus 6T

Description

There're AT LEASE 3 ISSUES related to zoom control on Android platform. (#232, #258, etc)
As I investigate, both of them can be solved with some imperfect solution. I'll explain them below.
For now, zoom on Android is nearly broken.

1. Zoom controls cannot control the zoom behavior

Step to reproduce

  1. Set displayZoomControls with true.
  2. Click/Tap on control buttons, nothing happened.

2. #232, #258

Root cause

The reason why pinch gesture failed infected by two reasons.

  1. setDesktopMode re-write user defined options.
    if (options.preferredContentMode != null) {
    switch (fromValue(options.preferredContentMode)) {
    case DESKTOP:
    setDesktopMode(true);
    break;
    case MOBILE:
    case RECOMMENDED:
    setDesktopMode(false);
    break;
    }
    }

    Default value of preferredContentMode is RECOMMENDED (0), when the code run into this function, it will disabled loadWithOverviewMode, useWideViewPort, builtInZoomControls, supportZoom no matter what value you set before.
  2. When displayZoomControls is false which is by default, the pinch gesture is failed but double tap still worked. I didn't found why this will happened.

Solution

So the solution comes clearly.

  1. Lines at android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebView.java#L653-L663 can be changed to:
if (options.preferredContentMode == PreferredContentModeOptionType.DESKTOP.toValue()) {
    setDesktopMode(true);
}

Then split user agent switcher from setDesktopMode for a better UA creation.
2. Figure out why displayZoomControls takes effect to zoom gestures.

@Hong-Jie-IXEN
Copy link

When displayZoomControls is false which is by default, the pinch gesture is failed but double tap still worked. I didn't found why this will happened.

Seems like the following function is the cause of zoom not working if you set displayZoomControls to false

`setOnTouchListener(new View.OnTouchListener() {
float m_downX;
float m_downY;

  @Override
  public boolean onTouch(View v, MotionEvent event) {

    if (event.getPointerCount() > 1) {
      //Multi touch detected
      return true;
    }

    if (options.disableHorizontalScroll && options.disableVerticalScroll) {
      return (event.getAction() == MotionEvent.ACTION_MOVE);
    }
    else if (options.disableHorizontalScroll || options.disableVerticalScroll) {
      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN: {
          // save the x
          m_downX = event.getX();
          // save the y
          m_downY = event.getY();
          break;
        }
        case MotionEvent.ACTION_MOVE:
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP: {
          if (options.disableHorizontalScroll) {
            // set x so that it doesn't move
            event.setLocation(m_downX, event.getY());
          } else {
            // set y so that it doesn't move
            event.setLocation(event.getX(), m_downY);
          }
          break;
        }
      }
    }
    return false;
  }
});`

By commenting out the function. I was able to zoom the page without showing zoom controls.

Tested on a Xiaomi Redmi Note 4 - Android 6
Flutter version: 1.9.1+hotfix5
Plugin version: 2.1.0+1

@AlexV525
Copy link
Contributor Author

AlexV525 commented Mar 21, 2020

Seems like the following function is the cause of zoom not working if you set displayZoomControls to false

Huge thanks for pointing it out, I'll try this ASAP.

@pichillilorenzo
Copy link
Owner

Published new version 3.0.0 with the fix! Thanks!

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

3 participants