Coder Social home page Coder Social logo

5-stones / react-native-readium Goto Github PK

View Code? Open in Web Editor NEW
70.0 6.0 23.0 7.05 MB

πŸ“š πŸ“– React Native ebook reader for iOS, Android, & Web via Readium

License: MIT License

Shell 0.10% Kotlin 45.19% JavaScript 2.14% Java 5.32% TypeScript 18.15% Swift 24.73% Ruby 2.53% C 0.07% Objective-C 0.76% HTML 0.24% Objective-C++ 0.76%
react-native readium readium-2 ebook ebooks ebook-reader epub epub3 epub-reader

react-native-readium's Introduction

react-native-readium

NPM version Commitizen friendly PRs welcome! This project is released under the MIT license


Have A Bug/Feature You Care About?

We ❀️ open source. We work on the things that are important to us when we're able to work on them. Have an issue you care about?

Issue Hunt


Overview

A react-native wrapper for https://readium.org/. At a high level this package allows you to do things like:

  • Render an ebook view.
  • Register for location changes (as the user pages through the book).
  • Register for the Table of Contents (so that you can display things like chapters in your app)
  • Control settings of the Reader. Things like:
    • Dark Mode, Light Mode, Sepia Mode
    • Font Size
    • Page Margins
    • More (see the Settings documentation in the API section)
  • Etc. (read on for more details. πŸ“–)

Table of Contents

Dark Mode Light Mode
Dark Mode Light Mode

Installation

Prerequisites

  1. iOS: Requires an iOS target >= 13.0 (see the iOS section for more details).
  2. Android: Requires compileSdkVersion >= 31 (see the Android section for more details).

Install Module

NPM

npm install react-native-readium

Yarn

yarn add react-native-readium

iOS

Due to the current state of the Readium swift libraries you need to manually update your Podfile (see more on that here).

# ./ios/Podfile
...
platform :ios, '13.0'

...

target 'ExampleApp' do
  config = use_native_modules!
  ...
  pod 'GCDWebServer', podspec: 'https://raw.githubusercontent.com/readium/GCDWebServer/3.7.5/GCDWebServer.podspec', modular_headers: true
  pod 'R2Shared', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.6.0/Support/CocoaPods/ReadiumShared.podspec'
  pod 'R2Streamer', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.6.0/Support/CocoaPods/ReadiumStreamer.podspec'
  pod 'R2Navigator', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.6.0/Support/CocoaPods/ReadiumNavigator.podspec'
  pod 'ReadiumInternal', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.6.0/Support/CocoaPods/ReadiumInternal.podspec'
  pod 'Minizip', modular_headers: true
  ...
end

Finally, install the pods:

pod install

Android

You might need to add jcenter if you're getting a build failure on android:

// android/build.gradle
...

allprojects {
    repositories {
        ...
        // required by react-native-readium https://github.com/readium/kotlin-toolkit/issues/31
        jcenter()
    }
    ...
}
...

If you're not using compileSdkVersion >= 31 you'll need to update that:

