21
rated 0 times
[
27]
[
6]
/ answers: 1 / hits: 7625
/ 3 Years ago, fri, may 7, 2021, 12:00:00
I'm trying to inject JS code to alert the user before the content of the React Native Webview loads, however, for me it just goes to the activity indicator and loads the Webview without injecting any Javascript. How do I fix this? Code below:
import React from 'react';
import { View, ActivityIndicator } from 'react-native';
import { WebView } from 'react-native-webview';
import styles from '../../styles';
export default function Links() {
function LoadingIndicatorView() {
return (
<View style={styles.hubLoading}>
<ActivityIndicator color='#009b88' size='large' />
</View>
)
}
const runFirst = `
setTimeout(function() { window.alert('hi') }, 2000);
true; // note: this is required, or you'll sometimes get silent failures
`
return <WebView source={{ uri: https://www.google.com/ }} renderLoading={LoadingIndicatorView} startInLoadingState={true} javaScriptEnabled={true} injectedJavaScript={runFirst} />;
}
Btw, I am running the app on my iOS device if that helps you to answer.
More From » react-native