5-stones / react-native-readium

📚 📖 React Native ebook reader for iOS, Android, & Web via Readium
MIT License
92 stars 26 forks source link

toc hrefs with '#' cannot be navigated #11

Closed durpy2 closed 1 year ago

durpy2 commented 2 years ago

Thanks for creating this library.

When an epub is loaded with toc, if the href contains '#', navigation doesn't work properly.

Attached a sample epub with toc href values like
<a href="7604861093435514544_67098-h-0.htm.xhtml#pgepubid00012" id="np-13">IN WHICH EEYORE LOSES A TAIL AND POOH FINDS ONE</a>

pg67098-images-3.epub.zip

Currently setting Link object location as

{ href: "7604861093435514544_67098-h-0.htm.xhtml#pgepubid00012", type: 'application/xhtml+xml',}

jspizziri commented 2 years ago

@durpy2 is this on iOS, Android, or both? additionally, what version are you using?

durpy2 commented 2 years ago

@jspizziri I've only tested for iOS 16 where this is happening, the environment looks like below.

{
    "react-native": "0.69.6",
    "react": "18.0.0",
    "react-dom": "18.0.0",
    "react-native-readium": "^1.0.0",
}

with podfile specs

  pod 'GCDWebServer', podspec: 'https://raw.githubusercontent.com/readium/GCDWebServer/3ec154d358f26858071feaa6429e0f1c16bb11bd/GCDWebServer.podspec', modular_headers: true
  pod 'R2Shared', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.4.0/Support/CocoaPods/ReadiumShared.podspec'
  pod 'R2Streamer', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.4.0/Support/CocoaPods/ReadiumStreamer.podspec'
  pod 'R2Navigator', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.4.0/Support/CocoaPods/ReadiumNavigator.podspec'
  pod 'Minizip', modular_headers: true
jspizziri commented 2 years ago

@durpy2 thanks for the additional information. It'll probably be a bit before I can look into this myself. Please feel free to do some digging via the example project. I can give guidance as needed.

jspizziri commented 1 year ago

@durpy2 I was just able to confirm this behavior. I'm going to take a look at getting it resolved.

jspizziri commented 1 year ago

@durpy2 alright, so the problem here is that you need to specifically pass the # as a fragment. Here's a rough example:

       <TableOfContents
            items={toc}
            onPress={(link) => {
              console.log('onPress', link);
              const parts = link.href.split('#');
              const l: any = {
                href: parts[0],
                type: 'application/xhtml+xml',
              };

              if (parts[1]) {
                l['locations'] = {
                  fragments: [parts[1]],
                };
              }

              setLocation(l);
            }}
          />

I would've assumed that the core swift-tooklit readium would've handled this automatically, as it is handling it on the Android side, but it's not on the Swift side.

I have filed an issue upstream and we'll see what they say. If they don't want to support it then we can add it to our swift code for consistency. In the meantime please try a workaround like the above.

durpy2 commented 1 year ago

@jspizziri Great. Thank you for the workaround info.

jspizziri commented 1 year ago

@durpy2 this should now be properly fixed in v1.0.3. You can now pass either a Link or Locator to the location prop (and to File.initialLocation) and it will properly navigate.

Please let me know if you have any more issues.