Skip to content

Instantly share code, notes, and snippets.

@zaguiini
Last active January 5, 2018 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaguiini/bafc7dfe6eaa1ae83591394c544de774 to your computer and use it in GitHub Desktop.
Save zaguiini/bafc7dfe6eaa1ae83591394c544de774 to your computer and use it in GitHub Desktop.
...
handleNavigationStateChange({ url }) {
...
if(Platform.OS === 'ios') {
this.refs[webviewRef].evaluateJavaScript('var isNative = "ios"')
} else {
this.refs[webviewRef].injectJavaScript('var isNative = "android"')
}
...
}
postMessage(message) {
message = JSON.stringify(message)
console.log('posting message', message)
const finalMessage = 'window.onMessage(' + message + ')'
if(Platform.OS === 'ios') {
this.refs[webviewRef].evaluateJavaScript(finalMessage)
} else {
this.refs[webviewRef].injectJavaScript(finalMessage)
}
console.log('message posted')
}
facebookLoginMethod() {
LoginManager
.logInWithReadPermissions(['public_profile'])
.then(response => {
// send the response back to the webview
this.postMessage(JSON.stringify({ ...response, type: 'facebookLogin' }))
})
.catch(console.error)
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment