Skip to content

Communicating between JS and Native not working on iOS  #3624

@javbk201

Description

@javbk201

Bug description:

To Reproduce:

  1. Create a new app with expo or cli.
  2. Install react-native-webview
  3. install pods
  4. copy and paste the code below in App.tsx
import { StyleSheet, View } from 'react-native'
import React from 'react'
import WebView from 'react-native-webview'

const App = () => {
  const html = `
      <html>
      <head></head>
      <body>
        <script>
          setTimeout(function () {
            window.ReactNativeWebView.postMessage("Hello!")
          }, 2000)
        </script>
      </body>
      </html>
    `;
  return (
    <View style={styles.container}>
      <WebView
        source={{html}}
        onMessage={event => {
          alert(event.nativeEvent.data);
        }}
      />
    </View>
  );
};

export default App

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
})

Expected behavior:
This code should to show an Alert after 2 seconds. But in iOS does not show it.

Environment:

  • OS: Mac OS Sequoia
  • OS version: 15.1
  • react-native version: 0.76.2
  • react-native-webview version: 13.12.4
  • iOS Version: 18.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions