react-native-readium 1.0.0-alpha.8 → 1.0.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/android/src/main/java/com/reactnativereadium/ReadiumView.kt +10 -1
- package/android/src/main/java/com/reactnativereadium/ReadiumViewManager.kt +16 -6
- package/android/src/main/java/com/reactnativereadium/reader/BaseReaderFragment.kt +32 -30
- package/android/src/main/java/com/reactnativereadium/reader/ReaderViewModel.kt +2 -0
- package/ios/ReadiumView.swift +8 -3
- package/ios/ReadiumViewManager.m +1 -0
- package/lib/commonjs/components/BaseReadiumView.js.map +1 -1
- package/lib/commonjs/components/ReadiumView.js +8 -0
- package/lib/commonjs/components/ReadiumView.js.map +1 -1
- package/lib/commonjs/index.js +14 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/interfaces/Link.js +2 -0
- package/lib/commonjs/interfaces/Link.js.map +1 -0
- package/lib/commonjs/interfaces/index.js +13 -0
- package/lib/commonjs/interfaces/index.js.map +1 -1
- package/lib/module/components/BaseReadiumView.js.map +1 -1
- package/lib/module/components/ReadiumView.js +8 -0
- package/lib/module/components/ReadiumView.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/interfaces/Link.js +2 -0
- package/lib/module/interfaces/Link.js.map +1 -0
- package/lib/module/interfaces/index.js +1 -0
- package/lib/module/interfaces/index.js.map +1 -1
- package/lib/typescript/components/BaseReadiumView.d.ts +2 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/interfaces/Link.d.ts +18 -0
- package/lib/typescript/interfaces/Locator.d.ts +4 -4
- package/lib/typescript/interfaces/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/BaseReadiumView.tsx +2 -1
- package/src/components/ReadiumView.tsx +9 -0
- package/src/index.tsx +1 -0
- package/src/interfaces/Link.ts +18 -0
- package/src/interfaces/Locator.ts +4 -4
- package/src/interfaces/index.ts +1 -0
package/README.md
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
# react-native-readium
|
|
2
2
|
|
|
3
|
-
A react-native wrapper for https://readium.org
|
|
3
|
+
A react-native wrapper for https://readium.org/. At a high level this package
|
|
4
|
+
allows you to do things like:
|
|
5
|
+
|
|
6
|
+
- Render an ebook view.
|
|
7
|
+
- Register for location changes (as the user pages through the book).
|
|
8
|
+
- Register for the Table of Contents (so that you can display things like chapters in your app)
|
|
9
|
+
- Control settings of the Reader. Things like:
|
|
10
|
+
- Dark Mode, Light Mode, Sepia Mode
|
|
11
|
+
- Font Size
|
|
12
|
+
- Page Margins
|
|
13
|
+
- More (see the `Settings` documentation in the [API section](#api))
|
|
14
|
+
- Etc. (read on for more details. :book:)
|
|
15
|
+
|
|
16
|
+
## Overview
|
|
4
17
|
|
|
5
18
|
- [Installation](#installation)
|
|
6
19
|
- [Usage](#usage)
|
|
@@ -128,6 +141,7 @@ DRM is not supported at this time. However, there is a clear path to [support it
|
|
|
128
141
|
| `settings` | [`Partial<Settings>`](https://github.com/5-stones/react-native-readium/blob/main/src/interfaces/Settings.ts) | :white_check_mark: | An object that allows you to control various aspects of the reader's UI (epub only) |
|
|
129
142
|
| `style` | `ViewStyle` | :white_check_mark: | A traditional style object. |
|
|
130
143
|
| `onLocationChange` | `(locator: Locator) => void` | :white_check_mark: | A callback that fires whenever the location is changed (e.g. the user transitions to a new page)|
|
|
144
|
+
| `onTableOfContents` | `(toc: Link[] \| null) => void` | :white_check_mark: | 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`](https://github.com/5-stones/react-native-readium/blob/main/src/interfaces/Link.ts) interface for more info. |
|
|
131
145
|
|
|
132
146
|
## Contributing
|
|
133
147
|
|
|
@@ -45,9 +45,9 @@ class ReadiumView(
|
|
|
45
45
|
.replace(this.id, frag, this.id.toString())
|
|
46
46
|
.commit()
|
|
47
47
|
|
|
48
|
+
val module = reactContext.getJSModule(RCTEventEmitter::class.java)
|
|
48
49
|
// subscribe to reader events
|
|
49
50
|
frag.channel.receive(frag) { event ->
|
|
50
|
-
val module = reactContext.getJSModule(RCTEventEmitter::class.java)
|
|
51
51
|
when (event) {
|
|
52
52
|
is ReaderViewModel.Event.LocatorUpdate -> {
|
|
53
53
|
val json = event.locator.toJSON()
|
|
@@ -58,6 +58,15 @@ class ReadiumView(
|
|
|
58
58
|
payload
|
|
59
59
|
)
|
|
60
60
|
}
|
|
61
|
+
is ReaderViewModel.Event.TableOfContentsLoaded -> {
|
|
62
|
+
val map = event.toc.map { it.toJSON().toMap() }
|
|
63
|
+
val payload = Arguments.makeNativeMap(mapOf("toc" to map))
|
|
64
|
+
module.receiveEvent(
|
|
65
|
+
this.id.toInt(),
|
|
66
|
+
ReadiumViewManager.ON_TABLE_OF_CONTENTS,
|
|
67
|
+
payload
|
|
68
|
+
)
|
|
69
|
+
}
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
}
|
|
@@ -25,13 +25,22 @@ class ReadiumViewManager(
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
override fun getExportedCustomBubblingEventTypeConstants(): Map<String, Any> {
|
|
28
|
-
return MapBuilder.builder<String, Any>()
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
return MapBuilder.builder<String, Any>()
|
|
29
|
+
.put(
|
|
30
|
+
ON_LOCATION_CHANGE,
|
|
31
|
+
MapBuilder.of(
|
|
32
|
+
"phasedRegistrationNames",
|
|
33
|
+
MapBuilder.of("bubbled", ON_LOCATION_CHANGE)
|
|
34
|
+
)
|
|
33
35
|
)
|
|
34
|
-
|
|
36
|
+
.put(
|
|
37
|
+
ON_TABLE_OF_CONTENTS,
|
|
38
|
+
MapBuilder.of(
|
|
39
|
+
"phasedRegistrationNames",
|
|
40
|
+
MapBuilder.of("bubbled", ON_TABLE_OF_CONTENTS)
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
.build()
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
override fun getCommandsMap(): MutableMap<String, Int> {
|
|
@@ -108,6 +117,7 @@ class ReadiumViewManager(
|
|
|
108
117
|
|
|
109
118
|
companion object {
|
|
110
119
|
var ON_LOCATION_CHANGE = "onLocationChange"
|
|
120
|
+
var ON_TABLE_OF_CONTENTS = "onTableOfContents"
|
|
111
121
|
var COMMAND_CREATE = 1
|
|
112
122
|
}
|
|
113
123
|
}
|
|
@@ -10,6 +10,7 @@ import org.readium.r2.navigator.*
|
|
|
10
10
|
import org.readium.r2.shared.publication.Locator
|
|
11
11
|
import com.reactnativereadium.utils.EventChannel
|
|
12
12
|
import kotlinx.coroutines.channels.Channel
|
|
13
|
+
import org.readium.r2.shared.publication.Link
|
|
13
14
|
|
|
14
15
|
/*
|
|
15
16
|
* Base reader fragment class
|
|
@@ -24,37 +25,38 @@ abstract class BaseReaderFragment : Fragment() {
|
|
|
24
25
|
)
|
|
25
26
|
|
|
26
27
|
protected abstract val model: ReaderViewModel
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
protected abstract val navigator: Navigator
|
|
29
|
+
|
|
30
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
|
31
|
+
setHasOptionsMenu(true)
|
|
32
|
+
super.onCreate(savedInstanceState)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
36
|
+
super.onViewCreated(view, savedInstanceState)
|
|
37
|
+
|
|
38
|
+
val viewScope = viewLifecycleOwner.lifecycleScope
|
|
39
|
+
|
|
40
|
+
channel.send(ReaderViewModel.Event.TableOfContentsLoaded(model.publication.tableOfContents))
|
|
41
|
+
navigator.currentLocator
|
|
42
|
+
.onEach { channel.send(ReaderViewModel.Event.LocatorUpdate(it)) }
|
|
43
|
+
.launchIn(viewScope)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
override fun onHiddenChanged(hidden: Boolean) {
|
|
47
|
+
super.onHiddenChanged(hidden)
|
|
48
|
+
setMenuVisibility(!hidden)
|
|
49
|
+
requireActivity().invalidateOptionsMenu()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fun go(locator: Locator, animated: Boolean): Boolean {
|
|
53
|
+
// don't attempt to navigate if we're already there
|
|
54
|
+
val currentLocator = navigator.currentLocator.value
|
|
55
|
+
if (locator.hashCode() == currentLocator.hashCode()) {
|
|
56
|
+
return true
|
|
42
57
|
}
|
|
43
58
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
setMenuVisibility(!hidden)
|
|
47
|
-
requireActivity().invalidateOptionsMenu()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
fun go(locator: Locator, animated: Boolean): Boolean {
|
|
51
|
-
// don't attempt to navigate if we're already there
|
|
52
|
-
val currentLocator = navigator.currentLocator.value
|
|
53
|
-
if (locator.hashCode() == currentLocator.hashCode()) {
|
|
54
|
-
return true
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return navigator.go(locator, animated)
|
|
58
|
-
}
|
|
59
|
+
return navigator.go(locator, animated)
|
|
60
|
+
}
|
|
59
61
|
|
|
60
62
|
}
|
|
@@ -20,6 +20,7 @@ import org.readium.r2.shared.publication.services.search.SearchIterator
|
|
|
20
20
|
import org.readium.r2.shared.publication.services.search.SearchTry
|
|
21
21
|
import org.readium.r2.shared.Search
|
|
22
22
|
import org.readium.r2.shared.UserException
|
|
23
|
+
import org.readium.r2.shared.publication.Link
|
|
23
24
|
import org.readium.r2.shared.util.Try
|
|
24
25
|
|
|
25
26
|
@OptIn(Search::class, ExperimentalDecorator::class)
|
|
@@ -111,6 +112,7 @@ class ReaderViewModel(
|
|
|
111
112
|
object StartNewSearch : Event()
|
|
112
113
|
class Failure(val error: UserException) : Event()
|
|
113
114
|
class LocatorUpdate(val locator: Locator) : Event()
|
|
115
|
+
class TableOfContentsLoaded(val toc: List<Link>) : Event()
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
sealed class FeedbackEvent {
|
package/ios/ReadiumView.swift
CHANGED
|
@@ -37,6 +37,7 @@ class ReadiumView : UIView, Loggable {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
@objc var onLocationChange: RCTDirectEventBlock?
|
|
40
|
+
@objc var onTableOfContents: RCTDirectEventBlock?
|
|
40
41
|
|
|
41
42
|
func loadBook(url: String) {
|
|
42
43
|
guard let rootViewController = UIApplication.shared.delegate?.window??.rootViewController else { return }
|
|
@@ -128,9 +129,7 @@ class ReadiumView : UIView, Loggable {
|
|
|
128
129
|
private func addViewControllerAsSubview(_ vc: ReaderViewController) {
|
|
129
130
|
vc.publisher.sink(
|
|
130
131
|
receiveValue: { locator in
|
|
131
|
-
|
|
132
|
-
self.onLocationChange!(locator.json)
|
|
133
|
-
}
|
|
132
|
+
self.onLocationChange?(locator.json)
|
|
134
133
|
}
|
|
135
134
|
)
|
|
136
135
|
.store(in: &self.subscriptions)
|
|
@@ -155,5 +154,11 @@ class ReadiumView : UIView, Loggable {
|
|
|
155
154
|
rootView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
|
|
156
155
|
rootView.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
|
|
157
156
|
rootView.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
|
|
157
|
+
|
|
158
|
+
self.onTableOfContents?([
|
|
159
|
+
"toc": vc.publication.tableOfContents.map({ link in
|
|
160
|
+
return link.json
|
|
161
|
+
})
|
|
162
|
+
])
|
|
158
163
|
}
|
|
159
164
|
}
|
package/ios/ReadiumViewManager.m
CHANGED
|
@@ -6,5 +6,6 @@ RCT_EXPORT_VIEW_PROPERTY(file, NSDictionary *)
|
|
|
6
6
|
RCT_EXPORT_VIEW_PROPERTY(location, NSDictionary *)
|
|
7
7
|
RCT_EXPORT_VIEW_PROPERTY(settings, NSDictionary *)
|
|
8
8
|
RCT_EXPORT_VIEW_PROPERTY(onLocationChange, RCTDirectEventBlock)
|
|
9
|
+
RCT_EXPORT_VIEW_PROPERTY(onTableOfContents, RCTDirectEventBlock)
|
|
9
10
|
|
|
10
11
|
@end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["BaseReadiumView.tsx"],"names":["BaseReadiumView","UIManager","getViewManagerConfig","COMPONENT_NAME","Error","LINKING_ERROR"],"mappings":";;;;;;;AAAA;;AAOA;;
|
|
1
|
+
{"version":3,"sources":["BaseReadiumView.tsx"],"names":["BaseReadiumView","UIManager","getViewManagerConfig","COMPONENT_NAME","Error","LINKING_ERROR"],"mappings":";;;;;;;AAAA;;AAOA;;AAcO,MAAMA,eAAe,GAC1BC,uBAAUC,oBAAV,CAA+BC,qBAA/B,KAAkD,IAAlD,GACI,yCAA6CA,qBAA7C,CADJ,GAEI,MAAM;AACJ,QAAM,IAAIC,KAAJ,CAAUC,oBAAV,CAAN;AACD,CALA","sourcesContent":["import {\n requireNativeComponent,\n UIManager,\n ViewStyle,\n} from 'react-native';\n\nimport type { Settings, Link, Locator, File, } from '../interfaces';\nimport { COMPONENT_NAME, LINKING_ERROR } from '../utils';\n\nexport type BaseReadiumViewProps = {\n file: File;\n location?: Locator;\n settings?: Partial<Settings>;\n style?: ViewStyle;\n onLocationChange?: (locator: Locator) => void;\n onTableOfContents?: (toc: Link[] | null) => void;\n ref?: any;\n height?: number;\n width?: number;\n};\n\nexport const BaseReadiumView =\n UIManager.getViewManagerConfig(COMPONENT_NAME) != null\n ? requireNativeComponent<BaseReadiumViewProps>(COMPONENT_NAME)\n : () => {\n throw new Error(LINKING_ERROR);\n };\n"]}
|
|
@@ -24,6 +24,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
|
24
24
|
const ReadiumView = _ref => {
|
|
25
25
|
let {
|
|
26
26
|
onLocationChange: wrappedOnLocationChange,
|
|
27
|
+
onTableOfContents: wrappedOnTableOfContents,
|
|
27
28
|
settings: unmappedSettings,
|
|
28
29
|
...props
|
|
29
30
|
} = _ref;
|
|
@@ -56,6 +57,12 @@ const ReadiumView = _ref => {
|
|
|
56
57
|
wrappedOnLocationChange(event.nativeEvent);
|
|
57
58
|
}
|
|
58
59
|
}, [wrappedOnLocationChange]);
|
|
60
|
+
const onTableOfContents = (0, _react.useCallback)(event => {
|
|
61
|
+
if (wrappedOnTableOfContents) {
|
|
62
|
+
const toc = event.nativeEvent.toc || null;
|
|
63
|
+
wrappedOnTableOfContents(toc);
|
|
64
|
+
}
|
|
65
|
+
}, [wrappedOnTableOfContents]);
|
|
59
66
|
(0, _react.useEffect)(() => {
|
|
60
67
|
if (_reactNative.Platform.OS === 'android') {
|
|
61
68
|
const viewId = (0, _reactNative.findNodeHandle)(ref.current);
|
|
@@ -70,6 +77,7 @@ const ReadiumView = _ref => {
|
|
|
70
77
|
width: width
|
|
71
78
|
}, props, {
|
|
72
79
|
onLocationChange: onLocationChange,
|
|
80
|
+
onTableOfContents: onTableOfContents,
|
|
73
81
|
settings: unmappedSettings ? _interfaces.Settings.map(unmappedSettings) : undefined,
|
|
74
82
|
ref: ref
|
|
75
83
|
})));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ReadiumView.tsx"],"names":["ReadiumView","onLocationChange","wrappedOnLocationChange","settings","unmappedSettings","props","ref","height","width","setDimensions","onLayout","nativeEvent","layout","event","Platform","OS","viewId","current","styles","container","Settings","map","undefined","StyleSheet","create"],"mappings":";;;;;;;AAAA;;AACA;;AAGA;;AACA;;AAEA;;;;;;;;AAIO,MAAMA,WAAmC,GAAG,
|
|
1
|
+
{"version":3,"sources":["ReadiumView.tsx"],"names":["ReadiumView","onLocationChange","wrappedOnLocationChange","onTableOfContents","wrappedOnTableOfContents","settings","unmappedSettings","props","ref","height","width","setDimensions","onLayout","nativeEvent","layout","event","toc","Platform","OS","viewId","current","styles","container","Settings","map","undefined","StyleSheet","create"],"mappings":";;;;;;;AAAA;;AACA;;AAGA;;AACA;;AAEA;;;;;;;;AAIO,MAAMA,WAAmC,GAAG,QAK7C;AAAA,MAL8C;AAClDC,IAAAA,gBAAgB,EAAEC,uBADgC;AAElDC,IAAAA,iBAAiB,EAAEC,wBAF+B;AAGlDC,IAAAA,QAAQ,EAAEC,gBAHwC;AAIlD,OAAGC;AAJ+C,GAK9C;AACJ,QAAMC,GAAG,GAAG,mBAAO,IAAP,CAAZ;AACA,QAAM,CAAC;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAAD,EAAoBC,aAApB,IAAqC,qBAAqB;AAC9DD,IAAAA,KAAK,EAAE,CADuD;AAE9DD,IAAAA,MAAM,EAAE;AAFsD,GAArB,CAA3C,CAFI,CAMJ;;AACA,QAAMG,QAAQ,GAAG,wBAAY,SAAmD;AAAA,QAAlD;AAAEC,MAAAA,WAAW,EAAE;AAAEC,QAAAA,MAAM,EAAE;AAAEJ,UAAAA,KAAF;AAASD,UAAAA;AAAT;AAAV;AAAf,KAAkD;AAC9EE,IAAAA,aAAa,CAAC;AACZD,MAAAA,KAAK,EAAE,kCAAUA,KAAV,CADK;AAEZD,MAAAA,MAAM,EAAE,kCAAUA,MAAV;AAFI,KAAD,CAAb;AAID,GALgB,EAKd,EALc,CAAjB,CAPI,CAaJ;;AACA,QAAMR,gBAAgB,GAAG,wBAAac,KAAD,IAAgB;AACnD,QAAIb,uBAAJ,EAA6B;AAC3BA,MAAAA,uBAAuB,CAACa,KAAK,CAACF,WAAP,CAAvB;AACD;AACF,GAJwB,EAItB,CAACX,uBAAD,CAJsB,CAAzB;AAMA,QAAMC,iBAAiB,GAAG,wBAAaY,KAAD,IAAgB;AACpD,QAAIX,wBAAJ,EAA8B;AAC5B,YAAMY,GAAG,GAAGD,KAAK,CAACF,WAAN,CAAkBG,GAAlB,IAAyB,IAArC;AACAZ,MAAAA,wBAAwB,CAACY,GAAD,CAAxB;AACD;AACF,GALyB,EAKvB,CAACZ,wBAAD,CALuB,CAA1B;AAOA,wBAAU,MAAM;AACd,QAAIa,sBAASC,EAAT,KAAgB,SAApB,EAA+B;AAC7B,YAAMC,MAAM,GAAG,iCAAeX,GAAG,CAACY,OAAnB,CAAf;AACA,iCAAeD,MAAf;AACD;AACF,GALD,EAKG,EALH;AAOA,sBACE,6BAAC,iBAAD;AACE,IAAA,KAAK,EAAEE,MAAM,CAACC,SADhB;AAEE,IAAA,QAAQ,EAAEV;AAFZ,kBAIE,6BAAC,gCAAD;AACE,IAAA,MAAM,EAAEH,MADV;AAEE,IAAA,KAAK,EAAEC;AAFT,KAGMH,KAHN;AAIE,IAAA,gBAAgB,EAAEN,gBAJpB;AAKE,IAAA,iBAAiB,EAAEE,iBALrB;AAME,IAAA,QAAQ,EAAEG,gBAAgB,GAAGiB,qBAASC,GAAT,CAAalB,gBAAb,CAAH,GAAoCmB,SANhE;AAOE,IAAA,GAAG,EAAEjB;AAPP,KAJF,CADF;AAgBD,CAvDM;;;;AAyDP,MAAMa,MAAM,GAAGK,wBAAWC,MAAX,CAAkB;AAC/BL,EAAAA,SAAS,EAAE;AAAEZ,IAAAA,KAAK,EAAE,MAAT;AAAiBD,IAAAA,MAAM,EAAE;AAAzB;AADoB,CAAlB,CAAf","sourcesContent":["import React, { useCallback, useState, useRef, useEffect } from 'react';\nimport { View, Platform, findNodeHandle, StyleSheet } from 'react-native';\n\nimport type { Dimensions } from '../interfaces';\nimport { Settings } from '../interfaces';\nimport { createFragment, getWidthOrHeightValue as dimension } from '../utils';\nimport type { BaseReadiumViewProps } from './BaseReadiumView';\nimport { BaseReadiumView } from './BaseReadiumView';\n\ntype ReadiumProps = BaseReadiumViewProps;\n\nexport const ReadiumView: React.FC<ReadiumProps> = ({\n onLocationChange: wrappedOnLocationChange,\n onTableOfContents: wrappedOnTableOfContents,\n settings: unmappedSettings,\n ...props\n}) => {\n const ref = useRef(null);\n const [{ height, width }, setDimensions] = useState<Dimensions>({\n width: 0,\n height: 0,\n });\n // set the view dimensions on layout\n const onLayout = useCallback(({ nativeEvent: { layout: { width, height } }}) => {\n setDimensions({\n width: dimension(width),\n height: dimension(height),\n });\n }, []);\n // wrap the native onLocationChange and extract the raw event value\n const onLocationChange = useCallback((event: any) => {\n if (wrappedOnLocationChange) {\n wrappedOnLocationChange(event.nativeEvent);\n }\n }, [wrappedOnLocationChange]);\n\n const onTableOfContents = useCallback((event: any) => {\n if (wrappedOnTableOfContents) {\n const toc = event.nativeEvent.toc || null;\n wrappedOnTableOfContents(toc);\n }\n }, [wrappedOnTableOfContents]);\n\n useEffect(() => {\n if (Platform.OS === 'android') {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }\n }, [])\n\n return (\n <View\n style={styles.container}\n onLayout={onLayout}\n >\n <BaseReadiumView\n height={height}\n width={width}\n {...props}\n onLocationChange={onLocationChange}\n onTableOfContents={onTableOfContents}\n settings={unmappedSettings ? Settings.map(unmappedSettings) : undefined}\n ref={ref}\n />\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: { width: '100%', height: '100%' },\n});\n"]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -3,11 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
RANGES: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "RANGES", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _utils.RANGES;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
6
15
|
|
|
7
16
|
var _enums = require("./enums");
|
|
8
17
|
|
|
9
18
|
Object.keys(_enums).forEach(function (key) {
|
|
10
19
|
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
11
21
|
if (key in exports && exports[key] === _enums[key]) return;
|
|
12
22
|
Object.defineProperty(exports, key, {
|
|
13
23
|
enumerable: true,
|
|
@@ -21,6 +31,7 @@ var _interfaces = require("./interfaces");
|
|
|
21
31
|
|
|
22
32
|
Object.keys(_interfaces).forEach(function (key) {
|
|
23
33
|
if (key === "default" || key === "__esModule") return;
|
|
34
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
24
35
|
if (key in exports && exports[key] === _interfaces[key]) return;
|
|
25
36
|
Object.defineProperty(exports, key, {
|
|
26
37
|
enumerable: true,
|
|
@@ -30,10 +41,13 @@ Object.keys(_interfaces).forEach(function (key) {
|
|
|
30
41
|
});
|
|
31
42
|
});
|
|
32
43
|
|
|
44
|
+
var _utils = require("./utils");
|
|
45
|
+
|
|
33
46
|
var _ReadiumView = require("./components/ReadiumView");
|
|
34
47
|
|
|
35
48
|
Object.keys(_ReadiumView).forEach(function (key) {
|
|
36
49
|
if (key === "default" || key === "__esModule") return;
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
37
51
|
if (key in exports && exports[key] === _ReadiumView[key]) return;
|
|
38
52
|
Object.defineProperty(exports, key, {
|
|
39
53
|
enumerable: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './enums';\nexport * from './interfaces';\nexport { RANGES } from './utils';\nexport * from './components/ReadiumView';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -30,6 +30,19 @@ Object.keys(_File).forEach(function (key) {
|
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
+
var _Link = require("./Link");
|
|
34
|
+
|
|
35
|
+
Object.keys(_Link).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _Link[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _Link[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
33
46
|
var _Locator = require("./Locator");
|
|
34
47
|
|
|
35
48
|
Object.keys(_Locator).forEach(function (key) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './Dimensions';\nexport * from './File';\nexport * from './Locator';\nexport * from './Settings';\n"]}
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './Dimensions';\nexport * from './File';\nexport * from './Link';\nexport * from './Locator';\nexport * from './Settings';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["BaseReadiumView.tsx"],"names":["requireNativeComponent","UIManager","COMPONENT_NAME","LINKING_ERROR","BaseReadiumView","getViewManagerConfig","Error"],"mappings":"AAAA,SACEA,sBADF,EAEEC,SAFF,QAIO,cAJP;AAOA,SAASC,cAAT,EAAyBC,aAAzB,QAA8C,UAA9C;
|
|
1
|
+
{"version":3,"sources":["BaseReadiumView.tsx"],"names":["requireNativeComponent","UIManager","COMPONENT_NAME","LINKING_ERROR","BaseReadiumView","getViewManagerConfig","Error"],"mappings":"AAAA,SACEA,sBADF,EAEEC,SAFF,QAIO,cAJP;AAOA,SAASC,cAAT,EAAyBC,aAAzB,QAA8C,UAA9C;AAcA,OAAO,MAAMC,eAAe,GAC1BH,SAAS,CAACI,oBAAV,CAA+BH,cAA/B,KAAkD,IAAlD,GACIF,sBAAsB,CAAuBE,cAAvB,CAD1B,GAEI,MAAM;AACJ,QAAM,IAAII,KAAJ,CAAUH,aAAV,CAAN;AACD,CALA","sourcesContent":["import {\n requireNativeComponent,\n UIManager,\n ViewStyle,\n} from 'react-native';\n\nimport type { Settings, Link, Locator, File, } from '../interfaces';\nimport { COMPONENT_NAME, LINKING_ERROR } from '../utils';\n\nexport type BaseReadiumViewProps = {\n file: File;\n location?: Locator;\n settings?: Partial<Settings>;\n style?: ViewStyle;\n onLocationChange?: (locator: Locator) => void;\n onTableOfContents?: (toc: Link[] | null) => void;\n ref?: any;\n height?: number;\n width?: number;\n};\n\nexport const BaseReadiumView =\n UIManager.getViewManagerConfig(COMPONENT_NAME) != null\n ? requireNativeComponent<BaseReadiumViewProps>(COMPONENT_NAME)\n : () => {\n throw new Error(LINKING_ERROR);\n };\n"]}
|
|
@@ -8,6 +8,7 @@ import { BaseReadiumView } from './BaseReadiumView';
|
|
|
8
8
|
export const ReadiumView = _ref => {
|
|
9
9
|
let {
|
|
10
10
|
onLocationChange: wrappedOnLocationChange,
|
|
11
|
+
onTableOfContents: wrappedOnTableOfContents,
|
|
11
12
|
settings: unmappedSettings,
|
|
12
13
|
...props
|
|
13
14
|
} = _ref;
|
|
@@ -40,6 +41,12 @@ export const ReadiumView = _ref => {
|
|
|
40
41
|
wrappedOnLocationChange(event.nativeEvent);
|
|
41
42
|
}
|
|
42
43
|
}, [wrappedOnLocationChange]);
|
|
44
|
+
const onTableOfContents = useCallback(event => {
|
|
45
|
+
if (wrappedOnTableOfContents) {
|
|
46
|
+
const toc = event.nativeEvent.toc || null;
|
|
47
|
+
wrappedOnTableOfContents(toc);
|
|
48
|
+
}
|
|
49
|
+
}, [wrappedOnTableOfContents]);
|
|
43
50
|
useEffect(() => {
|
|
44
51
|
if (Platform.OS === 'android') {
|
|
45
52
|
const viewId = findNodeHandle(ref.current);
|
|
@@ -54,6 +61,7 @@ export const ReadiumView = _ref => {
|
|
|
54
61
|
width: width
|
|
55
62
|
}, props, {
|
|
56
63
|
onLocationChange: onLocationChange,
|
|
64
|
+
onTableOfContents: onTableOfContents,
|
|
57
65
|
settings: unmappedSettings ? Settings.map(unmappedSettings) : undefined,
|
|
58
66
|
ref: ref
|
|
59
67
|
})));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ReadiumView.tsx"],"names":["React","useCallback","useState","useRef","useEffect","View","Platform","findNodeHandle","StyleSheet","Settings","createFragment","getWidthOrHeightValue","dimension","BaseReadiumView","ReadiumView","onLocationChange","wrappedOnLocationChange","settings","unmappedSettings","props","ref","height","width","setDimensions","onLayout","nativeEvent","layout","event","OS","viewId","current","styles","container","map","undefined","create"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,QAA7B,EAAuCC,MAAvC,EAA+CC,SAA/C,QAAgE,OAAhE;AACA,SAASC,IAAT,EAAeC,QAAf,EAAyBC,cAAzB,EAAyCC,UAAzC,QAA2D,cAA3D;AAGA,SAASC,QAAT,QAAyB,eAAzB;AACA,SAASC,cAAT,EAAyBC,qBAAqB,IAAIC,SAAlD,QAAmE,UAAnE;AAEA,SAASC,eAAT,QAAgC,mBAAhC;AAIA,OAAO,MAAMC,WAAmC,GAAG,
|
|
1
|
+
{"version":3,"sources":["ReadiumView.tsx"],"names":["React","useCallback","useState","useRef","useEffect","View","Platform","findNodeHandle","StyleSheet","Settings","createFragment","getWidthOrHeightValue","dimension","BaseReadiumView","ReadiumView","onLocationChange","wrappedOnLocationChange","onTableOfContents","wrappedOnTableOfContents","settings","unmappedSettings","props","ref","height","width","setDimensions","onLayout","nativeEvent","layout","event","toc","OS","viewId","current","styles","container","map","undefined","create"],"mappings":"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","sourcesContent":["import React, { useCallback, useState, useRef, useEffect } from 'react';\nimport { View, Platform, findNodeHandle, StyleSheet } from 'react-native';\n\nimport type { Dimensions } from '../interfaces';\nimport { Settings } from '../interfaces';\nimport { createFragment, getWidthOrHeightValue as dimension } from '../utils';\nimport type { BaseReadiumViewProps } from './BaseReadiumView';\nimport { BaseReadiumView } from './BaseReadiumView';\n\ntype ReadiumProps = BaseReadiumViewProps;\n\nexport const ReadiumView: React.FC<ReadiumProps> = ({\n onLocationChange: wrappedOnLocationChange,\n onTableOfContents: wrappedOnTableOfContents,\n settings: unmappedSettings,\n ...props\n}) => {\n const ref = useRef(null);\n const [{ height, width }, setDimensions] = useState<Dimensions>({\n width: 0,\n height: 0,\n });\n // set the view dimensions on layout\n const onLayout = useCallback(({ nativeEvent: { layout: { width, height } }}) => {\n setDimensions({\n width: dimension(width),\n height: dimension(height),\n });\n }, []);\n // wrap the native onLocationChange and extract the raw event value\n const onLocationChange = useCallback((event: any) => {\n if (wrappedOnLocationChange) {\n wrappedOnLocationChange(event.nativeEvent);\n }\n }, [wrappedOnLocationChange]);\n\n const onTableOfContents = useCallback((event: any) => {\n if (wrappedOnTableOfContents) {\n const toc = event.nativeEvent.toc || null;\n wrappedOnTableOfContents(toc);\n }\n }, [wrappedOnTableOfContents]);\n\n useEffect(() => {\n if (Platform.OS === 'android') {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }\n }, [])\n\n return (\n <View\n style={styles.container}\n onLayout={onLayout}\n >\n <BaseReadiumView\n height={height}\n width={width}\n {...props}\n onLocationChange={onLocationChange}\n onTableOfContents={onTableOfContents}\n settings={unmappedSettings ? Settings.map(unmappedSettings) : undefined}\n ref={ref}\n />\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: { width: '100%', height: '100%' },\n});\n"]}
|
package/lib/module/index.js
CHANGED
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":[],"mappings":"AAAA,cAAc,SAAd;AACA,cAAc,cAAd;AACA,cAAc,0BAAd","sourcesContent":["export * from './enums';\nexport * from './interfaces';\nexport * from './components/ReadiumView';\n"]}
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["RANGES"],"mappings":"AAAA,cAAc,SAAd;AACA,cAAc,cAAd;AACA,SAASA,MAAT,QAAuB,SAAvB;AACA,cAAc,0BAAd","sourcesContent":["export * from './enums';\nexport * from './interfaces';\nexport { RANGES } from './utils';\nexport * from './components/ReadiumView';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAd;AACA,cAAc,QAAd;AACA,cAAc,WAAd;AACA,cAAc,YAAd","sourcesContent":["export * from './Dimensions';\nexport * from './File';\nexport * from './Locator';\nexport * from './Settings';\n"]}
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAd;AACA,cAAc,QAAd;AACA,cAAc,QAAd;AACA,cAAc,WAAd;AACA,cAAc,YAAd","sourcesContent":["export * from './Dimensions';\nexport * from './File';\nexport * from './Link';\nexport * from './Locator';\nexport * from './Settings';\n"]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ViewStyle } from 'react-native';
|
|
2
|
-
import type { Settings, Locator, File } from '../interfaces';
|
|
2
|
+
import type { Settings, Link, Locator, File } from '../interfaces';
|
|
3
3
|
export declare type BaseReadiumViewProps = {
|
|
4
4
|
file: File;
|
|
5
5
|
location?: Locator;
|
|
6
6
|
settings?: Partial<Settings>;
|
|
7
7
|
style?: ViewStyle;
|
|
8
8
|
onLocationChange?: (locator: Locator) => void;
|
|
9
|
+
onTableOfContents?: (toc: Link[] | null) => void;
|
|
9
10
|
ref?: any;
|
|
10
11
|
height?: number;
|
|
11
12
|
width?: number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An interface representing the Readium Link object.
|
|
3
|
+
*/
|
|
4
|
+
export interface Link {
|
|
5
|
+
href: string;
|
|
6
|
+
templated: boolean;
|
|
7
|
+
type?: string | null;
|
|
8
|
+
title?: string | null;
|
|
9
|
+
rels?: Set<string>;
|
|
10
|
+
properties?: any;
|
|
11
|
+
height?: number | null;
|
|
12
|
+
width?: number | null;
|
|
13
|
+
bitrate?: number | null;
|
|
14
|
+
duration?: number | null;
|
|
15
|
+
languages?: string[];
|
|
16
|
+
alternates?: Link[];
|
|
17
|
+
children?: Link[];
|
|
18
|
+
}
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
export interface Locator {
|
|
5
5
|
href: string;
|
|
6
6
|
type: string;
|
|
7
|
-
target
|
|
7
|
+
target?: number;
|
|
8
8
|
title?: string;
|
|
9
|
-
locations
|
|
10
|
-
position: number;
|
|
9
|
+
locations?: {
|
|
11
10
|
progression: number;
|
|
12
|
-
|
|
11
|
+
position?: number;
|
|
12
|
+
totalProgression?: number;
|
|
13
13
|
};
|
|
14
14
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
ViewStyle,
|
|
5
5
|
} from 'react-native';
|
|
6
6
|
|
|
7
|
-
import type { Settings, Locator, File, } from '../interfaces';
|
|
7
|
+
import type { Settings, Link, Locator, File, } from '../interfaces';
|
|
8
8
|
import { COMPONENT_NAME, LINKING_ERROR } from '../utils';
|
|
9
9
|
|
|
10
10
|
export type BaseReadiumViewProps = {
|
|
@@ -13,6 +13,7 @@ export type BaseReadiumViewProps = {
|
|
|
13
13
|
settings?: Partial<Settings>;
|
|
14
14
|
style?: ViewStyle;
|
|
15
15
|
onLocationChange?: (locator: Locator) => void;
|
|
16
|
+
onTableOfContents?: (toc: Link[] | null) => void;
|
|
16
17
|
ref?: any;
|
|
17
18
|
height?: number;
|
|
18
19
|
width?: number;
|
|
@@ -11,6 +11,7 @@ type ReadiumProps = BaseReadiumViewProps;
|
|
|
11
11
|
|
|
12
12
|
export const ReadiumView: React.FC<ReadiumProps> = ({
|
|
13
13
|
onLocationChange: wrappedOnLocationChange,
|
|
14
|
+
onTableOfContents: wrappedOnTableOfContents,
|
|
14
15
|
settings: unmappedSettings,
|
|
15
16
|
...props
|
|
16
17
|
}) => {
|
|
@@ -33,6 +34,13 @@ export const ReadiumView: React.FC<ReadiumProps> = ({
|
|
|
33
34
|
}
|
|
34
35
|
}, [wrappedOnLocationChange]);
|
|
35
36
|
|
|
37
|
+
const onTableOfContents = useCallback((event: any) => {
|
|
38
|
+
if (wrappedOnTableOfContents) {
|
|
39
|
+
const toc = event.nativeEvent.toc || null;
|
|
40
|
+
wrappedOnTableOfContents(toc);
|
|
41
|
+
}
|
|
42
|
+
}, [wrappedOnTableOfContents]);
|
|
43
|
+
|
|
36
44
|
useEffect(() => {
|
|
37
45
|
if (Platform.OS === 'android') {
|
|
38
46
|
const viewId = findNodeHandle(ref.current);
|
|
@@ -50,6 +58,7 @@ export const ReadiumView: React.FC<ReadiumProps> = ({
|
|
|
50
58
|
width={width}
|
|
51
59
|
{...props}
|
|
52
60
|
onLocationChange={onLocationChange}
|
|
61
|
+
onTableOfContents={onTableOfContents}
|
|
53
62
|
settings={unmappedSettings ? Settings.map(unmappedSettings) : undefined}
|
|
54
63
|
ref={ref}
|
|
55
64
|
/>
|
package/src/index.tsx
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An interface representing the Readium Link object.
|
|
3
|
+
*/
|
|
4
|
+
export interface Link {
|
|
5
|
+
href: string;
|
|
6
|
+
templated: boolean;
|
|
7
|
+
type?: string | null;
|
|
8
|
+
title?: string | null;
|
|
9
|
+
rels?: Set<string>;
|
|
10
|
+
properties?: any;
|
|
11
|
+
height?: number | null;
|
|
12
|
+
width?: number | null;
|
|
13
|
+
bitrate?: number | null;
|
|
14
|
+
duration?: number | null;
|
|
15
|
+
languages?: string[];
|
|
16
|
+
alternates?: Link[];
|
|
17
|
+
children?: Link[];
|
|
18
|
+
}
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
export interface Locator {
|
|
5
5
|
href: string;
|
|
6
6
|
type: string;
|
|
7
|
-
target
|
|
7
|
+
target?: number;
|
|
8
8
|
title?: string;
|
|
9
|
-
locations
|
|
10
|
-
position: number;
|
|
9
|
+
locations?: {
|
|
11
10
|
progression: number;
|
|
12
|
-
|
|
11
|
+
position?: number;
|
|
12
|
+
totalProgression?: number;
|
|
13
13
|
};
|
|
14
14
|
}
|