victorsoares96 / epubjs-react-native

ePub.js Reader for React Native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to handle external links in epub book

SergeyBazhanov opened this issue · comments

Hello. Thank you for this awesome package. Could you please hint me if it's possible to handle external links in a book? They seems to do not work by default

Thanks in advance

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

Hi @SergeyBazhanov!

An example of how to use this has been added in the examples folder.
Please update the lib to v1.4.0 or higher to use this.

import * as React from 'react';
import { Linking, SafeAreaView, useWindowDimensions } from 'react-native';
import { Reader, ReaderProvider } from '@epubjs-react-native/core';
import { useFileSystem } from '@epubjs-react-native/file-system';

export function OpenExternalLink() {
  const { width, height } = useWindowDimensions();

  return (
    <SafeAreaView>
      <ReaderProvider>
        <Reader
          src="https://github.com/IDPF/epub3-samples/releases/download/20230704/accessible_epub_3.epub"
          width={width}
          height={height}
          fileSystem={useFileSystem}
          initialLocation="pr01s04.xhtml"
          onPressExternalLink={(url) => {
            Linking.openURL(url);
          }}
        />
      </ReaderProvider>
    </SafeAreaView>
  );
}