From d250bf8294e133a7fd29d3eb92e68f9682f46f63 Mon Sep 17 00:00:00 2001 From: Jacob Spizziri Date: Thu, 24 Mar 2022 16:12:09 -0500 Subject: [PATCH] fix(ios): fix an issue causing crash when used in conjunction with react-native-screens --- .../reactnativereadium/MainActivity.java | 10 ++ example/ios/Podfile.lock | 11 ++- example/package.json | 3 + example/src/App.tsx | 16 ++- example/src/Reader.tsx | 2 + example/yarn.lock | 98 ++++++++++++++++++- ios/ReadiumView.swift | 11 ++- 7 files changed, 139 insertions(+), 12 deletions(-) diff --git a/example/android/app/src/main/java/com/example/reactnativereadium/MainActivity.java b/example/android/app/src/main/java/com/example/reactnativereadium/MainActivity.java index e8ed7e9..0dfee14 100644 --- a/example/android/app/src/main/java/com/example/reactnativereadium/MainActivity.java +++ b/example/android/app/src/main/java/com/example/reactnativereadium/MainActivity.java @@ -1,9 +1,19 @@ package com.example.reactnativereadium; +// https://github.com/software-mansion/react-native-screens/tree/6ad2f401061a7706af0f77186a466cb33241d680#android +import android.os.Bundle; import com.facebook.react.ReactActivity; public class MainActivity extends ReactActivity { + /** + * Per: https://github.com/software-mansion/react-native-screens/tree/6ad2f401061a7706af0f77186a466cb33241d680#android + */ + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(null); + } + /** * Returns the name of the main component registered from JavaScript. This is used to schedule * rendering of the component. diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 62b4e1a..19fc36c 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -235,7 +235,7 @@ PODS: - React-jsinspector (0.67.3) - React-logger (0.67.3): - glog - - react-native-readium (1.0.0-alpha.1): + - react-native-readium (1.0.0-alpha.3): - R2Navigator - R2Shared - R2Streamer @@ -313,6 +313,9 @@ PODS: - React-perflogger (= 0.67.3) - RNFS (2.19.0): - React-Core + - RNScreens (3.13.1): + - React-Core + - React-RCTImage - RNVectorIcons (9.1.0): - React-Core - SwiftSoup (2.3.8) @@ -358,6 +361,7 @@ DEPENDENCIES: - React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`) - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) - RNFS (from `../node_modules/react-native-fs`) + - RNScreens (from `../node_modules/react-native-screens`) - RNVectorIcons (from `../node_modules/react-native-vector-icons`) - Yoga (from `../node_modules/react-native/ReactCommon/yoga`) @@ -443,6 +447,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon" RNFS: :path: "../node_modules/react-native-fs" + RNScreens: + :path: "../node_modules/react-native-screens" RNVectorIcons: :path: "../node_modules/react-native-vector-icons" Yoga: @@ -475,7 +481,7 @@ SPEC CHECKSUMS: React-jsiexecutor: 15ea57ead631a11fad57634ff69f78e797113a39 React-jsinspector: 1e1e03345cf6d47779e2061d679d0a87d9ae73d8 React-logger: 1e10789cb84f99288479ba5f20822ce43ced6ffe - react-native-readium: e5f2936b90d43139023008d73d1274ff21c8458f + react-native-readium: 26e20c0ac97bee44e893bd1f1571afd71f86f074 react-native-safe-area-context: da2d11bd7df9bf7779e9bdc85081c141cfa544f4 React-perflogger: 93d3f142d6d9a46e635f09ba0518027215a41098 React-RCTActionSheet: 87327c3722203cc79cf79d02fb83e7332aeedd18 @@ -490,6 +496,7 @@ SPEC CHECKSUMS: React-runtimeexecutor: af1946623656f9c5fd64ca6f36f3863516193446 ReactCommon: 650e33cde4fb7d36781cd3143f5276da0abb2f96 RNFS: fc610f78fdf8bfc89a9e5cc2f898519f4dba1002 + RNScreens: 40a2cb40a02a609938137a1e0acfbf8fc9eebf19 RNVectorIcons: 7923e585eaeb139b9f4531d25a125a1500162a0b SwiftSoup: ba8ea2c91151881a298cba4b0628ef31e835a77f Yoga: 90dcd029e45d8a7c1ff059e8b3c6612ff409061a diff --git a/example/package.json b/example/package.json index 752a148..2d07733 100644 --- a/example/package.json +++ b/example/package.json @@ -12,11 +12,14 @@ "clean": "react-native-clean-project" }, "dependencies": { + "@react-navigation/native": "^6.0.8", + "@react-navigation/native-stack": "^6.5.2", "react": "17.0.2", "react-native": "0.67.3", "react-native-elements": "^3.4.2", "react-native-fs": "^2.19.0", "react-native-safe-area-context": "^4.2.2", + "react-native-screens": "^3.13.1", "react-native-vector-icons": "^9.1.0" }, "devDependencies": { diff --git a/example/src/App.tsx b/example/src/App.tsx index 9f768cc..ab0d316 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,12 +1,20 @@ import React from 'react'; -import { SafeAreaProvider } from 'react-native-safe-area-context'; +import { NavigationContainer } from '@react-navigation/native'; +import { createNativeStackNavigator } from '@react-navigation/native-stack'; +import { enableScreens } from 'react-native-screens'; + +enableScreens(false); import Reader from './Reader'; +const Stack = createNativeStackNavigator(); + export default function App() { return ( - - - + + + + + ); } diff --git a/example/src/Reader.tsx b/example/src/Reader.tsx index 1ee9ad7..fcc02e0 100644 --- a/example/src/Reader.tsx +++ b/example/src/Reader.tsx @@ -8,6 +8,7 @@ import { Appearance, } from 'react-native-readium'; import type { Locator, File } from 'react-native-readium'; +import Screens from 'react-native-screens'; const EPUB_URL = `https://test.opds.io/assets/moby/file.epub`; const EPUB_PATH = `${RNFS.DocumentDirectoryPath}/moby-dick.epub`; @@ -108,6 +109,7 @@ const Reader: React.FC = () => { location={location} settings={settings} onLocationChange={(locator) => setLocation(locator)} + WrapperView={Screens.Screen} /> diff --git a/example/yarn.lock b/example/yarn.lock index 8918966..c83e6cf 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -1206,6 +1206,47 @@ resolved "https://registry.yarnpkg.com/@react-native/polyfills/-/polyfills-2.0.0.tgz#4c40b74655c83982c8cf47530ee7dc13d957b6aa" integrity sha512-K0aGNn1TjalKj+65D7ycc1//H9roAQ51GJVk5ZJQFb2teECGmzd86bYDC0aYdbRf7gtovescq4Zt6FR0tgXiHQ== +"@react-navigation/core@^6.1.1": + version "6.1.1" + resolved "https://registry.yarnpkg.com/@react-navigation/core/-/core-6.1.1.tgz#47b01d0263e413164431c886267a5139e093c706" + integrity sha512-njysuiqztgvR1Z9Noxk2OGJfYtFGFDRyji5Vmm1jHzlql0m+q0wh1dUiyaIEtTyrhFXr/YNgdrKuiPaU9Jp8OA== + dependencies: + "@react-navigation/routers" "^6.1.0" + escape-string-regexp "^4.0.0" + nanoid "^3.1.23" + query-string "^7.0.0" + react-is "^16.13.0" + +"@react-navigation/elements@^1.3.1": + version "1.3.1" + resolved "https://registry.yarnpkg.com/@react-navigation/elements/-/elements-1.3.1.tgz#aacb08fe0ca4db50f0ed16b72906869ce770edf4" + integrity sha512-jIDRJaG8YPIinl4hZXJu/W3TnhDe8hLYmGSEdL1mxZ1aoNMiApCBYkgTy11oq0EfK/koZd3DPSkJNbzBAQmPJw== + +"@react-navigation/native-stack@^6.5.2": + version "6.5.2" + resolved "https://registry.yarnpkg.com/@react-navigation/native-stack/-/native-stack-6.5.2.tgz#1e2dd25c1d5e3664898488008b64b190583b5623" + integrity sha512-aKnjDEljGPDbL8VflCRGVJ2SPD/6x5yuAWsxd1ouCuD+43clkMnz1e0piNf+t3EpNYIWdBNR66Xa+7U/UB4y3w== + dependencies: + "@react-navigation/elements" "^1.3.1" + warn-once "^0.1.0" + +"@react-navigation/native@^6.0.8": + version "6.0.8" + resolved "https://registry.yarnpkg.com/@react-navigation/native/-/native-6.0.8.tgz#66f48ad2b3fb1acd08c8d935d9f342a3d77ee6cd" + integrity sha512-6022M3+Btok3xJC/49B88er3SRrlDAZ4FdmGndhEVvBcGSHWmscU2qKCwFd0RY6A0AGCVmdIlXudrfdcdRAkpQ== + dependencies: + "@react-navigation/core" "^6.1.1" + escape-string-regexp "^4.0.0" + fast-deep-equal "^3.1.3" + nanoid "^3.1.23" + +"@react-navigation/routers@^6.1.0": + version "6.1.0" + resolved "https://registry.yarnpkg.com/@react-navigation/routers/-/routers-6.1.0.tgz#d5682be88f1eb7809527c48f9cd3dedf4f344e40" + integrity sha512-8xJL+djIzpFdRW/sGlKojQ06fWgFk1c5jER9501HYJ12LF5DIJFr/tqBI2TJ6bk+y+QFu0nbNyeRC80OjRlmkA== + dependencies: + nanoid "^3.1.23" + "@sideway/address@^4.1.3": version "4.1.3" resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.3.tgz#d93cce5d45c5daec92ad76db492cc2ee3c64ab27" @@ -2598,6 +2639,11 @@ escape-string-regexp@^2.0.0: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz#a30304e99daa32e23b2fd20f51babd07cffca344" integrity sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w== +escape-string-regexp@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" + integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== + escodegen@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-2.0.0.tgz#5e32b12833e8aa8fa35e1bf0befa89380484c7dd" @@ -2895,7 +2941,7 @@ extglob@^2.0.4: snapdragon "^0.8.1" to-regex "^3.0.1" -fast-deep-equal@^3.1.1: +fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525" integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q== @@ -2946,6 +2992,11 @@ fill-range@^7.0.1: dependencies: to-regex-range "^5.0.1" +filter-obj@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/filter-obj/-/filter-obj-1.1.0.tgz#9b311112bc6c6127a16e016c6c5d7f19e0805c5b" + integrity sha1-mzERErxsYSehbgFsbF1/GeCAXFs= + finalhandler@1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.1.2.tgz#b7e7d000ffd11938d0fdb053506f6ebabe9f587d" @@ -4792,6 +4843,11 @@ ms@2.1.3: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== +nanoid@^3.1.23: + version "3.3.1" + resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.1.tgz#6347a18cac88af88f58af0b3594b723d5e99bb35" + integrity sha512-n6Vs/3KGyxPQd6uO0eH4Bv0ojGSUvuLlIHtC3Y0kEO23YRge8H9x1GCzLn28YX0H66pMkxuaeESFq4tKISKwdw== + nanomatch@^1.2.9: version "1.2.13" resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119" @@ -5344,6 +5400,16 @@ punycode@^2.1.0, punycode@^2.1.1: resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== +query-string@^7.0.0: + version "7.1.1" + resolved "https://registry.yarnpkg.com/query-string/-/query-string-7.1.1.tgz#754620669db978625a90f635f12617c271a088e1" + integrity sha512-MplouLRDHBZSG9z7fpuAAcI7aAYjDLhtsiVZsevsfaHWDS2IDdORKbSd1kWUA+V4zyva/HZoSfpwnYMMQDhb0w== + dependencies: + decode-uri-component "^0.2.0" + filter-obj "^1.1.0" + split-on-first "^1.0.0" + strict-uri-encode "^2.0.0" + range-parser@~1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031" @@ -5357,12 +5423,17 @@ react-devtools-core@4.19.1: shell-quote "^1.6.1" ws "^7" +react-freeze@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/react-freeze/-/react-freeze-1.0.0.tgz#b21c65fe1783743007c8c9a2952b1c8879a77354" + integrity sha512-yQaiOqDmoKqks56LN9MTgY06O0qQHgV4FUrikH357DydArSZHQhl0BJFqGKIZoTqi8JizF9Dxhuk1FIZD6qCaw== + "react-is@^16.12.0 || ^17.0.0", react-is@^17.0.1, react-is@^17.0.2: version "17.0.2" resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== -react-is@^16.13.1, react-is@^16.7.0: +react-is@^16.13.0, react-is@^16.13.1, react-is@^16.7.0: version "16.13.1" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== @@ -5415,6 +5486,14 @@ react-native-safe-area-context@^4.2.2: resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-4.2.2.tgz#e7989125bd905ae27433bd8579ed4bf90e686a38" integrity sha512-uFyUDKHNGz6RHu7UKgf7twd7GRl4RbxY0blp/gB/ZAlZCsNYLiaWW6+HlRea4Vt3wmoZHgvMmW0l6OL2naW+iQ== +react-native-screens@^3.13.1: + version "3.13.1" + resolved "https://registry.yarnpkg.com/react-native-screens/-/react-native-screens-3.13.1.tgz#b3b1c5788dca25a71668909f66d87fb35c5c5241" + integrity sha512-xcrnuUs0qUrGpc2gOTDY4VgHHADQwp80mwR1prU/Q0JqbZN5W3koLhuOsT6FkSRKjR5t40l+4LcjhHdpqRB2HA== + dependencies: + react-freeze "^1.0.0" + warn-once "^0.1.0" + react-native-size-matters@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/react-native-size-matters/-/react-native-size-matters-0.3.1.tgz#24d0cfc335a2c730f6d58bd7b43ea5a41be4b49f" @@ -6052,6 +6131,11 @@ spdx-license-ids@^3.0.0: resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.11.tgz#50c0d8c40a14ec1bf449bae69a0ea4685a9d9f95" integrity sha512-Ctl2BrFiM0X3MANYgj3CkygxhRmr9mi6xhejbdO960nF6EDJApTYpn0BQnDKlnNBULKiCN1n3w9EBkHK8ZWg+g== +split-on-first@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.1.0.tgz#f610afeee3b12bce1d0c30425e76398b78249a5f" + integrity sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw== + split-string@^3.0.1, split-string@^3.0.2: version "3.1.0" resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2" @@ -6101,6 +6185,11 @@ stream-buffers@2.2.x: resolved "https://registry.yarnpkg.com/stream-buffers/-/stream-buffers-2.2.0.tgz#91d5f5130d1cef96dcfa7f726945188741d09ee4" integrity sha1-kdX1Ew0c75bc+n9yaUUYh0HQnuQ= +strict-uri-encode@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546" + integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY= + string-length@^4.0.1: version "4.0.2" resolved "https://registry.yarnpkg.com/string-length/-/string-length-4.0.2.tgz#a8a8dc7bd5c1a82b9b3c8b87e125f66871b6e57a" @@ -6602,6 +6691,11 @@ walker@^1.0.7, walker@~1.0.5: dependencies: makeerror "1.0.12" +warn-once@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/warn-once/-/warn-once-0.1.0.tgz#4f58d89b84f968d0389176aa99e0cf0f14ffd4c8" + integrity sha512-recZTSvuaH/On5ZU5ywq66y99lImWqzP93+AiUo9LUwG8gXHW+LJjhOd6REJHm7qb0niYqrEQJvbHSQfuJtTqA== + wcwidth@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8" diff --git a/ios/ReadiumView.swift b/ios/ReadiumView.swift index 3489849..eb12669 100644 --- a/ios/ReadiumView.swift +++ b/ios/ReadiumView.swift @@ -9,6 +9,10 @@ import R2Navigator class ReadiumView : UIView, Loggable { var readerService: ReaderService = ReaderService() var readerViewController: ReaderViewController? + var viewController: UIViewController? { + let viewController = sequence(first: self, next: { $0.next }).first(where: { $0 is UIViewController }) + return viewController as? UIViewController + } private var subscriptions = Set() @objc var file: NSDictionary? = nil { @@ -138,11 +142,12 @@ class ReadiumView : UIView, Loggable { self.updateUserSettings(settings) } - let rootViewController = UIApplication.shared.delegate?.window??.rootViewController - rootViewController?.addChild(readerViewController!) readerViewController!.view.frame = self.superview!.frame + self.viewController!.addChild(readerViewController!) let rootView = self.readerViewController!.view! self.addSubview(rootView) + self.viewController!.addChild(readerViewController!) + self.readerViewController!.didMove(toParent: self.viewController!) // bind the reader's view to be constrained to its parent rootView.translatesAutoresizingMaskIntoConstraints = false @@ -150,7 +155,5 @@ class ReadiumView : UIView, Loggable { rootView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true rootView.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true rootView.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true - - self.readerViewController!.didMove(toParent: rootViewController) } }