Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: OnNavigationStateChanged not always called #551

Closed
wants to merge 2 commits into from
Closed

Fix: OnNavigationStateChanged not always called #551

wants to merge 2 commits into from

Conversation

manuelblum
Copy link
Contributor

The OnNavigationStateChanged Prop of react-native-community-webview is not called when the history state is manipulated via javascript (e.g.: window.history.pushState({test: "test"}, "Test Title", "index.html")).

With this pull request each history change will be noticed by the native webviews (android and ios) and the navigation change will be forwarded to onNavigationStateChanged with navigationType: "other".

added onCanGoBackChanged and onCanGoForwardChanged prop to webview (ios+android)
@jamonholmgren
Copy link
Member

jamonholmgren commented May 21, 2019

So I've tried to get this to work, but it doesn't appear to.

import React, { Component } from "react";
import { WebView } from "react-native-webview";

export default class App extends Component<Props> {
  render() {
    const html = `
      <html>
      <head>
        <script>
          function changeurl() {
            document.body.innerHTML += '<p>clicked</p>';
            history.pushState({test: "test"}, "Test Title", "#hello");
            document.body.innerHTML += '<p>done clicking</p>';
          }
        </script>
        <style>body, button { font-size: 30px; padding: 30px; }</style>
      </head>
      <body>
        <h1>Testing</h1>
        <h1>Testing</h1>
        <h1>Testing</h1>
        <p>
          <button onclick="javascript:changeurl()">Hello</button>
        </p>
      </body>
      </html>
    `;
    return (
      <WebView
        source={{ html }}
        onNavigationStateChange={nav => alert(JSON.stringify(nav))}
      />
    );
  }
}

When I click the button, I see the appendChild fire, but the pushHistory doesn't fire onNavigationStateChange at all.

@jamonholmgren
Copy link
Member

Interesting -- it does work on Android.

@github-actions
Copy link

github-actions bot commented Sep 2, 2019

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants