2

We are planning to develop a custom react-native mobile app where we need to display lightning app pages in mobile webview through lightningout.js.

We created a react-native app using forcereact (Salesforce mobile sdk), and we can successfully login and get the OAuth token. Our requirement to show lightning component pages in in react-native webview through lightning out. To do that, we should pass the oAuth token to webview in securely. Is there any way to pass the token to react-native webview?

1 Answers1

0

Not very clear about your question.But if you are trying to interactive between the html page and the react-native.You can use postMessage and onMessage.

export default class Test extends React.Component{
    constructor(props){
        super(props);
    }

    handleMessage(msg){

    }

    postMessage(msg){
        this.webview.postMessage(msg)
    }

    render(){
        return (
            <Webview 
                source={{uri:"http://test.com"}}
                onMessage={this.handleMessage}
                ref={ref => { this.webview = ref }}
            />
        )
    }

}
Devin Gong
  • 124
  • 6
  • I am loading a index.html file from project directory. On loading, i should get the data from react-native.Can this.webview.postMessage(msg) pass the data to html page? – Senthilkumar.S May 23 '19 at 11:35
  • @Senthilkumar.S Yes.In your index.html file ,use `window.onload = function() { document.addEventListener('message', function(msg) { window.alert(msg.data); });` – Devin Gong May 27 '19 at 07:33