Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toc hrefs with '#' cannot be navigated #11

Closed
durpy2 opened this issue Oct 27, 2022 · 7 comments
Closed

toc hrefs with '#' cannot be navigated #11

durpy2 opened this issue Oct 27, 2022 · 7 comments
Labels

Comments

@durpy2
Copy link

durpy2 commented Oct 27, 2022

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 jspizziri added the bug Something isn't working label Oct 31, 2022
@jspizziri
Copy link
Contributor

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

@durpy2
Copy link
Author

durpy2 commented Oct 31, 2022

@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
Copy link
Contributor

@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
Copy link
Contributor

jspizziri commented Dec 1, 2022

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

@jspizziri
Copy link
Contributor

jspizziri commented Dec 1, 2022

@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
Copy link
Author

durpy2 commented Dec 1, 2022

@jspizziri Great. Thank you for the workaround info.

jspizziri added a commit that referenced this issue Dec 5, 2022
…turn Locator[] for consistency

Links and Locators are not the same and need to be handled differently. To avoid complexity, the
library has been update to only deal with Locators and map all Links it returns to Locators.

BREAKING CHANGE: onTableOfContents now returns a `Locator[]` instead of a `Link[]`. Update your
`onTableOfContents` callbacks from `(toc: Link[]) => {...}` to `(toc: Locator[]) => {...}`.

#11
jspizziri added a commit that referenced this issue Dec 5, 2022
…nk or Locator objects

Links and Locators are not the same and need to be handled differently. Regardless of which object
is passed to `location`, convert it to the proper Locator and navigate to it.

#11
@jspizziri
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants