Skip to content

Instantly share code, notes, and snippets.

@carbonphyber
Last active October 13, 2015 20:08
Show Gist options
  • Save carbonphyber/edb83eecec4a38efa1ca to your computer and use it in GitHub Desktop.
Save carbonphyber/edb83eecec4a38efa1ca to your computer and use it in GitHub Desktop.
Modified Sample1 of React-Native-Webview-Bridge to reproduce exception thrown when unloaded via a React Native Navigator
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var WebViewBridgeNative = require('react-native-webview-bridge');
var {
AppRegistry,
Component,
Navigator,
Text,
TouchableHighlight,
View,
WebView,
} = React;
class Sample1Wat extends Component {
constructor(props) {
super(props);
}
render() {
return (
<View style={{flex: 1}}>
</View>
);
}
}
class Sample1WebView extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
var myWebViewBridgeRef = this.refs.myWebViewBridge;
var onMessage = function(message) {
console.log("Received message", message);
};
myWebViewBridgeRef.onMessage(onMessage);
myWebViewBridgeRef.injectBridgeScript();
// //this opens up the printer window dialoge
// setTimeout(() => {
// myWebViewBridgeRef.print();
// }, 5000);
}
render() {
var url = 'http://netflix.com';
return (
<View style={{flex: 1, margin: 0, padding: 0, backgroundColor: '#fff', borderColor: '#f00', borderWidth: 4}}>
<WebViewBridgeNative
ref="myWebViewBridge"
url={url}
automaticallyAdjustContentInsets={false}
style={{flex: 1, margin: 0, padding: 0, backgroundColor: '#fff'}}
/>
</View>
);
// onNavigationStateChange={this.props.onNavigationStateChange}
}
}
class Sample1 extends Component {
constructor(props) {
super(props);
this.once = true;
}
// onNavigationStateChange={this.onNavigationStateChange.bind(this)}
onNavigationStateChange(navState) {
var myWebViewBridgeRef = this.refs.myWebViewBridge;
if (this.once) {
this.once = false;
}
console.log(navState.url);
}
render() {
return (
<View style={{flex: 1}}>
<View style={{
height: 40,
backgroundColor: '#ff0',
borderColor: '#0f0',
borderWidth: 4,
flexDirection: 'row',
}}>
<TouchableHighlight onPress={() => {
this.refs.navigator.pop()
}} style={{flex: 1, padding: 10}}>
<Text>back</Text>
</TouchableHighlight>
<TouchableHighlight onPress={() => {
this.refs.navigator.push({component: Sample1WebView})
}} style={{flex: 1, padding: 10}}>
<Text>web</Text>
</TouchableHighlight>
</View>
<Navigator
ref="navigator"
initialRoute={{
component: Sample1Wat,
title: 'wat',
passProps: {},
}}
configureScene={() => {
return Navigator.SceneConfigs.FloatFromRight;
}}
renderScene={(route, navigator) => {
// count the number of func calls
console.log(route, navigator);
if (route.component) {
return React.createElement(route.component, {navigator});
}
}}
/>
</View>
);
}
}
AppRegistry.registerComponent('Sample1', () => Sample1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment