Answer the question
In order to leave comments, you need to log in
How to implement react-native-webview onScroll?
Good day. I'm using the new react-native-webview package and trying to hang a function on page scroll. It seems to be nothing complicated, but for some reason it does not work. Maybe I'm doing something wrong.
<WebView
source={{
uri: this.state.chosenCityUrl,
"Accept-Language": navigator.language,
"User-Agent": Platform.OS,
}}
javaScriptEnabled={true}
ref={(b) => this._bridge = b}
injectedJavaScript='window.onscroll=function(){alert("Not WORK");}'
//injectedJavaScript='window.addEventListener("scroll", function(e)
// { alert("Not WORK");
// });
/>
Answer the question
In order to leave comments, you need to log in
I don't know why but this code works for my site
<WebView
source={{
uri: this.state.chosenCityUrl,
"Accept-Language": navigator.language,
"User-Agent": Platform.OS,
}}
javaScriptEnabled={true}
ref={(b) => this._bridge = b}
style={styles.webView}
onError={(error) => {
console.log("error", error);
return NetInfo.isConnected.fetch().done(isConnected => this.setState({isConnected}))
}}
onLoadEnd={(e) => this.onLoadEnd(e)}
renderError={() => this.renderError()}
onNavigationStateChange={this._onNavigationStateChange.bind(this)}
onMessage={event => this.onMessage(event)}
injectedJavaScript="setTimeout(() => {document.addEventListener('scroll', function (event) {window.ReactNativeWebView.postMessage(JSON.stringify(document.getElementsByClassName('topconteiner')[0].scrollTop));},true);}, 300);true;"
/>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question