From 3ed5a499a223c60a086b8e7b3cebf44b5a1ef585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Mon, 5 May 2025 18:01:47 +0200 Subject: [PATCH 1/2] Fix multiple tap events broadcasted on macOS --- CHANGELOG.md | 4 +++- Sources/Internal/Measure.swift | 21 +++++++++++++++++++ .../EPUB/EPUBNavigatorViewController.swift | 9 +++++++- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 Sources/Internal/Measure.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 93d97f585..9122943af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,9 @@ All notable changes to this project will be documented in this file. Take a look #### Navigator -* Fixed the cursor shape on iPadOS when using a physical trackpad or mouse. +* Fixed several issues with the EPUB navigator cursor and pointer events. + * Fixed the cursor shape on iPadOS when using a physical trackpad or mouse. + * Fixed multiple tap events broadcasted while running on macOS. ## [3.2.0] diff --git a/Sources/Internal/Measure.swift b/Sources/Internal/Measure.swift new file mode 100644 index 000000000..04fdbf789 --- /dev/null +++ b/Sources/Internal/Measure.swift @@ -0,0 +1,21 @@ +// +// Copyright 2025 Readium Foundation. All rights reserved. +// Use of this source code is governed by the BSD-style license +// available in the top-level LICENSE file of the project. +// + +import Foundation + +/// Measures the execution time of `block`. +public func measure(_ tag: String, _ block: () -> T) -> T { + let startPoint = Date() + defer { print("⏱️ Measure \(tag): \(Date().timeIntervalSince(startPoint)) seconds") } + return block() +} + +/// Measures the execution time of `block`. +public func measure(_ tag: String, _ block: () async -> T) async -> T { + let startPoint = Date() + defer { print("⏱️ Measure \(tag): \(Date().timeIntervalSince(startPoint)) seconds") } + return await block() +} diff --git a/Sources/Navigator/EPUB/EPUBNavigatorViewController.swift b/Sources/Navigator/EPUB/EPUBNavigatorViewController.swift index 152dca293..cc5761610 100644 --- a/Sources/Navigator/EPUB/EPUBNavigatorViewController.swift +++ b/Sources/Navigator/EPUB/EPUBNavigatorViewController.swift @@ -228,8 +228,10 @@ open class EPUBNavigatorViewController: UIViewController, switch state { case .initializing, .loading, .jumping, .moving: paginationView?.isUserInteractionEnabled = false + tapGestureRecognizer.isEnabled = true case .idle: paginationView?.isUserInteractionEnabled = true + tapGestureRecognizer.isEnabled = false } } } @@ -321,6 +323,11 @@ open class EPUBNavigatorViewController: UIViewController, fatalError("init(coder:) has not been implemented") } + /// Tap gesture recognizer used to intercept taps and clicks when a web view + /// is not yet ready. + private lazy var tapGestureRecognizer: UIGestureRecognizer = + UITapGestureRecognizer(target: self, action: #selector(didTapBackground)) + override open func viewDidLoad() { super.viewDidLoad() @@ -328,7 +335,7 @@ open class EPUBNavigatorViewController: UIViewController, // the current resource. We can use this to go to the next resource. view.accessibilityTraits.insert(.causesPageTurn) - view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapBackground))) + view.addGestureRecognizer(tapGestureRecognizer) tasks.add { await initialize() From 3346ed2bc78718000c6c8136db94c47a05606f59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Mon, 5 May 2025 18:07:14 +0200 Subject: [PATCH 2/2] Update Carthage project --- Support/Carthage/.xcodegen | 5 +++++ Support/Carthage/Readium.xcodeproj/project.pbxproj | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/Support/Carthage/.xcodegen b/Support/Carthage/.xcodegen index c433a3648..49a684399 100644 --- a/Support/Carthage/.xcodegen +++ b/Support/Carthage/.xcodegen @@ -327,6 +327,7 @@ ../../Sources/Internal/Extensions/UInt64.swift ../../Sources/Internal/Extensions/URL.swift ../../Sources/Internal/JSON.swift +../../Sources/Internal/Measure.swift ../../Sources/Internal/Memoize.swift ../../Sources/Internal/UTI.swift ../../Sources/LCP @@ -441,9 +442,13 @@ ../../Sources/Navigator/EPUB/Assets/Static/scripts ../../Sources/Navigator/EPUB/Assets/Static/scripts/.gitignore ../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed-wrapper-one.js +../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed-wrapper-one.js.map ../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed-wrapper-two.js +../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed-wrapper-two.js.map ../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed.js +../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed.js.map ../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-reflowable.js +../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-reflowable.js.map ../../Sources/Navigator/EPUB/CSS ../../Sources/Navigator/EPUB/CSS/CSSLayout.swift ../../Sources/Navigator/EPUB/CSS/CSSProperties.swift diff --git a/Support/Carthage/Readium.xcodeproj/project.pbxproj b/Support/Carthage/Readium.xcodeproj/project.pbxproj index be9c67822..e5f0d5995 100644 --- a/Support/Carthage/Readium.xcodeproj/project.pbxproj +++ b/Support/Carthage/Readium.xcodeproj/project.pbxproj @@ -366,6 +366,7 @@ E75D342B54BD25242A29B105 /* Publication+EPUB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508E0CD4F9F02CC851E6D1E1 /* Publication+EPUB.swift */; }; E782980A49279BCB0C70C24C /* OPDSCopies.swift in Sources */ = {isa = PBXBuildFile; fileRef = 819D931708B3EE95CF9ADFED /* OPDSCopies.swift */; }; E8293787CB5E5CECE38A63B2 /* Encryption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54699BC0E00F327E67908F6A /* Encryption.swift */; }; + E8C3B837B9FB2ABCB5F82380 /* Measure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FEE01FAD273864D0908C358 /* Measure.swift */; }; E90B8CDCDEE4B20B3A6AB2FC /* ZIPFoundationContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A3CDE3EA555A97BBFE1EEF /* ZIPFoundationContainer.swift */; }; EBD75415CB917F57D1ACF10B /* UTI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 218BE3110D2886B252A769A2 /* UTI.swift */; }; ECCE64CDEDA32509382A8520 /* CachingResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789B56D6D8A6AA79CD3643F4 /* CachingResource.swift */; }; @@ -607,6 +608,7 @@ 4BF38F71FDEC1920325B62D3 /* PublicationContentIterator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublicationContentIterator.swift; sourceTree = ""; }; 4BF3D04FB9D6A90EE77F1F02 /* ResourceProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourceProperties.swift; sourceTree = ""; }; 4E564AE6D5137499C81FEBE2 /* TargetAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TargetAction.swift; sourceTree = ""; }; + 4FEE01FAD273864D0908C358 /* Measure.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Measure.swift; sourceTree = ""; }; 50064FE9BBCEA4C00BA6BBEF /* ZIPFoundationArchiveOpener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZIPFoundationArchiveOpener.swift; sourceTree = ""; }; 505BF8A630F7C7B96754E333 /* InMemoryPositionsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InMemoryPositionsService.swift; sourceTree = ""; }; 508E0CD4F9F02CC851E6D1E1 /* Publication+EPUB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publication+EPUB.swift"; sourceTree = ""; }; @@ -1351,6 +1353,7 @@ isa = PBXGroup; children = ( 529B55BE6996FCDC1082BF0A /* JSON.swift */, + 4FEE01FAD273864D0908C358 /* Measure.swift */, F6E45005E776078B46DB8E14 /* Memoize.swift */, 218BE3110D2886B252A769A2 /* UTI.swift */, 40D18A37080F5B1D114CE2E1 /* Extensions */, @@ -2492,6 +2495,7 @@ 330690F62A5F240B77A14337 /* Date+ISO8601.swift in Sources */, 674BEEF110667C3051296E9B /* Double.swift in Sources */, DDD0C8AC27EF8D1A893DF6CC /* JSON.swift in Sources */, + E8C3B837B9FB2ABCB5F82380 /* Measure.swift in Sources */, D6D695C1BC390F583A350E0A /* Memoize.swift in Sources */, F631EA324143E669070523F3 /* NSRegularExpression.swift in Sources */, 606EBE8AC2096BC681F92908 /* Number.swift in Sources */,