1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +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

@ -141,6 +141,7 @@ android {
}
dependencies {
implementation project(':react-native-webview')
compile project(':react-native-push-notification')
implementation (project(':react-native-camera')) {
// This is required because com.google.firebase requires v16.0.x of com.google.android.gms

View File

@ -3,6 +3,7 @@ package net.cozic.joplin;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.reactnativecommunity.webview.RNCWebViewPackage;
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
import org.reactnative.camera.RNCameraPackage;
import com.vinzscam.reactnativefileviewer.RNFileViewerPackage;
@ -39,6 +40,7 @@ public class MainApplication extends Application implements ReactApplication {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNCWebViewPackage(),
new ReactNativePushNotificationPackage(),
new ImageResizerPackage(),
new RNCameraPackage(),

View File

@ -1,4 +1,6 @@
rootProject.name = 'Joplin'
include ':react-native-webview'
project(':react-native-webview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview/android')
include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
include ':react-native-file-viewer'

View File

@ -48,6 +48,7 @@
EC11356C90E9419799A2626F /* EvilIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 51BCEC3BC28046C8BB19531F /* EvilIcons.ttf */; };
F3D0BB525E6C490294D73075 /* libRNSecureRandom.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 22647ACF9A4C45918C44C599 /* libRNSecureRandom.a */; };
FBF57CE2F0F448FA9A8985E2 /* libsqlite3.0.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 0EB8BCAEA9AA41CAAE460443 /* libsqlite3.0.tbd */; };
45E8D3F9FBA0410E82E28A0D /* libRNCWebView.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C7A5EE79128470A920D4971 /* libRNCWebView.a */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -468,6 +469,8 @@
FC908F114F494130A324B402 /* RNCamera.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNCamera.xcodeproj; path = "../node_modules/react-native-camera/ios/RNCamera.xcodeproj"; sourceTree = "<group>"; };
FD370E24D76E461D960DD85D /* Feather.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = Feather.ttf; path = "../node_modules/react-native-vector-icons/Fonts/Feather.ttf"; sourceTree = "<group>"; };
FF411B45E68B4A8CBCC35777 /* Ionicons.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = Ionicons.ttf; path = "../node_modules/react-native-vector-icons/Fonts/Ionicons.ttf"; sourceTree = "<group>"; };
DECA9B559982480BBD8F9E84 /* RNCWebView.xcodeproj */ = {isa = PBXFileReference; name = "RNCWebView.xcodeproj"; path = "../node_modules/react-native-webview/ios/RNCWebView.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
4C7A5EE79128470A920D4971 /* libRNCWebView.a */ = {isa = PBXFileReference; name = "libRNCWebView.a"; path = "libRNCWebView.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -503,6 +506,7 @@
F3D0BB525E6C490294D73075 /* libRNSecureRandom.a in Frameworks */,
82C61D3DAE0A4666883001E9 /* libRNFileViewer.a in Frameworks */,
12AE298E1C0E445682922DAB /* libRNCamera.a in Frameworks */,
45E8D3F9FBA0410E82E28A0D /* libRNCWebView.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -797,6 +801,7 @@
252BD7B86BF7435B960DA901 /* RNSecureRandom.xcodeproj */,
59F5448FAF7345F8B568BD00 /* RNFileViewer.xcodeproj */,
FC908F114F494130A324B402 /* RNCamera.xcodeproj */,
DECA9B559982480BBD8F9E84 /* RNCWebView.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
@ -1450,6 +1455,7 @@
"$(SRCROOT)..\node_modules\neact-native-securerandomios",
"$(SRCROOT)..\node_modules\neact-native-file-viewerios",
"$(SRCROOT)/../node_modules/react-native-camera/ios/**",
"$(SRCROOT)/../node_modules/react-native-webview/ios",
);
INFOPLIST_FILE = Joplin/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@ -1458,6 +1464,7 @@
"\"$(SRCROOT)/Joplin\"",
"\"$(SRCROOT)/Joplin\"",
"\"$(SRCROOT)/Joplin\"",
"\"$(SRCROOT)/Joplin\"",
);
OTHER_LDFLAGS = (
"$(inherited)",
@ -1494,6 +1501,7 @@
"$(SRCROOT)..\node_modules\neact-native-securerandomios",
"$(SRCROOT)..\node_modules\neact-native-file-viewerios",
"$(SRCROOT)/../node_modules/react-native-camera/ios/**",
"$(SRCROOT)/../node_modules/react-native-webview/ios",
);
INFOPLIST_FILE = Joplin/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@ -1502,6 +1510,7 @@
"\"$(SRCROOT)/Joplin\"",
"\"$(SRCROOT)/Joplin\"",
"\"$(SRCROOT)/Joplin\"",
"\"$(SRCROOT)/Joplin\"",
);
OTHER_LDFLAGS = (
"$(inherited)",

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');

View File

@ -155,7 +155,7 @@ class Synchronizer {
// Stop queue but don't set it to null as it may be used to
// retrieve the last few downloads.
this.downloadQueue_.stop();
if (this.downloadQueue_) this.downloadQueue_.stop();
this.logSyncOperation('cancelling', null, null, '');
this.cancelling_ = true;

View File

@ -5854,6 +5854,25 @@
"resolved": "https://registry.npmjs.org/react-native-version-info/-/react-native-version-info-0.5.1.tgz",
"integrity": "sha512-DFnjbp+EsN/fADwNo4uFryM1KsRmRQOLns2njArAfFOM9faW77BX0wtRgBrtlpm3DKU97W9eI89WP8FGPBgKtA=="
},
"react-native-webview": {
"version": "5.12.0",
"resolved": "https://registry.npmjs.org/react-native-webview/-/react-native-webview-5.12.0.tgz",
"integrity": "sha512-tdKBRgxq/DP6kg/B3tYoqmWiARY2BKTqbjFHJ8vH7TcThaPprlyWJyHuO54FfrS9dnPpU2H4C5i3btJvvy2OVQ==",
"requires": {
"escape-string-regexp": "1.0.5",
"invariant": "2.2.4"
},
"dependencies": {
"invariant": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz",
"integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==",
"requires": {
"loose-envify": "^1.0.0"
}
}
}
},
"react-navigation": {
"version": "1.0.0-beta.21",
"resolved": "https://registry.npmjs.org/react-navigation/-/react-navigation-1.0.0-beta.21.tgz",

View File

@ -59,6 +59,7 @@
"react-native-sqlite-storage": "3.3.*",
"react-native-vector-icons": "^4.4.2",
"react-native-version-info": "^0.5.1",
"react-native-webview": "^5.12.0",
"react-navigation": "^1.0.0-beta.21",
"react-redux": "5.0.7",
"redux": "4.0.0",

1
ReactNativeClient/run_ios.sh Executable file
View File

@ -0,0 +1 @@
react-native run-ios --simulator 'iPhone 6'