A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: fix pdf previews not working on ios
Ammar Ahmedf6c442ba886e
diff --git a/apps/mobile/app/components/dialogs/pdf-preview/index.jsx b/apps/mobile/app/components/dialogs/pdf-preview/index.jsxindex ffaf7090b..f8e404f4d 100644--- a/apps/mobile/app/components/dialogs/pdf-preview/index.jsx+++ b/apps/mobile/app/components/dialogs/pdf-preview/index.jsx@@ -23,6 +23,7 @@ import React, { useCallback, useEffect, useRef, useState } from "react";import { Dimensions, TextInput, View } from "react-native";import Orientation from "react-native-orientation-locker";import Pdf from "react-native-pdf";+import FileViewer from "react-native-file-viewer";import { MMKV } from "../../../common/database/mmkv";import downloadAttachment from "../../../common/filesystem/download-attachment";import { deleteCacheFileByPath, exists } from "../../../common/filesystem/io";@@ -43,6 +44,7 @@ import SheetProvider from "../../sheet-provider";import { IconButton } from "../../ui/icon-button";import { ProgressBarComponent } from "../../ui/svg/lazy";import Paragraph from "../../ui/typography/paragraph";+import ReactNativeBlobUtil from "react-native-blob-util";const WIN_WIDTH = Dimensions.get("window").width;const WIN_HEIGHT = Dimensions.get("window").height;@@ -117,8 +119,11 @@ const PDFPreview = () => {setVisible(false);return;}- const path = `${cacheDir}/${uri}`;+ let path = `${cacheDir}/${attachment.filename}`;snapshotValue.current = snapshot.current;+ await ReactNativeBlobUtil.fs+ .mv(`${cacheDir}/${uri}`, path)+ .catch(console.log);setPDFSource("file://" + path);setLoading(false);}, 100);@@ -127,7 +132,7 @@ const PDFPreview = () => {);const close = () => {- deleteCacheFileByPath(pdfSource);+ deleteCacheFileByPath(pdfSource.replace("file://", ""));setPDFSource(null);setVisible(false);setPassword("");@@ -157,7 +162,12 @@ const PDFPreview = () => {return (visible && (- <BaseDialog animation="fade" visible={true} onRequestClose={close}>+ <BaseDialog+ animation="fade"+ visible={true}+ onRequestClose={close}+ useSafeArea={false}+ ><SheetProvider context={attachment?.hash} /><Dialog context={attachment?.hash} />@@ -223,45 +233,48 @@ const PDFPreview = () => {<Viewstyle={{flexDirection: "row",- alignItems: "center",- marginRight: 12+ gap: DefaultAppStyles.GAP_SMALL}}>- <TextInput- ref={inputRef}- defaultValue={currentPage + ""}+ <Viewstyle={{- color: colors.primary.paragraph,- padding: 0,- paddingTop: 0,- paddingBottom: 0,- marginTop: 0,- marginBottom: 0,- paddingVertical: 0,- height: 25,- backgroundColor: colors.secondary.background,- width: 40,- textAlign: "center",- marginRight: 4,- borderRadius: 3,- fontFamily: "Inter-Regular"+ flexDirection: "row",+ alignItems: "center"}}- selectTextOnFocus- keyboardType="decimal-pad"- onSubmitEditing={(event) => {- setCurrentPage(event.nativeEvent.text);- pdfRef.current?.setPage(parseInt(event.nativeEvent.text));- }}- blurOnSubmit- />- <Paragraph color={colors.static.white}>/{numPages}</Paragraph>- </View>-- <View- style={{- flexDirection: "row"- }}- >+ >+ <TextInput+ ref={inputRef}+ defaultValue={currentPage + ""}+ style={{+ color: colors.primary.paragraph,+ padding: 0,+ paddingTop: 0,+ paddingBottom: 0,+ marginTop: 0,+ marginBottom: 0,+ paddingVertical: 0,+ height: 25,+ backgroundColor: colors.secondary.background,+ width: 40,+ textAlign: "center",+ marginRight: 4,+ borderRadius: 3,+ fontFamily: "Inter-Regular"+ }}+ selectTextOnFocus+ keyboardType="decimal-pad"+ onSubmitEditing={(event) => {+ setCurrentPage(event.nativeEvent.text);+ pdfRef.current?.setPage(+ parseInt(event.nativeEvent.text)+ );+ }}+ blurOnSubmit+ />+ <Paragraph color={colors.static.white}>+ /{numPages}+ </Paragraph>+ </View><IconButtoncolor={colors.static.white}name="download"@@ -269,6 +282,16 @@ const PDFPreview = () => {downloadAttachment(attachment.hash, false);}}/>+ <IconButton+ color={colors.static.white}+ name="open-in-new"+ onPress={() => {+ FileViewer.open(pdfSource, {+ showOpenWithDialog: true,+ showAppsSuggestions: true+ });+ }}+ /></View></View>{pdfSource ? (diff --git a/apps/mobile/ios/Podfile.lock b/apps/mobile/ios/Podfile.lockindex fef2a550a..307f65aba 100644--- a/apps/mobile/ios/Podfile.lock+++ b/apps/mobile/ios/Podfile.lock@@ -1887,7 +1887,7 @@ PODS:- ReactCommon/turbomodule/core- SocketRocket- Yoga- - react-native-document-picker (11.0.1):+ - react-native-document-picker (11.0.3):- boost- DoubleConversion- fast_float@@ -2033,7 +2033,7 @@ PODS:- SocketRocket- SwiftUIIntrospect (~> 1.0)- Yoga- - react-native-pdf (6.7.7):+ - react-native-pdf (7.0.3):- boost- DoubleConversion- fast_float@@ -3894,7 +3894,7 @@ SPEC CHECKSUMS:react-native-blob-util: 7946b7e13acf0da5e849dc2f73fcfebe1d981699react-native-config: 963b5efabc864cf69412e54b5de49b6a23e4af03react-native-date-picker: 4f4f40f6e65798038bb4b1bff47890c2be69c2e6- react-native-document-picker: 254467fec90f263dfc4828210daf3e8baa4fcb81+ react-native-document-picker: d624d3d9bd9311da87f6f7b64aa44f69927d8543react-native-fingerprint-scanner: d5e143a361f3f01858e9c45141ddcabc4fd57055react-native-get-random-values: d16467cf726c618e9c7a8c3c39c31faa2244bbbareact-native-gzip: 794e0e964a0d9e1dfd1773fee938adb4d4310e26@@ -3907,7 +3907,7 @@ SPEC CHECKSUMS:react-native-notification-sounds: ce106d58df0dd384bccbd2e84fb53accab7cc068react-native-orientation-locker: cc6f357b289a2e0dd2210fea0c52cb8e0727fdaareact-native-pager-view: d7d2aa47f54343bf55fdcee3973503dd27c2bd37- react-native-pdf: c586da0d19c14e6d859e62bf957851687fba0f25+ react-native-pdf: edc236298f13f1609e42d41e45b8b6ea88ed10f9react-native-quick-sqlite: 1ed8d3db1e22a8604d006be69f06053382e93bb0react-native-safe-area-context: c6e2edd1c1da07bdce287fa9d9e60c5f7b514616react-native-screenguard: 9fc3b4ad5b97783fc0832638fae0dce51272c661diff --git a/apps/mobile/package-lock.json b/apps/mobile/package-lock.jsonindex c7f5a4039..647be16a4 100644--- a/apps/mobile/package-lock.json+++ b/apps/mobile/package-lock.json@@ -42,7 +42,7 @@"@react-native-community/datetimepicker": "^8.4.5","@react-native-community/netinfo": "^11.4.1","@react-native-community/toolbar-android": "^0.2.1",- "@react-native-documents/picker": "^11.0.1",+ "@react-native-documents/picker": "^11.0.3","@react-native-masked-view/masked-view": "^0.3.2","@react-navigation/elements": "^1.3.3","@react-navigation/native": "^6.0.10",@@ -103,7 +103,7 @@"react-native-notification-sounds": "0.5.5","react-native-orientation-locker": "^1.7.0","react-native-pager-view": "^8.0.0",- "react-native-pdf": "6.7.7",+ "react-native-pdf": "^7.0.3","react-native-privacy-snapshot": "github:standardnotes/react-native-privacy-snapshot","react-native-progress": "5.0.0","react-native-qrcode-svg": "^6.0.6",@@ -4853,9 +4853,9 @@}},"node_modules/@react-native-documents/picker": {- "version": "11.0.1",- "resolved": "https://registry.npmjs.org/@react-native-documents/picker/-/picker-11.0.1.tgz",- "integrity": "sha512-aUq4MHGO/f8BslCFFx9OXz9NLLmcLkYAXp5PAEVau31v7obItPpb71Fe84bxpGV6gALIvGlGgSm6W9kEyU4toA==",+ "version": "11.0.3",+ "resolved": "https://registry.npmjs.org/@react-native-documents/picker/-/picker-11.0.3.tgz",+ "integrity": "sha512-q+vQNT1NtZcFGwsDpTwMKNNcgOEq6foFDGlPQVt8H7KaEjCjC+wTGdXuVSe8JJr2uO9xZR6kJ7aRHReZ4XDRBw==","license": "MIT","peerDependencies": {"react": "*",@@ -17753,9 +17753,9 @@}},"node_modules/react-native-pdf": {- "version": "6.7.7",- "resolved": "https://registry.npmjs.org/react-native-pdf/-/react-native-pdf-6.7.7.tgz",- "integrity": "sha512-D0ga/eyPsVWSPEBm622sGVZLl3gibxPmfm2cxsLcUrZ4WDSGR5HyGmvvWaR/m9wXEyIbD4J6q9qzuG6yObcSXw==",+ "version": "7.0.3",+ "resolved": "https://registry.npmjs.org/react-native-pdf/-/react-native-pdf-7.0.3.tgz",+ "integrity": "sha512-zDtF6CGXPAfGptQZqX7LQK3CVQrIGsD+rYuBnMK0sVmd8mrq7ciwmWXINT+d92emMtZ7+PLnx1IQZIdsh0fphA==","license": "MIT","dependencies": {"crypto-js": "4.2.0",diff --git a/apps/mobile/package.json b/apps/mobile/package.jsonindex 0d8673fc2..45d19fe93 100644--- a/apps/mobile/package.json+++ b/apps/mobile/package.json@@ -58,7 +58,7 @@"@react-native-community/datetimepicker": "^8.4.5","@react-native-community/netinfo": "^11.4.1","@react-native-community/toolbar-android": "^0.2.1",- "@react-native-documents/picker": "^11.0.1",+ "@react-native-documents/picker": "^11.0.3","@react-native-masked-view/masked-view": "^0.3.2","@react-navigation/elements": "^1.3.3","@react-navigation/native": "^6.0.10",@@ -119,7 +119,7 @@"react-native-notification-sounds": "0.5.5","react-native-orientation-locker": "^1.7.0","react-native-pager-view": "^8.0.0",- "react-native-pdf": "6.7.7",+ "react-native-pdf": "^7.0.3","react-native-privacy-snapshot": "github:standardnotes/react-native-privacy-snapshot","react-native-progress": "5.0.0","react-native-qrcode-svg": "^6.0.6",