// android/build.gradle
...
buildscript {
    ...
    ext {
        ...
        compileSdkVersion = 31
...

Usage

import React, { useState } from 'react';
import { ReadiumView } from 'react-native-readium';
import type { File } from 'react-native-readium';

const MyComponent: React.FC = () => {
  const [file] = useState<File>({
    url: SOME_LOCAL_FILE_URL,
  });

  return (
    <ReadiumView
      file={file}
    />
  );
}

Take a look at the Example App for a more complex usage example.

Supported Formats & DRM

Format Support

Format Support Notes
Epub 2 βœ…
Epub 3 βœ…
PDF ❌ On the roadmap, feel free to submit a PR or ask for direction.
CBZ ❌ On the roadmap, feel free to submit a PR or ask for direction.

Missing a format you need? Reach out and see if it can be added to the roadmap.

DRM Support

DRM is not supported at this time. However, there is a clear path to support it via LCP and the intention is to eventually implement it.

API

View Props

Name Type Optional Description
file File ❌ A file object containing the path to the eBook file on disk.
location Locator | Link βœ… A locator prop that allows you to externally control the location of the reader (e.g. Chapters or Bookmarks).

⚠️ If you want to set the location of an ebook on initial load, you should use the File.initialLocation property (look at the file prop). See more here
settings Partial<Settings> βœ… An object that allows you to control various aspects of the reader's UI (epub only)
style ViewStyle βœ… A traditional style object.
onLocationChange (locator: Locator) => void βœ… A callback that fires whenever the location is changed (e.g. the user transitions to a new page)
onTableOfContents (toc: Link[] | null) => void βœ… A callback that fires once the file is parsed and emits the table of contents embedded in the file. Returns null or an empty [] if no TOC exists. See the Link interface for more info.

⚠️ Web vs Native File URLs

Please note that on web the File.url should be a web accessible URL path to the manifest.json of the unpacked epub. In native contexts it needs to be a local filepath to the epub file itself on disk. If you're not sure how to serve epub books take a look at this example which is based on the dita-streamer-js project (which is built on all the readium r2-*-js libraries)

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Release

The standard release command for this project is:

yarn version

This command will:

  1. Generate/update the Changelog
  2. Bump the package version
  3. Tag & pushing the commit

e.g.

yarn version --new-version 1.2.17
yarn version --patch // 1.2.17 -> 1.2.18

License

MIT

react-native-readium's People

Contributors

adesege avatar jspizziri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-native-readium's Issues

Help Needed In Using File

I need help on giving file path to ReadiumView
@jspizziri @mrogers-5s @Ken-Michalak

import { observer } from "mobx-react-lite"
import React, { FC, useEffect, useMemo } from "react"
import {
  ActivityIndicator,
  StyleSheet,
  View,
  SafeAreaView,
  useWindowDimensions
} from "react-native"
import { Reader, ReaderProvider, useReader, ePubCfi } from '@epubjs-react-native/core'
import { useFileSystem } from '@epubjs-react-native/file-system'
import { AppStackScreenProps } from "../../navigators"
import WebView from "react-native-webview"
import AppHeader from "../../components/AppHeader"
import { spacing } from "../../theme"
import { ReadiumView } from 'react-native-readium';
import type { File } from 'react-native-readium';


export const ReadFile: FC<AppStackScreenProps<"ReadFile">> = observer(({ route }) => {
  const { width, height } = useWindowDimensions();
  const [file] = React.useState<File>({
    url: require('../../../assets/storybook/book.epub'),
  });

  return (
    <SafeAreaView style={styles.container}>
      <View style={{flex:1, marginTop: spacing.extraLarge}}>
      <AppHeader backButton/>
      </View>
      <ReadiumView file={file}/>
    </SafeAreaView>
  )
})


const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'orange',
  },
})

Full screen causes problems on Android

I'm having problems with fullscreen on android, to be honest I would like to remove it, is there any way to do this?

The app's fullscreen on android does not remove the React Navigation Header, and besides, if I activate and deactivate the fullscreen a few times in a row, the location starts to "return" to the beginning of the chapter. I believe that removing the fullscreen action solves the location problem

the fullscreen action I mean, is when you click in the middle of the screen

test.webm

App Crash

It works fine in debug mode. But, in the release build app crashes when navigating to ReadiumView page.

Failing build due to missing JCenter dependencies

The following error is caused by an outdated kotlin-toolkit dependency:

[stderr] 
FAILURE:
[stderr] 
Build failed with an exception.
[stderr] 
* What went wrong:
[stderr] 
Could not determine the dependencies of task ':app:buildReleasePreBundle'.
[stderr] 
>
[stderr] 
Could not resolve all task dependencies for configuration ':app:releaseRuntimeClasspath'.
[stderr] 
>
[stderr] 
Could not find com.shopgun.android:utils:1.0.9.
[stderr] 
Searched in the following locations:
[stderr] 
- http://10.4.1.4:8081/artifactory/libs-release/com/shopgun/android/utils/1.0.9/utils-1.0.9.pom
[stderr] 
       - file:/home/expo/.m2/repository/com/shopgun/android/utils/1.0.9/utils-1.0.9.pom
[stderr] 
       - file:/home/expo/workingdir/build/node_modules/react-native/android/com/shopgun/android/utils/1.0.9/utils-1.0.9.pom
[stderr] 
       - file:/home/expo/workingdir/build/node_modules/jsc-android/dist/com/shopgun/android/utils/1.0.9/utils-1.0.9.pom
[stderr] 
       - https://dl.google.com/dl/android/maven2/com/shopgun/android/utils/1.0.9/utils-1.0.9.pom
[stderr] 
       - https://repo.maven.apache.org/maven2/com/shopgun/android/utils/1.0.9/utils-1.0.9.pom
[stderr] 
       - https://www.jitpack.io/com/shopgun/android/utils/1.0.9/utils-1.0.9.pom
[stderr] 
       - https://plugins.gradle.org/m2/com/shopgun/android/utils/1.0.9/utils-1.0.9.pom
[stderr] 
     Required by:
[stderr] 
         project :app > project :react-native-readium > com.github.readium.kotlin-toolkit:readium-navigator:2.2.1

After a brief discussion here it looks like this project needs to get updated to version 2.3. I noticed there is an open PR #38 containing the required changes. Just checking if it has been forgotten or it will be released soon?

[Bug] Reader view brightness does not match system

I'm having issues with brightness on the page I implemented Readium. The brightness is the same as the system brightness on other pages in the app, but the brightness changes when I navigate to the page with Readium. Also I would like to know if there is any way to control the brightness as in the kotlin-readium?

Build failed in Lastest react-native

With these specifications, I tried to install the build.gradle and the latest version of React Native, but I failed to get the build.
buildscript {
ext {
buildToolsVersion = "34.0.0"
minSdkVersion = 21
compileSdkVersion = 34
targetSdkVersion = 34
ndkVersion = "23.1.7779620"
kotlinVersion = "1.8.0"
}
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
}
}

I encountered the following errors:
Could not determine the dependencies of task ':app:processDebugResources'.

Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
Could not resolve com.github.barteksc:android-pdf-viewer:2.8.2.
Required by:
project :app > project :react-native-readium > com.github.readium.kotlin-toolkit:readium-navigator:2.2.1
> Could not resolve com.github.barteksc:android-pdf-viewer:2.8.2.
> Could not get resource 'https://www.jitpack.io/com/github/barteksc/android-pdf-viewer/2.8.2/android-pdf-viewer-2.8.2.pom'.
> Could not GET 'https://www.jitpack.io/com/github/barteksc/android-pdf-viewer/2.8.2/android-pdf-viewer-2.8.2.pom'. Received status code 401 from server: Unauthorized
Could not find com.duolingo.open:rtl-viewpager:1.0.3.
Searched in the following locations:
- https://oss.sonatype.org/content/repositories/snapshots/com/duolingo/open/rtl-viewpager/1.0.3/rtl-viewpager-1.0.3.pom
- https://repo.maven.apache.org/maven2/com/duolingo/open/rtl-viewpager/1.0.3/rtl-viewpager-1.0.3.pom
- file:/C:/Users/UP/Desktop/tessset/ZiBook/node_modules/jsc-android/dist/com/duolingo/open/rtl-viewpager/1.0.3/rtl-viewpager-1.0.3.pom
- https://dl.google.com/dl/android/maven2/com/duolingo/open/rtl-viewpager/1.0.3/rtl-viewpager-1.0.3.pom - https://www.jitpack.io/com/duolingo/open/rtl-viewpager/1.0.3/rtl-viewpager-1.0.3.pom
Required by:
project :app > project :react-native-readium > com.github.readium.kotlin-toolkit:readium-navigator:2.2.1
Could not find com.shopgun.android:utils:1.0.9.
Searched in the following locations:
- https://oss.sonatype.org/content/repositories/snapshots/com/shopgun/android/utils/1.0.9/utils-1.0.9.pom
- https://repo.maven.apache.org/maven2/com/shopgun/android/utils/1.0.9/utils-1.0.9.pom
- file:/C:/Users/UP/Desktop/tessset/ZiBook/node_modules/jsc-android/dist/com/shopgun/android/utils/1.0.9/utils-1.0.9.pom
- https://dl.google.com/dl/android/maven2/com/shopgun/android/utils/1.0.9/utils-1.0.9.pom
- https://www.jitpack.io/com/shopgun/android/utils/1.0.9/utils-1.0.9.pom
Required by:
project :app > project :react-native-readium > com.github.readium.kotlin-toolkit:readium-navigator:2.2.1

What is wrong???

Location doesn't work on Android and iOS

Location doesn't work on Android. Always opens the first page. Locator props works fine.

<ReadiumView
file={{url: filePath}}
settings={settings}
location={{
href: '/EPUB/text/ch002.xhtml',
locations: {
position: 5,
progression: 0,
totalProgression: 0.024390243902439025,
},
type: 'application/xhtml+xml',
}}
onLocationChange={locator => locationChanged(locator)}
/>

Error: lateinit property navigator has not been initialized

Support for React Native 0.73 - Android

I'm trying to use this library with the latest React Native version 0.73.4

But I'm having problems on Android.
I'm running the app from an emulator.

How to reproduce

npx react-native@latest init Readium073
yarn add react-native-readium
yarn android

or use my repo

https://github.com/casperolesen/Readium073

Java version error

`Execution failed for task ':react-native-readium:compileDebugKotlin'.

'compileDebugJavaWithJavac' task (current target is 17) and 'compileDebugKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version. Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain`

I've tried to remove this from the build.gradle

kotlinOptions {
    jvmTarget = "1.8"
  }

This fixes the issues with the Java version.

Build failed with an exception

I'm now getting multiple errors when trying to build like

