Open abusaadp opened 1 year ago
Same here...
I have the same issue. I wonder if this is caused by a recent update of the WebView2 runtime: 1.0.1823.32 or not. https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes?tabs=dotnetcsharp
there is a workaround ,it's work for me.
in flutter side,catch the mouse position when mouse move ,send mouse positioin to webview when mosuse scroll. In webview, find the element by position which send from flutter, and then judge the element can scroll or not, if it can scroll ,handle the scorll event, if not, post the event to it's parent element ,do the same thing. if there is no element can hanlde the scroll event ,drop it. here is the code:
//init js method when webview page init
_initScrollJs(){ _wController.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{ //if ele can't scroll ,find it's parent. return eleCanScroll( ele.parentElement); } } } """); }
//when mouse scroll ,accept the mouse position
_setWebViewScroll(double x,double y,double dx,double dy){ print('_setWebViewScroll------$x----$y-------$dx---------$dy'); _wController.executeScript(""" var el = document.elementFromPoint($x,$y); //get the scroll element var el2 = eleCanScroll(el); //handle scroll el2.scrollBy($dx,$dy); """); }
//on flutter, listen the mouse move and scroll event
Listener( onPointerSignal: (signal){ if (signal is PointerScrollEvent) { _setWebViewScroll(pageKey: GlobalValues.currentShowPrgPageKey,x:GlobalValues.pointX,y: GlobalValues.pointY,dx: signal.scrollDelta.dx,dy: signal.scrollDelta.dy); } }, onPointerHover: (ev) { GlobalValues.pointX = ev.localPosition.dx; GlobalValues.pointY = ev.localPosition.dy; }, child :'your webview page' )
@NickYoung-max It looks like a good idea, but it doesn't work in some cases. if the scroll element's parent node is HTMLIFrameElement(iframe),scrollling failed, in the case, document.elementFromPoint($x,$y) always return HTMLIFrameElement.
I am not able to scroll the webview with a mouse. Is there any workaround for it?