victorsoares96 / epubjs-react-native

ePub.js Reader for React Native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Internal Linking for iOs (again!)

natesanyo opened this issue Β· comments

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch @epubjs-react-native/core@1.1.0 for the project I'm working on.

Because the ePub spec does not require hyperlinks to follow a particular structure, sometimes internal hyperlinks have relative fragments such as "../", sometimes they have parent directories specified "../Text", and sometimes they simply directly reference the target file within the ePub. These variations break the internal navigation hack for iOs we implemented in View.tsx.

If someone finds a better solution, please ignore mine, I know my hack here causes two useless "goToLocation" calls for every internal link press. But at least the user gets to the location they wanted!

Here is the diff that solved my problem:

diff --git a/node_modules/@epubjs-react-native/core/src/View.tsx b/node_modules/@epubjs-react-native/core/src/View.tsx
index eff704b..401c568 100644
--- a/node_modules/@epubjs-react-native/core/src/View.tsx
+++ b/node_modules/@epubjs-react-native/core/src/View.tsx
@@ -270,10 +270,20 @@ export function View({
                     request.mainDocumentURL &&
                     request.url !== request.mainDocumentURL
                   ) {
+                    const urlXMain = request.url.replace(request.mainDocumentURL, "");
+                    const urlXParent = urlXMain.replace("OEBPS/", "");
+                    const urlXText = urlXParent.replace("Text/", "");
                     goToLocation(
-                      request.url.replace(request.mainDocumentURL, '')
+                     urlXText
                     );
+                    goToLocation(
+                      urlXMain
+                     );
+                     goToLocation(
+                      urlXParent
+                     );
                   }
+                  console.log(request)
                   return true;
                 }}
                 style={{

This issue body was partially generated by patch-package.

hi @natesanyo, thanks for your job! you can provided a pr with your fix?

This issue is stale because it has been open for 90 days with no activity.