/react-native-readium/android/src/main/java/com/reactnativereadium/ReadiumView.kt:62:7 'when' expression must be exhaustive, add necessary 'is Failure', 'OpenDrmManagementRequested', 'OpenOutlineRequested', 'StartNewSearch' branches or 'else' branch instead
/react-native-readium/android/src/main/java/com/reactnativereadium/epub/UserSettings.kt:226:73 Unresolved reference: webView
/react-native-readium/android/src/main/java/com/reactnativereadium/reader/EpubReaderFragment.kt:112:55 Unresolved reference: epub_navigator_tag

I can get the build to complete by fixing or removing the lines with errors.

Metro error

Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release

This is were I'm stuck now.

When I remove react-native-readium the app is running fine again.

I'm not an experienced kotlin developer, but I would like to help fixing this! πŸ¦Έβ€β™‚οΈ
I just don't know if it's a small bug or something that needs a bigger rewrite of this library.

If someone else can confirm that it's not working with the latest release of React Native - how should we fix it?

Example app: Unable to navigate using table of contents

Using the example app, I'm unable to navigate to the selected page. The modal closes but it doesn't perform the navigation.

Upon further investigation, I found out that onPress parameter on TableOfContents component returns a Link and not a Locator.

I also attempted to use the returned Link object as the initialLocation but it didn't work too.

Swipe navigation works as expected.

Project not working in IOS

tried all . facing these error
1.projectpath/ios/Pods/SwiftSoup/Sources/TokeniserState.swift:98:19 Protocol 'TokeniserStateProtocol' requires 'read' to be available in iOS 8.0 and newer

tried everything - clean build folder pod install

any help appreciated

Thanks.

toc hrefs with '#' cannot be navigated

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',}

LCP support

Hi Jacob,
This package seems to be very promising! Wanted to have an updated on Readium LCP support.

Can we expect it in any nearest future? How big/challenging is the scope of works seems to be?

Thanks in advance.

[Feature Request] Support for decorators like highlight & underline

I would like to add highlight/underline and ability to add notes feature . From my understanding in readium architecture a text object in Locator helps us to access text in the publication. But I’m not getting the text object in react native readium. Could you please provide information on how to access the text object using React Native Readium?

If my explanation isn't clear, the text object I'm referring is : https://readium.org/architecture/models/locators/#the-text-object

Full screen causes problems on Android

Readium full screen option works well on iOS. But it doesn't work well on Android.

In android :- Title and status bar part is not hidden in full screen option. Is there an option to enable / disable full screen? Also, how to handle the bottom page number indication? (Page number hint doesn't work on Android)

Please check the following screenshots;

iOS
Simulator Screen Shot - iPhone 13 - 2022-12-15 at 11 30 29

android
image

Build failed - android

  • What went wrong:
    Could not determine the dependencies of task ':react-native-readium:compileReleaseAidl'.

Could not resolve all task dependencies for configuration ':react-native-readium:releaseCompileClasspath'.
Could not find com.github.edrlab.nanohttpd:nanohttpd:master-SNAPSHOT.
Required by:
project :react-native-readium
Could not find com.github.edrlab.nanohttpd:nanohttpd-nanolets:master-SNAPSHOT.
Required by:
project :react-native-readium

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings

issue while running latest exampleApp due to @babel/runtime/helpers/interopRequireDefault

Could you please assist me in resolving an issue I encountered while attempting to run the Example app on Android using npm and yarn? Unfortunately, I'm currently facing an error message.

error: Error: Unable to resolve module @babel/runtime/helpers/interopRequireDefault from /Volumes/Data/WorkSpace/RNReadium/react-native-readium/src/components/ReadiumView.tsx: @babel/runtime/helpers/interopRequireDefault could not be found within the project or in these directories:
../../../../node_modules

1 | import React, { useCallback, useState, useRef, useEffect } from 'react';
2 | import { View, Platform, findNodeHandle, StyleSheet } from 'react-native';
3 |
4 | import type { BaseReadiumViewProps, Dimensions } from '../interfaces';

I have made several attempts to resolve the issue by trying different node versions, namely v14.20.1, v16.18.1, and v18.14.0. Despite multiple attempts, including deleting node modules, package.json, and yarn.lock files, clearing the cache, and adjusting the package version of @babel/runtime, I have been unable to successfully resolve the problem. Could you kindly assist me in finding a solution to this issue?

Bookmark

Is readium support bookmark feature? if yes, How can I add?

Add ability to get currently displayed page text from ePub

Please add a method to to get text from currently displayed page.

Whats would this enable:

It would be helpful to implement accessibility options i.e. text-to-speech implementations.
Or ability to get a copy of text if the ePub might be educational for example.
Ability to create implementation for citations.
etc....

Personally i would love if it was in one of two formats:
a) A method accessible through ref you can manually call.
b) A callback that is fired on page change.

I personally favor option a but this is only an opinion.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.