I have a webview that I am using inside a NativeScript app. The issue being that when a swipe occurs that causes a momentum scroll in either direction, if the phone is under load from lack of resources or its just doing something in the background the scroll direction will bounce to the wrong direction than what was originally swiped. The Code:
<html>
<body>
<div style="height: 100000px;"> </div>
<script src="./lib/jquery-3.4.1.min.js"></script>
<script src="./my-script.js"></script>
</body>
</html>
$(document).ready(function () {
var lastY = 0; // Needed in order to determine direction of scroll.
var lastTouchDirection;
var lastScrollTop = 0;
$("div").on('touchstart', function(event) {
console.log('touchstart');
lastY = event.touches[0].clientY;
});
$('div').on('touchmove', function(event) {
console.log('touchmove');
var top = event.touches[0].clientY;
var direction = (lastY - top) < 0 ? "up" : "down";
lastTouchDirection = direction;
lastY = top;
});
$('div').on('touchend', function(event) {
console.log('touchend');
});
$(window).scroll(function(event) {
var st = $(this).scrollTop();
if (st > lastScrollTop){
console.log("downscroll")
if (lastTouchDirection == "up") {
console.log("wrong Direction")
}
} else {
console.log("upscroll")
if (lastTouchDirection == "down") {
console.log("wrong Direction")
}
}
lastScrollTop = st;
});
});
As you can see there isn't anything unique here, the code I have is for checking what was the last direction of the touch event and what direction the scroll is currently moving. I'm guessing this has something to do with nativescript and the webview package I am using since I don't see this issue happen in the inbuilt webview from nativescript.
My next step will be to correct the scroll direction programatically when it detects that it is going in the wrong direction but I was hoping that I could correct whatever is causing this to happen in the first place. What am I missing here?
NativeScript version: 6.1.0 The web view package is called nativescript-webview-interface and its used for having two way communication between nativescript and the web view.
Just for anyone that comes across this issue, I corrected it by correcting the source of the heavy load which ended up being a bug in nativescript. I have no idea why this had any effect on the webview but it is what it is.