Skip to content

Fix multiple tap events broadcasted on macOS #587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
21 changes: 21 additions & 0 deletions Sources/Internal/Measure.swift
Original file line number Diff line number Diff line change
@@ -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<T>(_ 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<T>(_ tag: String, _ block: () async -> T) async -> T {
let startPoint = Date()
defer { print("⏱️ Measure \(tag): \(Date().timeIntervalSince(startPoint)) seconds") }
return await block()
}
9 changes: 8 additions & 1 deletion Sources/Navigator/EPUB/EPUBNavigatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -321,14 +323,19 @@ 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()

// Will call `accessibilityScroll()` when VoiceOver reaches the end of
// 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()
Expand Down
5 changes: 5 additions & 0 deletions Support/Carthage/.xcodegen
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Support/Carthage/Readium.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -607,6 +608,7 @@
4BF38F71FDEC1920325B62D3 /* PublicationContentIterator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublicationContentIterator.swift; sourceTree = "<group>"; };
4BF3D04FB9D6A90EE77F1F02 /* ResourceProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourceProperties.swift; sourceTree = "<group>"; };
4E564AE6D5137499C81FEBE2 /* TargetAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TargetAction.swift; sourceTree = "<group>"; };
4FEE01FAD273864D0908C358 /* Measure.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Measure.swift; sourceTree = "<group>"; };
50064FE9BBCEA4C00BA6BBEF /* ZIPFoundationArchiveOpener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZIPFoundationArchiveOpener.swift; sourceTree = "<group>"; };
505BF8A630F7C7B96754E333 /* InMemoryPositionsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InMemoryPositionsService.swift; sourceTree = "<group>"; };
508E0CD4F9F02CC851E6D1E1 /* Publication+EPUB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publication+EPUB.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1351,6 +1353,7 @@
isa = PBXGroup;
children = (
529B55BE6996FCDC1082BF0A /* JSON.swift */,
4FEE01FAD273864D0908C358 /* Measure.swift */,
F6E45005E776078B46DB8E14 /* Memoize.swift */,
218BE3110D2886B252A769A2 /* UTI.swift */,
40D18A37080F5B1D114CE2E1 /* Extensions */,
Expand Down Expand Up @@ -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 */,
Expand Down