open links displayed in the embedded webview on the device browser
This commit is contained in:
parent
624d95ab42
commit
24fa80d92a
1 changed files with 13 additions and 1 deletions
|
@ -64,6 +64,10 @@ class FilePage extends React.PureComponent {
|
||||||
|
|
||||||
converter = null;
|
converter = null;
|
||||||
|
|
||||||
|
linkHandlerScript = `(function () {
|
||||||
|
window.onclick = function(evt) { evt.preventDefault(); window.ReactNativeWebView.postMessage(evt.target.href); evt.stopPropagation(); }
|
||||||
|
}());`;
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -109,7 +113,6 @@ class FilePage extends React.PureComponent {
|
||||||
|
|
||||||
onComponentFocused = () => {
|
onComponentFocused = () => {
|
||||||
StatusBar.setHidden(false);
|
StatusBar.setHidden(false);
|
||||||
console.log('fileComponent Focused...');
|
|
||||||
NativeModules.Firebase.setCurrentScreen('File').then(result => {
|
NativeModules.Firebase.setCurrentScreen('File').then(result => {
|
||||||
DeviceEventEmitter.addListener('onStoragePermissionGranted', this.handleStoragePermissionGranted);
|
DeviceEventEmitter.addListener('onStoragePermissionGranted', this.handleStoragePermissionGranted);
|
||||||
DeviceEventEmitter.addListener('onStoragePermissionRefused', this.handleStoragePermissionRefused);
|
DeviceEventEmitter.addListener('onStoragePermissionRefused', this.handleStoragePermissionRefused);
|
||||||
|
@ -800,6 +803,13 @@ class FilePage extends React.PureComponent {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleWebViewMessage = evt => {
|
||||||
|
const href = evt.nativeEvent.data;
|
||||||
|
if (href && href.startsWith('http')) {
|
||||||
|
Linking.openURL(href);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
buildWebViewSource = () => {
|
buildWebViewSource = () => {
|
||||||
const { contentType, fileInfo } = this.props;
|
const { contentType, fileInfo } = this.props;
|
||||||
const localFileUri = this.localUriForFileInfo(fileInfo);
|
const localFileUri = this.localUriForFileInfo(fileInfo);
|
||||||
|
@ -996,6 +1006,8 @@ class FilePage extends React.PureComponent {
|
||||||
source={this.buildWebViewSource()}
|
source={this.buildWebViewSource()}
|
||||||
style={filePageStyle.viewer}
|
style={filePageStyle.viewer}
|
||||||
onLoad={this.handleWebViewLoad}
|
onLoad={this.handleWebViewLoad}
|
||||||
|
injectedJavaScript={this.linkHandlerScript}
|
||||||
|
onMessage={this.handleWebViewMessage}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{this.state.showImageViewer && (
|
{this.state.showImageViewer && (
|
||||||
|
|
Loading…
Reference in a new issue