1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Mobile: Upgraded WebView

This commit is contained in:
Laurent Cozic
2019-06-14 08:11:15 +01:00
parent 861cf8a1b2
commit 122bc29035
11 changed files with 51 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
const React = require('react'); const Component = React.Component;
const { Platform, WebView, View } = require('react-native');
const { Platform, View } = require('react-native');
const { WebView } = require('react-native-webview');
const { themeStyle } = require('lib/components/global-style.js');
const Resource = require('lib/models/Resource.js');
const Setting = require('lib/models/Setting.js');
@@ -99,6 +100,7 @@ class NoteBodyViewer extends Component {
highlightedKeywords: this.props.highlightedKeywords,
resources: this.props.noteResources,//await shared.attachedResources(bodyToRender),
codeTheme: theme.codeThemeCss,
postMessageSyntax: 'window.ReactNativeWebView.postMessage',
};
let result = this.mdToHtml_.render(bodyToRender, this.props.webViewStyle, mdOptions);
@@ -108,7 +110,7 @@ class NoteBodyViewer extends Component {
const injectedJs = [this.mdToHtml_.injectedJavaScript()];
injectedJs.push(shim.injectedJs('webviewLib'));
injectedJs.push('webviewLib.initialize({ postMessage: msg => { return postMessage(msg); } });');
injectedJs.push('webviewLib.initialize({ postMessage: msg => { return window.ReactNativeWebView.postMessage(msg); } });');
injectedJs.push(`
const readyStateCheckInterval = setInterval(function() {
if (document.readyState === "complete") {
@@ -162,9 +164,13 @@ class NoteBodyViewer extends Component {
baseUrl: 'file://' + Setting.value('resourceDir') + '/',
};
// Note: useWebKit={false} is needed to go around this bug:
// https://github.com/react-native-community/react-native-webview/issues/376
return (
<View style={style}>
<WebView
useWebKit={false}
scalesPageToFit={Platform.OS !== 'ios'}
style={webViewStyle}
source={source}

View File

@@ -157,7 +157,11 @@ class NoteScreenComponent extends BaseScreenComponent {
throw new Error(_('The Joplin mobile app does not currently support this type of link: %s', BaseModel.modelTypeToName(item.type_)));
}
} else {
Linking.openURL(msg);
if (msg.indexOf('file://') === 0) {
throw new Error(_('Links with protocol "%s" are not supported', 'file://'));
} else {
Linking.openURL(msg);
}
}
} catch (error) {
dialogs.error(this, error.message);

View File

@@ -1,6 +1,7 @@
const React = require('react'); const Component = React.Component;
const { View } = require('react-native');
const { WebView, Button, Text } = require('react-native');
const { Button, Text } = require('react-native');
const { WebView } = require('react-native-webview');
const { connect } = require('react-redux');
const Setting = require('lib/models/Setting.js');
const { ScreenHeader } = require('lib/components/screen-header.js');