Skip to content

Commit d2091e5

Browse files
authored
Fix multiple tap events broadcasted on macOS (#587)
1 parent 617d07f commit d2091e5

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ All notable changes to this project will be documented in this file. Take a look
1616

1717
#### Navigator
1818

19-
* Fixed the cursor shape on iPadOS when using a physical trackpad or mouse.
19+
* Fixed several issues with the EPUB navigator cursor and pointer events.
20+
* Fixed the cursor shape on iPadOS when using a physical trackpad or mouse.
21+
* Fixed multiple tap events broadcasted while running on macOS.
2022

2123

2224
## [3.2.0]

Sources/Internal/Measure.swift

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Copyright 2025 Readium Foundation. All rights reserved.
3+
// Use of this source code is governed by the BSD-style license
4+
// available in the top-level LICENSE file of the project.
5+
//
6+
7+
import Foundation
8+
9+
/// Measures the execution time of `block`.
10+
public func measure<T>(_ tag: String, _ block: () -> T) -> T {
11+
let startPoint = Date()
12+
defer { print("⏱️ Measure \(tag): \(Date().timeIntervalSince(startPoint)) seconds") }
13+
return block()
14+
}
15+
16+
/// Measures the execution time of `block`.
17+
public func measure<T>(_ tag: String, _ block: () async -> T) async -> T {
18+
let startPoint = Date()
19+
defer { print("⏱️ Measure \(tag): \(Date().timeIntervalSince(startPoint)) seconds") }
20+
return await block()
21+
}

Sources/Navigator/EPUB/EPUBNavigatorViewController.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ open class EPUBNavigatorViewController: UIViewController,
228228
switch state {
229229
case .initializing, .loading, .jumping, .moving:
230230
paginationView?.isUserInteractionEnabled = false
231+
tapGestureRecognizer.isEnabled = true
231232
case .idle:
232233
paginationView?.isUserInteractionEnabled = true
234+
tapGestureRecognizer.isEnabled = false
233235
}
234236
}
235237
}
@@ -321,14 +323,19 @@ open class EPUBNavigatorViewController: UIViewController,
321323
fatalError("init(coder:) has not been implemented")
322324
}
323325

326+
/// Tap gesture recognizer used to intercept taps and clicks when a web view
327+
/// is not yet ready.
328+
private lazy var tapGestureRecognizer: UIGestureRecognizer =
329+
UITapGestureRecognizer(target: self, action: #selector(didTapBackground))
330+
324331
override open func viewDidLoad() {
325332
super.viewDidLoad()
326333

327334
// Will call `accessibilityScroll()` when VoiceOver reaches the end of
328335
// the current resource. We can use this to go to the next resource.
329336
view.accessibilityTraits.insert(.causesPageTurn)
330337

331-
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapBackground)))
338+
view.addGestureRecognizer(tapGestureRecognizer)
332339

333340
tasks.add {
334341
await initialize()

Support/Carthage/.xcodegen

+5
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@
327327
../../Sources/Internal/Extensions/UInt64.swift
328328
../../Sources/Internal/Extensions/URL.swift
329329
../../Sources/Internal/JSON.swift
330+
../../Sources/Internal/Measure.swift
330331
../../Sources/Internal/Memoize.swift
331332
../../Sources/Internal/UTI.swift
332333
../../Sources/LCP
@@ -441,9 +442,13 @@
441442
../../Sources/Navigator/EPUB/Assets/Static/scripts
442443
../../Sources/Navigator/EPUB/Assets/Static/scripts/.gitignore
443444
../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed-wrapper-one.js
445+
../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed-wrapper-one.js.map
444446
../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed-wrapper-two.js
447+
../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed-wrapper-two.js.map
445448
../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed.js
449+
../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed.js.map
446450
../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-reflowable.js
451+
../../Sources/Navigator/EPUB/Assets/Static/scripts/readium-reflowable.js.map
447452
../../Sources/Navigator/EPUB/CSS
448453
../../Sources/Navigator/EPUB/CSS/CSSLayout.swift
449454
../../Sources/Navigator/EPUB/CSS/CSSProperties.swift

Support/Carthage/Readium.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@
366366
E75D342B54BD25242A29B105 /* Publication+EPUB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508E0CD4F9F02CC851E6D1E1 /* Publication+EPUB.swift */; };
367367
E782980A49279BCB0C70C24C /* OPDSCopies.swift in Sources */ = {isa = PBXBuildFile; fileRef = 819D931708B3EE95CF9ADFED /* OPDSCopies.swift */; };
368368
E8293787CB5E5CECE38A63B2 /* Encryption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54699BC0E00F327E67908F6A /* Encryption.swift */; };
369+
E8C3B837B9FB2ABCB5F82380 /* Measure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FEE01FAD273864D0908C358 /* Measure.swift */; };
369370
E90B8CDCDEE4B20B3A6AB2FC /* ZIPFoundationContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A3CDE3EA555A97BBFE1EEF /* ZIPFoundationContainer.swift */; };
370371
EBD75415CB917F57D1ACF10B /* UTI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 218BE3110D2886B252A769A2 /* UTI.swift */; };
371372
ECCE64CDEDA32509382A8520 /* CachingResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789B56D6D8A6AA79CD3643F4 /* CachingResource.swift */; };
@@ -607,6 +608,7 @@
607608
4BF38F71FDEC1920325B62D3 /* PublicationContentIterator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublicationContentIterator.swift; sourceTree = "<group>"; };
608609
4BF3D04FB9D6A90EE77F1F02 /* ResourceProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourceProperties.swift; sourceTree = "<group>"; };
609610
4E564AE6D5137499C81FEBE2 /* TargetAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TargetAction.swift; sourceTree = "<group>"; };
611+
4FEE01FAD273864D0908C358 /* Measure.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Measure.swift; sourceTree = "<group>"; };
610612
50064FE9BBCEA4C00BA6BBEF /* ZIPFoundationArchiveOpener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZIPFoundationArchiveOpener.swift; sourceTree = "<group>"; };
611613
505BF8A630F7C7B96754E333 /* InMemoryPositionsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InMemoryPositionsService.swift; sourceTree = "<group>"; };
612614
508E0CD4F9F02CC851E6D1E1 /* Publication+EPUB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publication+EPUB.swift"; sourceTree = "<group>"; };
@@ -1351,6 +1353,7 @@
13511353
isa = PBXGroup;
13521354
children = (
13531355
529B55BE6996FCDC1082BF0A /* JSON.swift */,
1356+
4FEE01FAD273864D0908C358 /* Measure.swift */,
13541357
F6E45005E776078B46DB8E14 /* Memoize.swift */,
13551358
218BE3110D2886B252A769A2 /* UTI.swift */,
13561359
40D18A37080F5B1D114CE2E1 /* Extensions */,
@@ -2492,6 +2495,7 @@
24922495
330690F62A5F240B77A14337 /* Date+ISO8601.swift in Sources */,
24932496
674BEEF110667C3051296E9B /* Double.swift in Sources */,
24942497
DDD0C8AC27EF8D1A893DF6CC /* JSON.swift in Sources */,
2498+
E8C3B837B9FB2ABCB5F82380 /* Measure.swift in Sources */,
24952499
D6D695C1BC390F583A350E0A /* Memoize.swift in Sources */,
24962500
F631EA324143E669070523F3 /* NSRegularExpression.swift in Sources */,
24972501
606EBE8AC2096BC681F92908 /* Number.swift in Sources */,

0 commit comments

Comments
 (0)