react-native-readium 3.0.0 → 3.0.2
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 +2 -0
- package/android/src/main/java/com/reactnativereadium/ReadiumViewManager.kt +4 -2
- package/lib/src/components/BaseReadiumView.js +1 -1
- package/lib/src/components/ReadiumView.js +4 -4
- package/lib/src/components/ReadiumView.web.js +8 -8
- package/lib/src/interfaces/Settings.js +6 -6
- package/lib/src/utils/getWidthOrHeightValue.js +3 -1
- package/lib/web/hooks/useReaderRef.js +6 -6
- package/lib/web/hooks/useSettingsObserver.js +1 -4
- package/package.json +3 -2
- package/src/components/BaseReadiumView.tsx +1 -4
- package/src/components/BaseReadiumView.web.tsx +1 -1
- package/src/components/ReadiumView.tsx +86 -63
- package/src/components/ReadiumView.web.tsx +55 -51
- package/src/interfaces/File.ts +0 -1
- package/src/interfaces/Settings.ts +6 -16
- package/src/utils/RANGES.ts +5 -5
- package/src/utils/clamp.ts +1 -1
- package/src/utils/createFragment.ts +2 -2
- package/src/utils/getWidthOrHeightValue.ts +4 -2
- package/src/utils/indexOfObjectValue.ts +1 -1
- package/web/hooks/useLocationObserver.ts +1 -1
- package/web/hooks/useReaderRef.ts +8 -9
- package/web/hooks/useSettingsObserver.ts +2 -5
package/README.md
CHANGED
|
@@ -53,6 +53,8 @@ allows you to do things like:
|
|
|
53
53
|
1. **iOS**: Requires an iOS target >= `13.0` (see the iOS section for more details).
|
|
54
54
|
2. **Android**: Requires `compileSdkVersion` >= `31` (see the Android section for more details).
|
|
55
55
|
|
|
56
|
+
:warning: This library does not current support `newArch`. Please disable `newArch` if you intend to use it. PR's welcome.
|
|
57
|
+
|
|
56
58
|
#### Install Module
|
|
57
59
|
|
|
58
60
|
**NPM**
|
|
@@ -82,7 +82,7 @@ class ReadiumViewManager(
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
fun locationToLinkOrLocator(location: ReadableMap): LinkOrLocator? {
|
|
85
|
-
val json = JSONObject(location.toHashMap())
|
|
85
|
+
val json = JSONObject(location.toHashMap() as HashMap<*, *>)
|
|
86
86
|
val hasLocations = json.has("locations")
|
|
87
87
|
val hasChildren = json.has("children")
|
|
88
88
|
val hasHashHref = (json.get("href") as String).contains("#")
|
|
@@ -114,7 +114,9 @@ class ReadiumViewManager(
|
|
|
114
114
|
|
|
115
115
|
@ReactProp(name = "settings")
|
|
116
116
|
fun setSettings(view: ReadiumView, settings: ReadableMap) {
|
|
117
|
-
|
|
117
|
+
val map = mutableMapOf<String, Any>()
|
|
118
|
+
settings.toHashMap().forEach { (key, value) -> if (value != null) map[key] = value }
|
|
119
|
+
view.updateSettingsFromMap(map)
|
|
118
120
|
}
|
|
119
121
|
|
|
120
122
|
@ReactPropGroup(names = ["width", "height"], customType = "Style")
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { requireNativeComponent, UIManager
|
|
1
|
+
import { requireNativeComponent, UIManager } from 'react-native';
|
|
2
2
|
import { COMPONENT_NAME, LINKING_ERROR } from '../utils';
|
|
3
3
|
export const BaseReadiumView = UIManager.getViewManagerConfig(COMPONENT_NAME) != null
|
|
4
4
|
? requireNativeComponent(COMPONENT_NAME)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback, useState, useEffect, forwardRef, useRef } from 'react';
|
|
1
|
+
import React, { useCallback, useState, useEffect, forwardRef, useRef, } from 'react';
|
|
2
2
|
import { View, Platform, findNodeHandle, StyleSheet } from 'react-native';
|
|
3
3
|
import { Settings } from '../interfaces';
|
|
4
4
|
import { createFragment, getWidthOrHeightValue as dimension } from '../utils';
|
|
@@ -10,7 +10,7 @@ export const ReadiumView = forwardRef(({ onLocationChange: wrappedOnLocationChan
|
|
|
10
10
|
height: 0,
|
|
11
11
|
});
|
|
12
12
|
// set the view dimensions on layout
|
|
13
|
-
const onLayout = useCallback(({ nativeEvent: { layout: { width, height } } }) => {
|
|
13
|
+
const onLayout = useCallback(({ nativeEvent: { layout: { width, height }, }, }) => {
|
|
14
14
|
setDimensions({
|
|
15
15
|
width: dimension(width),
|
|
16
16
|
height: dimension(height),
|
|
@@ -45,8 +45,8 @@ export const ReadiumView = forwardRef(({ onLocationChange: wrappedOnLocationChan
|
|
|
45
45
|
}
|
|
46
46
|
}, [defaultRef.current !== null]);
|
|
47
47
|
return (<View style={styles.container} onLayout={onLayout}>
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
<BaseReadiumView height={height} width={width} {...props} onLocationChange={onLocationChange} onTableOfContents={onTableOfContents} settings={unmappedSettings ? Settings.map(unmappedSettings) : undefined} ref={defaultRef}/>
|
|
49
|
+
</View>);
|
|
50
50
|
});
|
|
51
51
|
const styles = StyleSheet.create({
|
|
52
52
|
container: { width: '100%', height: '100%' },
|
|
@@ -27,14 +27,14 @@ export const ReadiumView = React.forwardRef(({ file, settings, location, onLocat
|
|
|
27
27
|
if (width)
|
|
28
28
|
mainStyle.width = width;
|
|
29
29
|
return (<View style={styles.container}>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
{!reader && <div style={loaderStyle}>Loading reader...</div>}
|
|
31
|
+
<div id="D2Reader-Container" style={styles.d2Container}>
|
|
32
|
+
<main style={mainStyle} tabIndex={-1} id="iframe-wrapper">
|
|
33
|
+
<div id="reader-loading" className="loading" style={loaderStyle}/>
|
|
34
|
+
<div id="reader-error" className="error"/>
|
|
35
|
+
</main>
|
|
36
|
+
</div>
|
|
37
|
+
</View>);
|
|
38
38
|
});
|
|
39
39
|
const loaderStyle = {
|
|
40
40
|
width: '100%',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Appearance, FontFamily, TextAlignment, ColumnCount
|
|
2
|
-
import { RANGES, indexOfObjectValue, clamp
|
|
1
|
+
import { Appearance, FontFamily, TextAlignment, ColumnCount } from '../enums';
|
|
2
|
+
import { RANGES, indexOfObjectValue, clamp } from '../utils';
|
|
3
3
|
/**
|
|
4
4
|
* A reader settings object with sensible defaults.
|
|
5
5
|
*/
|
|
@@ -43,10 +43,10 @@ export class Settings {
|
|
|
43
43
|
static map(settings) {
|
|
44
44
|
const defaultValues = new Settings();
|
|
45
45
|
const mapped = {};
|
|
46
|
-
Object.keys(defaultValues)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
Object.keys(defaultValues).forEach((key) => {
|
|
47
|
+
mapped[key] =
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
settings[key] !== undefined ? settings[key] : defaultValues[key];
|
|
50
50
|
});
|
|
51
51
|
mapped.appearance = indexOfObjectValue(Appearance, mapped.appearance);
|
|
52
52
|
mapped.fontFamily = indexOfObjectValue(FontFamily, mapped.fontFamily);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Platform, PixelRatio } from 'react-native';
|
|
2
2
|
export const getWidthOrHeightValue = (val) => {
|
|
3
|
-
return Platform.OS === 'android'
|
|
3
|
+
return Platform.OS === 'android'
|
|
4
|
+
? PixelRatio.getPixelSizeForLayoutSize(val)
|
|
5
|
+
: val;
|
|
4
6
|
};
|
|
@@ -68,18 +68,18 @@ export const useReaderRef = ({ file, onLocationChange, onTableOfContents, }) =>
|
|
|
68
68
|
// consider bundling them with the library.
|
|
69
69
|
const injectables = [
|
|
70
70
|
{
|
|
71
|
-
type:
|
|
72
|
-
url:
|
|
71
|
+
type: 'style',
|
|
72
|
+
url: 'https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-before.css',
|
|
73
73
|
r2before: true,
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
|
-
type:
|
|
77
|
-
url:
|
|
76
|
+
type: 'style',
|
|
77
|
+
url: 'https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-default.css',
|
|
78
78
|
r2default: true,
|
|
79
79
|
},
|
|
80
80
|
{
|
|
81
|
-
type:
|
|
82
|
-
url:
|
|
81
|
+
type: 'style',
|
|
82
|
+
url: 'https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-after.css',
|
|
83
83
|
r2after: true,
|
|
84
84
|
},
|
|
85
85
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-readium",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "A react-native wrapper for https://readium.org/",
|
|
5
5
|
"main": "lib/src/index",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"scripts": {
|
|
25
25
|
"test": "jest",
|
|
26
26
|
"typescript": "tsc --noEmit",
|
|
27
|
-
"lint": "eslint \"
|
|
27
|
+
"lint": "eslint \"./src/**/*.{js,ts,tsx}\"",
|
|
28
|
+
"lint:fix": "eslint ./src --fix",
|
|
28
29
|
"prepare": "rimraf lib && tsc",
|
|
29
30
|
"release": "release-it",
|
|
30
31
|
"example": "yarn --cwd example",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const BaseReadiumView = () => null
|
|
1
|
+
export const BaseReadiumView = () => null;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
useCallback,
|
|
3
|
+
useState,
|
|
4
|
+
useEffect,
|
|
5
|
+
forwardRef,
|
|
6
|
+
useRef,
|
|
7
|
+
} from 'react';
|
|
2
8
|
import { View, Platform, findNodeHandle, StyleSheet } from 'react-native';
|
|
3
9
|
|
|
4
10
|
import type { BaseReadiumViewProps, Dimensions } from '../interfaces';
|
|
@@ -8,74 +14,91 @@ import { BaseReadiumView } from './BaseReadiumView';
|
|
|
8
14
|
|
|
9
15
|
export type ReadiumProps = BaseReadiumViewProps;
|
|
10
16
|
|
|
11
|
-
export const ReadiumView: React.FC<ReadiumProps> = forwardRef(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
setDimensions({
|
|
26
|
-
width: dimension(width),
|
|
27
|
-
height: dimension(height),
|
|
17
|
+
export const ReadiumView: React.FC<ReadiumProps> = forwardRef(
|
|
18
|
+
(
|
|
19
|
+
{
|
|
20
|
+
onLocationChange: wrappedOnLocationChange,
|
|
21
|
+
onTableOfContents: wrappedOnTableOfContents,
|
|
22
|
+
settings: unmappedSettings,
|
|
23
|
+
...props
|
|
24
|
+
},
|
|
25
|
+
forwardedRef
|
|
26
|
+
) => {
|
|
27
|
+
const defaultRef = useRef<any>(null);
|
|
28
|
+
const [{ height, width }, setDimensions] = useState<Dimensions>({
|
|
29
|
+
width: 0,
|
|
30
|
+
height: 0,
|
|
28
31
|
});
|
|
29
|
-
}, []);
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
// set the view dimensions on layout
|
|
34
|
+
const onLayout = useCallback(
|
|
35
|
+
({
|
|
36
|
+
nativeEvent: {
|
|
37
|
+
layout: { width, height },
|
|
38
|
+
},
|
|
39
|
+
}: any) => {
|
|
40
|
+
setDimensions({
|
|
41
|
+
width: dimension(width),
|
|
42
|
+
height: dimension(height),
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
[]
|
|
46
|
+
);
|
|
37
47
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
// wrap the native onLocationChange and extract the raw event value
|
|
49
|
+
const onLocationChange = useCallback(
|
|
50
|
+
(event: any) => {
|
|
51
|
+
if (wrappedOnLocationChange) {
|
|
52
|
+
wrappedOnLocationChange(event.nativeEvent);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
[wrappedOnLocationChange]
|
|
56
|
+
);
|
|
44
57
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
const onTableOfContents = useCallback(
|
|
59
|
+
(event: any) => {
|
|
60
|
+
if (wrappedOnTableOfContents) {
|
|
61
|
+
const toc = event.nativeEvent.toc || null;
|
|
62
|
+
wrappedOnTableOfContents(toc);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
[wrappedOnTableOfContents]
|
|
66
|
+
);
|
|
52
67
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
}, [defaultRef.current !== null])
|
|
68
|
+
// create the view fragment on android
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (Platform.OS === 'android' && defaultRef.current) {
|
|
71
|
+
const viewId = findNodeHandle(defaultRef.current);
|
|
72
|
+
createFragment(viewId);
|
|
73
|
+
}
|
|
74
|
+
}, []);
|
|
61
75
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
76
|
+
// assign the forwarded ref
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (forwardedRef && 'current' in forwardedRef) {
|
|
79
|
+
forwardedRef.current = defaultRef.current;
|
|
80
|
+
} else if (forwardedRef) {
|
|
81
|
+
forwardedRef(defaultRef);
|
|
82
|
+
}
|
|
83
|
+
}, [defaultRef.current !== null]);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<View style={styles.container} onLayout={onLayout}>
|
|
87
|
+
<BaseReadiumView
|
|
88
|
+
height={height}
|
|
89
|
+
width={width}
|
|
90
|
+
{...props}
|
|
91
|
+
onLocationChange={onLocationChange}
|
|
92
|
+
onTableOfContents={onTableOfContents}
|
|
93
|
+
settings={
|
|
94
|
+
unmappedSettings ? Settings.map(unmappedSettings) : undefined
|
|
95
|
+
}
|
|
96
|
+
ref={defaultRef}
|
|
97
|
+
/>
|
|
98
|
+
</View>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
);
|
|
79
102
|
|
|
80
103
|
const styles = StyleSheet.create({
|
|
81
104
|
container: { width: '100%', height: '100%' },
|
|
@@ -9,62 +9,66 @@ import {
|
|
|
9
9
|
useLocationObserver,
|
|
10
10
|
} from '../../web/hooks';
|
|
11
11
|
|
|
12
|
-
export const ReadiumView = React.forwardRef<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
const reader = readerRef.current;
|
|
31
|
-
|
|
32
|
-
useImperativeHandle(ref, () => ({
|
|
33
|
-
nextPage: () => {
|
|
34
|
-
readerRef.current?.nextPage();
|
|
35
|
-
},
|
|
36
|
-
prevPage: () => {
|
|
37
|
-
readerRef.current?.previousPage();
|
|
12
|
+
export const ReadiumView = React.forwardRef<
|
|
13
|
+
{
|
|
14
|
+
nextPage: () => void;
|
|
15
|
+
prevPage: () => void;
|
|
16
|
+
},
|
|
17
|
+
ReadiumProps
|
|
18
|
+
>(
|
|
19
|
+
(
|
|
20
|
+
{
|
|
21
|
+
file,
|
|
22
|
+
settings,
|
|
23
|
+
location,
|
|
24
|
+
onLocationChange,
|
|
25
|
+
onTableOfContents,
|
|
26
|
+
style = {},
|
|
27
|
+
height,
|
|
28
|
+
width,
|
|
38
29
|
},
|
|
39
|
-
|
|
30
|
+
ref
|
|
31
|
+
) => {
|
|
32
|
+
const readerRef = useReaderRef({
|
|
33
|
+
file,
|
|
34
|
+
onLocationChange,
|
|
35
|
+
onTableOfContents,
|
|
36
|
+
});
|
|
37
|
+
const reader = readerRef.current;
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
useImperativeHandle(ref, () => ({
|
|
40
|
+
nextPage: () => {
|
|
41
|
+
readerRef.current?.nextPage();
|
|
42
|
+
},
|
|
43
|
+
prevPage: () => {
|
|
44
|
+
readerRef.current?.previousPage();
|
|
45
|
+
},
|
|
46
|
+
}));
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
...(style as CSSProperties),
|
|
47
|
-
};
|
|
48
|
+
useSettingsObserver(reader, settings);
|
|
49
|
+
useLocationObserver(reader, location);
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
const mainStyle = {
|
|
52
|
+
...styles.maximize,
|
|
53
|
+
...(style as CSSProperties),
|
|
54
|
+
};
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
id="iframe-wrapper"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
</
|
|
64
|
-
</
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
if (height) mainStyle.height = height;
|
|
57
|
+
if (width) mainStyle.width = width;
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<View style={styles.container}>
|
|
61
|
+
{!reader && <div style={loaderStyle}>Loading reader...</div>}
|
|
62
|
+
<div id="D2Reader-Container" style={styles.d2Container}>
|
|
63
|
+
<main style={mainStyle} tabIndex={-1} id="iframe-wrapper">
|
|
64
|
+
<div id="reader-loading" className="loading" style={loaderStyle} />
|
|
65
|
+
<div id="reader-error" className="error" />
|
|
66
|
+
</main>
|
|
67
|
+
</div>
|
|
68
|
+
</View>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
);
|
|
68
72
|
|
|
69
73
|
const loaderStyle: React.CSSProperties = {
|
|
70
74
|
width: '100%',
|
package/src/interfaces/File.ts
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Appearance,
|
|
3
|
-
FontFamily,
|
|
4
|
-
TextAlignment,
|
|
5
|
-
ColumnCount,
|
|
6
|
-
} from '../enums';
|
|
1
|
+
import { Appearance, FontFamily, TextAlignment, ColumnCount } from '../enums';
|
|
7
2
|
|
|
8
|
-
import {
|
|
9
|
-
RANGES,
|
|
10
|
-
indexOfObjectValue,
|
|
11
|
-
clamp,
|
|
12
|
-
} from '../utils';
|
|
3
|
+
import { RANGES, indexOfObjectValue, clamp } from '../utils';
|
|
13
4
|
|
|
14
5
|
/**
|
|
15
6
|
* A reader settings object with sensible defaults.
|
|
@@ -63,12 +54,11 @@ export class Settings {
|
|
|
63
54
|
const defaultValues = new Settings();
|
|
64
55
|
const mapped: Record<string, any> = {};
|
|
65
56
|
|
|
66
|
-
Object.keys(defaultValues)
|
|
67
|
-
|
|
57
|
+
Object.keys(defaultValues).forEach((key: string) => {
|
|
58
|
+
mapped[key] =
|
|
68
59
|
// @ts-ignore
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
;
|
|
60
|
+
settings[key] !== undefined ? settings[key] : defaultValues[key];
|
|
61
|
+
});
|
|
72
62
|
|
|
73
63
|
mapped.appearance = indexOfObjectValue(Appearance, mapped.appearance);
|
|
74
64
|
mapped.fontFamily = indexOfObjectValue(FontFamily, mapped.fontFamily);
|
package/src/utils/RANGES.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export const RANGES = {
|
|
2
|
-
fontSize:
|
|
3
|
-
wordSpacing:
|
|
4
|
-
letterSpacing:
|
|
5
|
-
pageMargins:
|
|
6
|
-
lineHeight:
|
|
2
|
+
fontSize: [100.0, 300.0],
|
|
3
|
+
wordSpacing: [0.0, 0.5],
|
|
4
|
+
letterSpacing: [0.0, 0.5],
|
|
5
|
+
pageMargins: [0.5, 4.0],
|
|
6
|
+
lineHeight: [1.0, 2.0],
|
|
7
7
|
paragraphMargins: [0.0, 2.0],
|
|
8
8
|
};
|
package/src/utils/clamp.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Platform, PixelRatio } from 'react-native';
|
|
2
2
|
|
|
3
3
|
export const getWidthOrHeightValue = (val: number) => {
|
|
4
|
-
return Platform.OS === 'android'
|
|
5
|
-
|
|
4
|
+
return Platform.OS === 'android'
|
|
5
|
+
? PixelRatio.getPixelSizeForLayoutSize(val)
|
|
6
|
+
: val;
|
|
7
|
+
};
|
|
@@ -4,7 +4,7 @@ import type { Link, Locator } from '../../src/interfaces';
|
|
|
4
4
|
|
|
5
5
|
export const useLocationObserver = (
|
|
6
6
|
reader?: D2Reader | null,
|
|
7
|
-
location?: Link | Locator | null
|
|
7
|
+
location?: Link | Locator | null
|
|
8
8
|
) => {
|
|
9
9
|
useDeepCompareEffect(() => {
|
|
10
10
|
if (reader && location) {
|
|
@@ -7,7 +7,7 @@ export const useReaderRef = ({
|
|
|
7
7
|
file,
|
|
8
8
|
onLocationChange,
|
|
9
9
|
onTableOfContents,
|
|
10
|
-
}: Pick<ReadiumProps, 'file' | 'onLocationChange' | 'onTableOfContents'
|
|
10
|
+
}: Pick<ReadiumProps, 'file' | 'onLocationChange' | 'onTableOfContents'>) => {
|
|
11
11
|
const readerRef = useRef<D2Reader | null>(null);
|
|
12
12
|
const readingOrder = useRef<Locator[]>([]);
|
|
13
13
|
|
|
@@ -84,7 +84,7 @@ export const useReaderRef = ({
|
|
|
84
84
|
run();
|
|
85
85
|
}, [file.url]);
|
|
86
86
|
|
|
87
|
-
return readerRef
|
|
87
|
+
return readerRef;
|
|
88
88
|
};
|
|
89
89
|
|
|
90
90
|
// NOTE: right now we're serving these through statically.io, which is just
|
|
@@ -92,19 +92,18 @@ export const useReaderRef = ({
|
|
|
92
92
|
// consider bundling them with the library.
|
|
93
93
|
const injectables: any[] = [
|
|
94
94
|
{
|
|
95
|
-
type:
|
|
96
|
-
url:
|
|
95
|
+
type: 'style',
|
|
96
|
+
url: 'https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-before.css',
|
|
97
97
|
r2before: true,
|
|
98
98
|
},
|
|
99
99
|
{
|
|
100
|
-
type:
|
|
101
|
-
url:
|
|
100
|
+
type: 'style',
|
|
101
|
+
url: 'https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-default.css',
|
|
102
102
|
r2default: true,
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
|
-
type:
|
|
106
|
-
url:
|
|
105
|
+
type: 'style',
|
|
106
|
+
url: 'https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-after.css',
|
|
107
107
|
r2after: true,
|
|
108
108
|
},
|
|
109
109
|
];
|
|
110
|
-
|
|
@@ -4,7 +4,7 @@ import type { Settings } from '../../src/interfaces';
|
|
|
4
4
|
|
|
5
5
|
export const useSettingsObserver = (
|
|
6
6
|
reader?: D2Reader | null,
|
|
7
|
-
settings?: Partial<Settings> | null
|
|
7
|
+
settings?: Partial<Settings> | null
|
|
8
8
|
) => {
|
|
9
9
|
useDeepCompareEffect(() => {
|
|
10
10
|
if (reader && settings) {
|
|
@@ -12,8 +12,5 @@ export const useSettingsObserver = (
|
|
|
12
12
|
// are equivalent or not
|
|
13
13
|
reader?.applyUserSettings(settings as Partial<D2UserSettings>);
|
|
14
14
|
}
|
|
15
|
-
}, [
|
|
16
|
-
settings,
|
|
17
|
-
!!reader,
|
|
18
|
-
]);
|
|
15
|
+
}, [settings, !!reader]);
|
|
19
16
|
};
|