Skip to content

Commit

Permalink
Merge pull request #325 from victorsoares96/RC-1.4.6
Browse files Browse the repository at this point in the history
RC-1.4.6
  • Loading branch information
victorsoares96 authored Dec 9, 2024
2 parents b31d5d5 + aa05d4c commit 7b15838
Show file tree
Hide file tree
Showing 11 changed files with 4,926 additions and 5,208 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default function App() {
| `onReady` | `function` | Called once book has been displayed. Optional. |
| `onDisplayError` | `function` | Called once book has not been displayed. Optional. |
| `onRendered` | `function` | Emit that a section has been rendered. Optional. |
| `onChangeSection` | `function` | Called when section has been change. Optional. |
| `onResized` | `function` | Called when occurred a page change. Optional. |
| `onLocationChange` | `function` | Called when occurred a page change. Optional. |
| `onSearch` | `function` | Called once when the book has been searched. Optional. |
Expand Down Expand Up @@ -148,6 +149,7 @@ export default function App() {
| `fullsize` | `boolean` | |
| `waitForLocationsReady` | `boolean` | only render book after locations generated |
| `keepScrollOffsetOnLocationChange` | `boolean` | Prevents scroll top when change location. Works with `scrolled-doc` flow.
| `charactersPerLocation` | `number` | Default is 1600 |

## Hooks

Expand Down
10 changes: 5 additions & 5 deletions example-bare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"@react-navigation/native": "^6.1.15",
"@react-navigation/native-stack": "^6.9.24",
"@react-native-community/slider": "^4.5.2",
"expo": "~50.0.11",
"expo-document-picker": "~11.10.1",
"expo": "~51.0.0",
"expo-document-picker": "~12.0.0",
"expo-status-bar": "~1.12.0",
"react": "18.2.0",
"react-native": "0.73.6",
"react": "18.3.1",
"react-native": "0.75.2",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "^2.15.0",
"react-native-paper": "^5.12.3",
"react-native-reanimated": "~3.6.2",
"react-native-reanimated": "~3.15.0",
"react-native-safe-area-context": "^4.9.0",
"react-native-screens": "^3.29.0",
"react-native-vector-icons": "^10.0.3",
Expand Down
3,426 changes: 1,610 additions & 1,816 deletions example-bare/yarn.lock

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions example-expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@
"@react-native-community/slider": "^4.5.2",
"@react-navigation/native": "^6.1.15",
"@react-navigation/native-stack": "^6.9.24",
"expo": "^50.0.1",
"expo-document-picker": "~11.10.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.73.6",
"react": "18.3.1",
"react-dom": "18.3.1",
"expo": "^51.0.0",
"expo-document-picker": "~12.0.0",
"react-native": "0.75.2",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "~2.14.0",
"react-native-gesture-handler": "~2.18.0",
"react-native-paper": "^5.12.3",
"react-native-reanimated": "~3.6.2",
"react-native-safe-area-context": "4.8.2",
"react-native-screens": "~3.29.0",
"react-native-reanimated": "~3.15.0",
"react-native-safe-area-context": "4.10.9",
"react-native-screens": "~3.34.0",
"react-native-vector-icons": "^10.0.3",
"react-native-web": "~0.19.6",
"react-native-webview": "13.6.4",
"react-native-webview": "13.11.1",
"usehooks-ts": "^3.1.0"
},
"devDependencies": {
"@babel/core": "^7.19.3",
"@types/react": "~18.2.14",
"@types/react-native": "~0.73.0",
"@types/react": "~18.3.0",
"typescript": "^5.4.5"
},
"scripts": {
Expand Down
3,484 changes: 1,643 additions & 1,841 deletions example-expo/yarn.lock

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@
"devDependencies": {
"@react-native-community/eslint-config": "3.2.0",
"@testing-library/jest-native": "5.4.3",
"@testing-library/react-native": "12.4.5",
"@testing-library/react-native": "12.6.0",
"@types/jest": "29.5.12",
"@types/react": "~18.2.0",
"@types/react-native": "^0.73.0",
"@types/react": "~18.3.0",
"@types/react-test-renderer": "18.3.0",
"@typescript-eslint/eslint-plugin": "7.11.0",
"@typescript-eslint/parser": "7.11.0",
Expand All @@ -76,29 +75,29 @@
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jest": "^28.0.0",
"eslint-plugin-jsx-a11y": "6.8.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-react": "7.34.2",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-jsx-a11y": "6.9.0",
"eslint-plugin-react": "7.35.0",
"eslint-plugin-react-hooks": "4.6.2",
"eslint-plugin-testing-library": "6.2.2",
"husky": "9.0.11",
"jest": "29.7.0",
"lint-staged": "15.2.5",
"metro-react-native-babel-preset": "^0.77.0",
"pod-install": "0.2.2",
"prettier": "3.2.5",
"react": "18.2.0",
"react-native": "0.73.6",
"react": "18.3.1",
"react-native": "0.75.2",
"react-native-builder-bob": "0.23.2",
"react-native-gesture-handler": "^2.12.0",
"react-native-webview": "13.3.0",
"react-test-renderer": "18.2.0",
"react-native-webview": "13.11.1",
"react-test-renderer": "18.3.1",
"ts-jest": "29.1.4",
"ts-node": "10.9.2",
"typescript": "^5.4.5"
},
"resolutions": {
"@types/react": "~18.2.0"
"@types/react": "~18.3.0"
},
"peerDependencies": {
"react": "*",
Expand Down
19 changes: 12 additions & 7 deletions src/Reader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Platform } from 'react-native';
import { LoadingFile } from './utils/LoadingFile';
import type { ReaderProps } from './types';
import { View } from './View';
import { useInjectWebVieWVariables } from './hooks/useInjectWebviewVariables';
import { useInjectWebViewVariables } from './hooks/useInjectWebviewVariables';
import { ReaderContext, defaultTheme as initialTheme } from './context';
import { isURL } from './utils/isURL';
import { getSourceType } from './utils/getSourceType';
Expand Down Expand Up @@ -31,6 +31,7 @@ export function Reader({
snap,
spread,
fullsize,
charactersPerLocation,
...rest
}: ReaderProps) {
const {
Expand All @@ -46,7 +47,7 @@ export function Reader({
const allowPopups = onPressExternalLink ? true : rest.allowPopups || false;

const { setIsLoading, isLoading } = useContext(ReaderContext);
const { injectWebVieWVariables } = useInjectWebVieWVariables();
const { injectWebViewVariables } = useInjectWebViewVariables();
const [template, setTemplate] = useState<string | null>(null);
const [templateUrl, setTemplateUrl] = useState<string | null>(null);
const [allowedUris, setAllowedUris] = useState<string | null>(null);
Expand Down Expand Up @@ -86,7 +87,7 @@ export function Reader({
}
if (sourceType === SourceType.BASE64) {
setTemplate(
injectWebVieWVariables({
injectWebViewVariables({
jszip: jszipFileUri,
epubjs: epubjsFileUri,
type: SourceType.BASE64,
Expand All @@ -101,13 +102,14 @@ export function Reader({
snap,
spread,
fullsize,
charactersPerLocation,
})
);

setIsLoading(false);
} else {
setTemplate(
injectWebVieWVariables({
injectWebViewVariables({
jszip: jszipFileUri,
epubjs: epubjsFileUri,
type: SourceType.BINARY,
Expand All @@ -122,6 +124,7 @@ export function Reader({
snap,
spread,
fullsize,
charactersPerLocation,
})
);

Expand All @@ -138,7 +141,7 @@ export function Reader({

if (sourceType === SourceType.OPF || sourceType === SourceType.EPUB) {
setTemplate(
injectWebVieWVariables({
injectWebViewVariables({
jszip: jszipFileUri,
epubjs: epubjsFileUri,
type: sourceType,
Expand All @@ -153,6 +156,7 @@ export function Reader({
snap,
spread,
fullsize,
charactersPerLocation,
})
);

Expand All @@ -165,7 +169,7 @@ export function Reader({
setAllowedUris(`${bookFileUri},${jszipFileUri},${epubjsFileUri}`);

setTemplate(
injectWebVieWVariables({
injectWebViewVariables({
jszip: jszipFileUri,
epubjs: epubjsFileUri,
type: sourceType,
Expand All @@ -180,6 +184,7 @@ export function Reader({
snap,
spread,
fullsize,
charactersPerLocation,
})
);

Expand All @@ -197,7 +202,7 @@ export function Reader({
downloadFile,
enableSelection,
initialLocations,
injectWebVieWVariables,
injectWebViewVariables,
setIsLoading,
src,
// ! Causing unknown loop
Expand Down
10 changes: 8 additions & 2 deletions src/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function View({
waitForLocationsReady = false,
keepScrollOffsetOnLocationChange,
flow,
onChangeSection = () => {},
}: ViewProps) {
const {
registerBook,
Expand All @@ -98,6 +99,7 @@ export function View({
removeSelection,
setAnnotations,
setInitialAnnotations,
section,
setSection,
setToc,
setLandmarks,
Expand Down Expand Up @@ -204,6 +206,10 @@ export function View({
setProgress(progress);
setSection(currentSection);

if (section?.href !== currentSection?.href) {
onChangeSection(currentSection);
}

handleChangeIsBookmarked(bookmarks, currentLocation);

if (currentLocation.atStart) setAtStart(true);
Expand Down Expand Up @@ -270,9 +276,9 @@ export function View({
}

if (type === 'onRendered') {
const { section, currentSection } = parsedEvent;
const { currentSection } = parsedEvent;

return onRendered(section, currentSection);
return onRendered(parsedEvent.section, currentSection);
}

if (type === 'onLayout') {
Expand Down
14 changes: 10 additions & 4 deletions src/hooks/useInjectWebviewVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { Flow, Manager, Spread, Theme, ePubCfi } from '../types';
import template from '../template';
import type { SourceType } from '../utils/enums/source-type.enum';

export function useInjectWebVieWVariables() {
const injectWebVieWVariables = useCallback(
export function useInjectWebViewVariables() {
const injectWebViewVariables = useCallback(
({
jszip,
epubjs,
Expand All @@ -20,6 +20,7 @@ export function useInjectWebVieWVariables() {
snap,
spread,
fullsize,
charactersPerLocation = 1600,
}: {
jszip: string;
epubjs: string;
Expand All @@ -35,6 +36,7 @@ export function useInjectWebVieWVariables() {
snap?: boolean;
spread?: Spread;
fullsize?: boolean;
charactersPerLocation?: number;
}) => {
return template
.replace(
Expand Down Expand Up @@ -71,9 +73,13 @@ export function useInjectWebVieWVariables() {
/spread: undefined/,
`spread: ${spread ? JSON.stringify(spread) : undefined}`
)
.replace(/fullsize: undefined/, `fullsize: ${fullsize ?? undefined}`);
.replace(/fullsize: undefined/, `fullsize: ${fullsize ?? undefined}`)
.replace(
/book\.locations\.generate\(1600\)/,
`book.locations.generate(${charactersPerLocation})`
);
},
[]
);
return { injectWebVieWVariables };
return { injectWebViewVariables };
}
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,11 @@ export interface ReaderProps {
* @param {any} section
* @param {any} currentSection
* @returns {void} void
*
* @deprecated use **onChangeSection** instead
*/
onRendered?: (section: any, currentSection: any) => void;
onChangeSection?: (section: Section | null) => void;
/**
* Called when book layout is change
* @param {string} layout
Expand Down Expand Up @@ -467,4 +470,9 @@ export interface ReaderProps {
* Default is false
*/
keepScrollOffsetOnLocationChange?: boolean;

/**
* Default is 1600
*/
charactersPerLocation?: number;
}
Loading

0 comments on commit 7b15838

Please sign in to comment.