Shashika Virajh
Shashika Virajh

Reputation: 9467

RN navigating from webview to a screen

I have the following RN code in my project. I want to navigate to a screen from where I have commented. Im inside a webview and if a condition is true, I want to navigate to a specific screen. Is there any way I can achieve this?

class CitizenLoginWebView extends Component {  
  render() {
    return (
      <WebView 
        source={{uri: citizenLoginUrl}} 
        onNavigationStateChange={navState => {
          if (navState.title === "Consent Platform") {
            if (hasWordsInString(navState.url, searchWords)) {
              // WANT TO NAVIGATE TO A SCREEN FROM HERE
              console.log('Words found');
            } 
          }     
        }}
      />
    );
  }  
}

Upvotes: 0

Views: 662

Answers (1)

Kesav Sundar M
Kesav Sundar M

Reputation: 137

class CitizenLoginWebView extends Component {
  render() {
    return (
        <WebView
            ref={'webview'}
            source={{uri: citizenLoginUrl}}
            onNavigationStateChange={navState => {
                if (navState.title === "Consent Platform") {
                    if (hasWordsInString(navState.url, searchWords)) {
                        this.refs.webview.stopLoading();
                        this.props.navigation.navigate(screen);
                        console.log('Words found');
                    }
                }
            }}
        />
    );
  }
}

This would work if you use React-Navigation

Upvotes: 1

Related Questions