flutter-webview-windows icon indicating copy to clipboard operation
flutter-webview-windows copied to clipboard

Scroll down and Up are not working.

Open toannguyendts opened this issue 4 years ago • 17 comments

I try to use mouse scroll . But It is not affected. I have tested it on WPF. It is working perfectly. Anh Touch support only click. Cannot move. Thank!

I tested it on https://joltfly.com/mouse-test/

toannguyendts avatar Jun 30 '21 13:06 toannguyendts

I have the same problem @jnschulze @toannguyendts

Milesssssss avatar Jul 02 '21 10:07 Milesssssss

Scrolling works for me but in order to debug this, you can do a quick check if the problem is on the Dart or the native side.

This plugin uses the Listener widget on the Dart side for detecting scroll events. You might set up a Listener and see if it fires scroll events (using onPointerSignal).

jnschulze avatar Jul 03 '21 11:07 jnschulze

image @jnschulze you can move your mouse to this area and scroll it. It cannot scroll box inside. It is working only outside

toannguyendts avatar Jul 07 '21 06:07 toannguyendts

Hi @toannguyendts, you can help me to setup this package in my project? You can provide your current version flutter. Because I have error in my project. You can show more error in this link: #41

tuantiensiu avatar Aug 18 '21 10:08 tuantiensiu

Scrolling works for me but in order to debug this, you can do a quick check if the problem is on the Dart or the native side.

This plugin uses the Listener widget on the Dart side for detecting scroll events. You might set up a Listener and see if it fires scroll events (using onPointerSignal).

I checked on my widget for using "onPointerSignal",the scroll events in widget worked,but in the webview's page,the scroll event doesn't worked

angle222 avatar May 20 '22 14:05 angle222

Scrolling works for me but in order to debug this, you can do a quick check if the problem is on the Dart or the native side.

This plugin uses the Listener widget on the Dart side for detecting scroll events. You might set up a Listener and see if it fires scroll events (using onPointerSignal).

So the scrolling does work, but the only places where it doesn't work (as expected) is when there are smaller containers in the webpage which are scrollable.

Expected Behaviour: When the mouse is placed on / hovered on the (webpage) container and scrolled, the scroll bar inside the smaller container should be considered and not the main page scroll bar (if it exists)

Current Behaviour: The mouse location doesn't really seem to matter, it will always interact with the main page (largest) scrollbar.

Ingenious-c0der avatar Jun 11 '22 19:06 Ingenious-c0der

I am having the same issue with ESRI Map in webview, Zoom and zoom out by scrolling doesn't work. I am using the latest version. I can see code reach

return _methodChannel.invokeMethod('setScrollDelta', [dx, dy]);
But after that I believe we need to run in native to debug Any update on this? Update: I end up creating own Listener widget and update the same listener in web content as well.

tashi146 avatar Jul 22 '22 13:07 tashi146

@tashi146 , could you describe exactly what you did to workaround the issue? I debugged the case and the line setScrollDelta is called when scrolling a small container with scrollbar. Which listener did you update in web content? Thanky you!

incspitz avatar Sep 21 '22 10:09 incspitz

any updates?

cathino avatar Dec 04 '22 11:12 cathino

Scrolling works for me but in order to debug this, you can do a quick check if the problem is on the Dart or the native side.

This plugin uses the Listener widget on the Dart side for detecting scroll events. You might set up a Listener and see if it fires scroll events (using onPointerSignal).

So the scrolling does work, but the only places where it doesn't work (as expected) is when there are smaller containers in the webpage which are scrollable.

Expected Behaviour: When the mouse is placed on / hovered on the (webpage) container and scrolled, the scroll bar inside the smaller container should be considered and not the main page scroll bar (if it exists)

Current Behaviour: The mouse location doesn't really seem to matter, it will always interact with the main page (largest) scrollbar.

Did you solve it.

979liyang avatar Mar 08 '23 09:03 979liyang

同样的问题,无法与网页小滚动条交互,始终是与最外层的滚动条交互。有解决问题的麻烦回复我下谢谢,[email protected]

aisams avatar Apr 12 '23 07:04 aisams

I have solution for this. You must custom onPointerSignal of lib. By my way, I dont use _controller._setScrollDelta . I will use postMessage to my web apps. Then my webapps can capture event scroll. Finally, you can control event scroll by your self.

*Flutter Side: Go to webview_windows.dart Add function below

String postMouseEvent(String mouseEvent,dynamic data)
  {
    return jsonEncode({"mouse_event" : mouseEvent,"data" : data});
  }

Then override onPotinerSignal

onPointerSignal: (signal) {
                        if (signal is PointerScrollEvent) {
                          String mouse_event = postMouseEvent("scroll",{"scroll_delta_dx":-signal.scrollDelta.dx,"scroll_delta_dy":-signal.scrollDelta.dy});
                          _controller.postWebMessage(mouse_event);
                          // _controller._setScrollDelta(
                          //     -signal.scrollDelta.dx, -signal.scrollDelta.dy);
                        }
                      },
  • Web App
 document.getElementsByTagName("body")[0].addEventListener("mousemove", (e) => {
      this.element = document.elementFromPoint(e.x, e.y);
      // this.mousePos = { x: e.x, y: e.y };
    });

    if (typeof window.chrome.webview !== "undefined") {
      window.chrome.webview.removeEventListener("message");
      window.chrome.webview.addEventListener("message", this.handleMessage);
    }

handleMessage(message) { let direction = message.data.data.scroll_delta_dy > 0 ? -1 : 1; let distance = 40; if(this.getScrollDiv(this.element)) { let classList = this.getScrollDiv(this.element).classList; let queryString = ""; for(let i = 0; i < classList.length; i++) { queryString += ('.' + classList[i]); } let elems = document.querySelectorAll(queryString); if (elems && elems[0]) { elems.forEach((elem) => { elem.scrollTop += direction * distance; }); } } }, getScrollDiv(el) { while (el && el.parentNode) { if(el.style.overflow == "auto" || el.style.overflow == "scroll" || el.style.overflowY == "auto" || el.style.overflowY == "scroll") { return el; } el = el.parentNode; } return null; },

toannguyendts avatar Apr 14 '23 08:04 toannguyendts

We solved it in a similar fashion, here is the source code for reference:



  Future<void> scrollWebview(double mouseX, double mouseY, double dx, double dy) {
    return _windowsController.executeScript("""
            function eleCanScroll(ele) {
              if (ele.scrollTop > 0) { return ele; }
              else {
                ele.scrollTop++;
                const top = ele.scrollTop;
                top && (ele.scrollTop = 0);
                if(top > 0){
                  return ele;
                } else {
                  return eleCanScroll( ele.parentElement);
                }
              }
            }
            var el = document.elementFromPoint($mouseX,$mouseY);
            var el2 = eleCanScroll(el);
            el2.scrollBy($dx,$dy);
            """);
  }


// ... inside your body use:
return Listener(
        onPointerPanZoomUpdate: (event) {
          final Offset panDelta = event.panDelta;
          final Offset position = event.position;
          scrollWebview(position.dx, position.dy, panDelta.dx, panDelta.dy);
        },
        onPointerSignal: (signal) {
          if (signal is PointerScrollEvent) {
            final Offset scrollDelta = signal.scrollDelta;
            final Offset position = signal.position;
            scrollWebview(position.dx, position.dy, scrollDelta.dx, scrollDelta.dy);
          }
        },
        child: Stack(
          children: [
            webview_windows.Webview(
              _windowsController,
            ),
            StreamBuilder<webview_windows.LoadingState>(
              stream: _windowsController.loadingState,
              builder: (context, snapshot) {
                if (snapshot.hasData && snapshot.data == webview_windows.LoadingState.loading) {
                  return const LinearProgressIndicator();
                } else {
                  return const SizedBox();
                }
              },
            ),
          ],
        ),
      );

bvoq avatar Oct 17 '23 08:10 bvoq