Home > Software design >  How can get the game score in react-native-webview
How can get the game score in react-native-webview

Time:04-01

How can get the score points after the play game.

I have used the OnMessage and InjectJavascript method but not working.

CodePudding user response:

it would help if you can add some code to your question and also explain it in more detail. I had a similar question a while back - maybe this helps: Get value from input field in webview to react native

CodePudding user response:

For Data Fetching From Webview Into React Native App. You need to Add Code Into HTML.

<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>

<body style="display: flex;
    justify-content: center;
    flex-direction: column;
    align-items: center;">
<button onclick="sendDataToReactNativeApp()" style="padding: 20;
    width: 200;
    font-size: 20;
    color: white;
    background-color: #6751ff;">
    Send Data To React Native App
</button>
<script>
    const sendDataToReactNativeApp = async () => {
        window.ReactNativeWebView.postMessage('DATA SEND TO RN APP');
    };
</script>

React Native Side.

You get data into webview onMessage Function Like Below

<WebView
 source={your webview URL or Html}
 onMessage={(data) => console.log(data.nativeEvent.data)}
/>
  • Related