flutter-webview-windows
flutter-webview-windows copied to clipboard
the scroll event in the webview page inside doesn't work
how to fix it? @jnschulze
I have the same issue, anyone can resolve it?
I have the same issue, anyone can resolve it?
The source code of loading WebView is C++,Some people also pointed out this problem,but the author doesn't seem to think this is a bug, please checked the issue #28
also in #182
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' )
@jnschulze
https://www.w3.org/WAI/WCAG22/Understanding/dragging-movements