React Native WebView Scrolling Behavior Not Working Properly

I have my own application that uses React Native WebView to wrap a web page.

<WebView ref={webview => (this.webview = webview)} source={{ uri: `http://localhost:8000` }} /> 

In this example, the page simply points to the localhost instance, which has the following code, which increments the number as the user scrolls:

 var i = 0; var $el = document.getElementById('counter') window.addEventListener('scroll', function(e) { e.preventDefault(); i += 1; $el.innerText = i }); 
 <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body style="height: 2000px; background: linear-gradient(dodgerblue, yellowgreen)"> <div id="type"></div> <div id="counter" style="position: fixed">0</div> </body> </html> 

The scroll behavior inside the React Native WebView behaves in a way that is different from the browser. It waits for the scroll to complete before the scroll event scroll .

Here is a comparison of behavior; in the browser, the scroll event is fired while the scroll is in progress, as desired and as expected:

scroll-behavior - browser

In a React Native project in iOS 11, the scroll event fires after the scroll completes:

scroll-behavior - simulator

This behavior is apparently used for performance reasons, but that's all but killing the intended behavior of my application.

Is there any other work that I have not thought about?

How can I guarantee that the scroll event behaves the same as the browser inside my React Native app?

+7
ios reactjs scroll react-native webview
source share
2 answers

I found below information about MDN scroll event documentation . I think the problem is not related to the reaction.

Browser compatible

iOS UIWebView

On iOS UIWebViews, scroll events do not fire during scrolling; they are fired only after scrolling is completed. See Bootstrap Question No. 16202 . Safari and This error does not affect WKWebViews.

+1
source share

The issue was resolved using WKWebView instead of React Native WebView.

+1
source share

All Articles