Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #134 from readium/2.0.0-alpha.1
Browse files Browse the repository at this point in the history
2.0.0-alpha.1
  • Loading branch information
mickael-menu authored Aug 11, 2020
2 parents 7f8bd93 + 97128e6 commit ebd68fa
Show file tree
Hide file tree
Showing 14 changed files with 218 additions and 47 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [2.0.0-alpha.1]

### Added

* Support for pop-up footnotes (contributed by [@tooolbox](https://github.com/readium/r2-navigator-swift/pull/118)).
Expand All @@ -29,4 +31,4 @@ All notable changes to this project will be documented in this file.
* Touching interactive elements in fixed-layout EPUBs, when two-page spreads are enabled.

[unreleased]: https://github.com/readium/r2-navigator-swift/compare/master...HEAD
[x.x.x]: https://github.com/readium/r2-navigator-swift/compare/1.2.6...x.x.x
[2.0.0-alpha.1]: https://github.com/readium/r2-navigator-swift/compare/1.2.6...2.0.0-alpha.1
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#github "readium/r2-shared-swift" == 1.4.3
github "readium/r2-shared-swift" "2.0.0-alpha.1"
github "scinfu/SwiftSoup" == 2.3.2
3 changes: 3 additions & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
github "cezheng/Fuzi" "3.1.2"
github "dexman/Minizip" "1.4.0"
github "readium/r2-shared-swift" "c77b663dfed7e8e0d9317c7c01daaccb878bf9fb"
github "scinfu/SwiftSoup" "2.3.2"
4 changes: 2 additions & 2 deletions R2Navigator.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pod::Spec.new do |s|

s.name = "R2Navigator"
s.version = "1.2.6"
s.version = "2.0.0-alpha.1"
s.license = "BSD 3-Clause License"
s.summary = "R2 Navigator"
s.homepage = "http://readium.github.io"
s.author = { "Aferdita Muriqi" => "[email protected]" }
s.source = { :git => "https://github.com/readium/r2-navigator-swift.git", :tag => "1.2.6" }
s.source = { :git => "https://github.com/readium/r2-navigator-swift.git", :tag => "2.0.0-alpha.1" }
s.exclude_files = ["**/Info*.plist"]
s.requires_arc = true
s.resources = ['r2-navigator-swift/Resources/**', 'r2-navigator-swift/EPUB/Resources/**']
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install R2Navigator with Carthage:
2. Update your Cartfile to include the following:

```ruby
github "readium/r2-navigator-swift" ~> 1.0.6
github "readium/r2-navigator-swift" "develop"
```

3. Run `carthage update` and
Expand Down Expand Up @@ -52,7 +52,7 @@ R2Navigator with CocoaPods:
use_frameworks!
target 'YourAppTargetName' do
pod 'R2Navigator', :git => 'https://github.com/readium/r2-navigator-swift.git', '~> 1.0.6'
pod 'R2Navigator', :git => 'https://github.com/readium/r2-navigator-swift.git', :branch => 'develop'
end
```

Expand Down
17 changes: 14 additions & 3 deletions r2-navigator-swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CA90372222D8C94C00D4C86F /* fxl-spread-two.html in Resources */ = {isa = PBXBuildFile; fileRef = CA90372022D8C94C00D4C86F /* fxl-spread-two.html */; };
CA94292122BCF97700305CDB /* Static in Resources */ = {isa = PBXBuildFile; fileRef = CA94292022BCF97700305CDB /* Static */; };
CA94293022BD2D2F00305CDB /* Scripts in Resources */ = {isa = PBXBuildFile; fileRef = CA94292F22BD2D2F00305CDB /* Scripts */; };
CAAABA9B24D695E5004A4466 /* TargetAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAAABA9A24D695E5004A4466 /* TargetAction.swift */; };
CAB9086B22492D4C00711C3F /* Navigator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAB9086A22492D4C00711C3F /* Navigator.swift */; };
CAC2A6D72292E4BA000AA2A7 /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAC2A6D62292E4BA000AA2A7 /* WebView.swift */; };
CACE84F82254BE5F00E19E8B /* PDFDocumentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CACE84F72254BE5F00E19E8B /* PDFDocumentView.swift */; };
Expand All @@ -28,6 +29,7 @@
CAEACA222272EFBD00476340 /* ImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAEACA212272EFBD00476340 /* ImageViewController.swift */; };
CAF1E3F122DC98C200E807EA /* EPUBSpread.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAF1E3F022DC98C200E807EA /* EPUBSpread.swift */; };
CAF1E3F522DF23F400E807EA /* PaginationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAF1E3F422DF23F400E807EA /* PaginationView.swift */; };
CAFB017724D48FC2006B074C /* PDFTapGestureController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFB017624D48FC2006B074C /* PDFTapGestureController.swift */; };
F341C2711F506ED5005E6758 /* UserSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = F341C2701F506ED5005E6758 /* UserSettings.swift */; };
F3E7D3D41F4D83B000DF166D /* r2-navigator-swift.h in Headers */ = {isa = PBXBuildFile; fileRef = F3E7D3C61F4D83B000DF166D /* r2-navigator-swift.h */; settings = {ATTRIBUTES = (Public, ); }; };
F3E7D3E21F4D84A000DF166D /* EPUBNavigatorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3E7D3E11F4D84A000DF166D /* EPUBNavigatorViewController.swift */; };
Expand All @@ -46,6 +48,7 @@
CA90372022D8C94C00D4C86F /* fxl-spread-two.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "fxl-spread-two.html"; sourceTree = "<group>"; };
CA94292022BCF97700305CDB /* Static */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Static; sourceTree = "<group>"; };
CA94292F22BD2D2F00305CDB /* Scripts */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Scripts; sourceTree = "<group>"; };
CAAABA9A24D695E5004A4466 /* TargetAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TargetAction.swift; sourceTree = "<group>"; };
CAB9086A22492D4C00711C3F /* Navigator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Navigator.swift; sourceTree = "<group>"; };
CAC2A6D62292E4BA000AA2A7 /* WebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = "<group>"; };
CACE84F72254BE5F00E19E8B /* PDFDocumentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFDocumentView.swift; sourceTree = "<group>"; };
Expand All @@ -57,6 +60,7 @@
CAEACA212272EFBD00476340 /* ImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageViewController.swift; sourceTree = "<group>"; };
CAF1E3F022DC98C200E807EA /* EPUBSpread.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EPUBSpread.swift; sourceTree = "<group>"; };
CAF1E3F422DF23F400E807EA /* PaginationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaginationView.swift; sourceTree = "<group>"; };
CAFB017624D48FC2006B074C /* PDFTapGestureController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFTapGestureController.swift; sourceTree = "<group>"; };
F341C2701F506ED5005E6758 /* UserSettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserSettings.swift; sourceTree = "<group>"; };
F3E7D3C31F4D83B000DF166D /* R2Navigator.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = R2Navigator.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F3E7D3C61F4D83B000DF166D /* r2-navigator-swift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "r2-navigator-swift.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -85,19 +89,21 @@
children = (
CA0B3AC2222EE555006D9363 /* PDFNavigatorViewController.swift */,
CACE84F72254BE5F00E19E8B /* PDFDocumentView.swift */,
CAFB017624D48FC2006B074C /* PDFTapGestureController.swift */,
);
path = PDF;
sourceTree = "<group>";
};
CA479DC1226493390053445E /* Toolkit */ = {
isa = PBXGroup;
children = (
CA1E4F4A240037E6009C4DE3 /* CompletionList.swift */,
CAF1E3F422DF23F400E807EA /* PaginationView.swift */,
CAD178B522B3B553004E6812 /* R2NavigatorLocalizedString.swift */,
CAAABA9A24D695E5004A4466 /* TargetAction.swift */,
CA479DC2226493570053445E /* UIView.swift */,
CA479DC42264AEA20053445E /* UIColor.swift */,
CAF1E3F422DF23F400E807EA /* PaginationView.swift */,
CAC2A6D62292E4BA000AA2A7 /* WebView.swift */,
CAD178B522B3B553004E6812 /* R2NavigatorLocalizedString.swift */,
CA1E4F4A240037E6009C4DE3 /* CompletionList.swift */,
);
path = Toolkit;
sourceTree = "<group>";
Expand Down Expand Up @@ -251,6 +257,7 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = F3E7D3B91F4D83B000DF166D;
productRefGroup = F3E7D3C41F4D83B000DF166D /* Products */;
Expand Down Expand Up @@ -289,11 +296,13 @@
CAB9086B22492D4C00711C3F /* Navigator.swift in Sources */,
CA0B3AC3222EE555006D9363 /* PDFNavigatorViewController.swift in Sources */,
F3E7D3E61F4D84EF00DF166D /* EPUBSpreadView.swift in Sources */,
CAAABA9B24D695E5004A4466 /* TargetAction.swift in Sources */,
F3E7D42E1F4EE0FE00DF166D /* CBZNavigatorViewController.swift in Sources */,
CA479DC52264AEA20053445E /* UIColor.swift in Sources */,
CAD178B622B3B553004E6812 /* R2NavigatorLocalizedString.swift in Sources */,
CAEACA222272EFBD00476340 /* ImageViewController.swift in Sources */,
CACE84FB2254BFEE00E19E8B /* EditingAction.swift in Sources */,
CAFB017724D48FC2006B074C /* PDFTapGestureController.swift in Sources */,
F341C2711F506ED5005E6758 /* UserSettings.swift in Sources */,
CACE851F225CDE3400E19E8B /* EPUBFixedSpreadView.swift in Sources */,
CA479DC3226493570053445E /* UIView.swift in Sources */,
Expand Down Expand Up @@ -456,6 +465,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/iOS",
);
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
INFOPLIST_FILE = "r2-navigator-swift/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
Expand Down Expand Up @@ -485,6 +495,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/iOS",
);
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
INFOPLIST_FILE = "r2-navigator-swift/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
Expand Down
6 changes: 5 additions & 1 deletion r2-navigator-swift/CBZ/ImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ final class ImageViewController: UIViewController, Loggable {
imageView.contentMode = .scaleAspectFit
scrollView.addSubview(imageView)

// Adds an empty view before the scroll view to have a consistent behavior on all iOS versions, regarding to the content inset adjustements. Even if automaticallyAdjustsScrollViewInsets is not set to false on the navigator's parent view controller, the scroll view insets won't be adjusted if the scroll view is not the first child in the subviews hierarchy.
// Adds an empty view before the scroll view to have a consistent behavior on all iOS
// versions, regarding to the content inset adjustements. Even if
// automaticallyAdjustsScrollViewInsets is not set to false on the navigator's parent view
// controller, the scroll view insets won't be adjusted if the scroll view is not the first
// child in the subviews hierarchy.
view.insertSubview(UIView(frame: .zero), at: 0)
if #available(iOS 11.0, *) {
// Prevents the pages from jumping down when the status bar is toggled
Expand Down
34 changes: 22 additions & 12 deletions r2-navigator-swift/EPUB/EPUBNavigatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,21 +264,31 @@ open class EPUBNavigatorViewController: UIViewController, VisualNavigator, Logga
// MARK: - Navigator

public var currentLocation: Locator? {
guard let spreadView = paginationView.currentView as? EPUBSpreadView,
let href = Optional(spreadView.spread.leading.href),
let positionList = publication.positionsByResource[href],
positionList.count > 0 else
{
guard let spreadView = paginationView.currentView as? EPUBSpreadView else {
return nil
}

// Gets the current locator from the positionList, and fill its missing data.

let link = spreadView.spread.leading
let href = link.href
let progression = spreadView.progression(in: href)
let positionIndex = Int(ceil(progression * Double(positionList.count - 1)))
return positionList[positionIndex].copy(
title: tableOfContentsTitleByHref[href],
locations: { $0.progression = progression }
)

// The positions are not always available, for example a Readium WebPub doesn't have any
// unless a Publication Positions Web Service is provided.
if
let positionList = publication.positionsByResource[href],
positionList.count > 0
{
// Gets the current locator from the positionList, and fill its missing data.
let positionIndex = Int(ceil(progression * Double(positionList.count - 1)))
return positionList[positionIndex].copy(
title: tableOfContentsTitleByHref[href],
locations: { $0.progression = progression }
)
} else {
return Locator(link: link).copy(
locations: { $0.progression = progression }
)
}
}

/// Last current location notified to the delegate.
Expand Down
30 changes: 27 additions & 3 deletions r2-navigator-swift/PDF/PDFDocumentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,45 @@
import Foundation
import PDFKit


@available(iOS 11.0, *)
public final class PDFDocumentView: PDFView {

var editingActions: EditingActionsController

init(frame: CGRect, editingActions: EditingActionsController) {
self.editingActions = editingActions

super.init(frame: frame)

// For a reader, the default inset adjustement is not appropriate. Usually, we want to
// display any navigation bar above the content (to avoid it jumping when toggling the
// navigation bars), while still making sure that the content is entirely visible despite
// the screen notches.
// Thefore, we will handle the adjustement manually by only taking the notch area into
// account.
firstScrollView?.contentInsetAdjustmentBehavior = .never
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

public override func safeAreaInsetsDidChange() {
super.safeAreaInsetsDidChange()
updateContentInset()
}

public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
updateContentInset()
}

private func updateContentInset() {
// Setting the horizontal values triggers shifts the content incorrectly, somehow.
firstScrollView?.contentInset.top = notchAreaInsets.top
firstScrollView?.contentInset.bottom = notchAreaInsets.bottom
}

public override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
return super.canPerformAction(action, withSender: sender) && editingActions.canPerformAction(action)
}
Expand Down
26 changes: 11 additions & 15 deletions r2-navigator-swift/PDF/PDFNavigatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ open class PDFNavigatorViewController: UIViewController, VisualNavigator, Loggab
private let editingActions: EditingActionsController
/// Reading order index of the current resource.
private var currentResourceIndex: Int?

// Holds a reference to make sure it is not garbage-collected.
private var tapGestureController: PDFTapGestureController?

public init(publication: Publication, license: DRMLicense? = nil, initialLocation: Locator? = nil, editingActions: [EditingAction] = EditingAction.defaultActions) {
self.publication = publication
Expand All @@ -45,7 +48,6 @@ open class PDFNavigatorViewController: UIViewController, VisualNavigator, Loggab

super.init(nibName: nil, bundle: nil)

automaticallyAdjustsScrollViewInsets = false
self.editingActions.delegate = self
}

Expand All @@ -62,16 +64,13 @@ open class PDFNavigatorViewController: UIViewController, VisualNavigator, Loggab

view.backgroundColor = .black

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTap))
tapGesture.numberOfTapsRequired = 1
tapGesture.delegate = self
view.addGestureRecognizer(tapGesture)

pdfView = PDFDocumentView(frame: view.bounds, editingActions: editingActions)
pdfView.delegate = self
pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(pdfView)

tapGestureController = PDFTapGestureController(pdfView: pdfView, target: self, action: #selector(didTap))

setupPDFView()

NotificationCenter.default.addObserver(self, selector: #selector(pageDidChange), name: .PDFViewPageChanged, object: pdfView)
Expand Down Expand Up @@ -308,9 +307,15 @@ extension PDFNavigatorViewController: PDFViewDelegate {

public func pdfViewWillClick(onLink sender: PDFView, with url: URL) {
log(.debug, "Click URL: \(url)")

let url = url.addingSchemeIfMissing("http")
delegate?.navigator(self, presentExternalURL: url)
}

public func pdfViewParentViewController() -> UIViewController {
return self
}

}

@available(iOS 11.0, *)
Expand All @@ -321,12 +326,3 @@ extension PDFNavigatorViewController: EditingActionsControllerDelegate {
}

}

@available(iOS 11.0, *)
extension PDFNavigatorViewController: UIGestureRecognizerDelegate {

public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}

}
73 changes: 73 additions & 0 deletions r2-navigator-swift/PDF/PDFTapGestureController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// PDFTapGestureController.swift
// r2-navigator-swift
//
// Created by Mickaël Menu on 31/07/2020.
//
// Copyright 2020 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import Foundation
import UIKit
import PDFKit

/// Since iOS 13, the way to add a properly functioning tap gesture recognizer on a `PDFView`
/// significantly changed. This class handles the setup depending on the current iOS version.
@available(iOS 11.0, *)
final class PDFTapGestureController: NSObject {

private let pdfView: PDFView
private let tapAction: TargetAction
private var tapRecognizer: UITapGestureRecognizer!

init(pdfView: PDFView, target: Any, action: Selector) {
assert(pdfView.superview != nil, "The PDFView must be in the view hierarchy")

self.pdfView = pdfView
self.tapAction = TargetAction(target: target, action: action)

super.init()

self.tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(didTap))

if #available(iOS 13.0, *) {
// If we add the gesture on the superview on iOS 13, then it will be triggered when
// taping a link.
// The delegate will be used to make sure that this recognizer has a lower precedence
// over the default tap recognizer of the `PDFView`, which is used to handle links.
tapRecognizer.delegate = self
pdfView.addGestureRecognizer(tapRecognizer)

} else {
// Before iOS 13, the gesture must be on the superview to prevent conflicts.
pdfView.superview?.addGestureRecognizer(tapRecognizer)
}
}

@objc private func didTap(_ gesture: UITapGestureRecognizer) {
// On iOS 13, the tap to clear text selection is broken by adding the tap recognizer, so
// we clear it manually.
guard pdfView.currentSelection == nil else {
pdfView.clearSelection()
return
}

self.tapAction.invoke(from: gesture)
}

}

@available(iOS 11.0, *)
extension PDFTapGestureController: UIGestureRecognizerDelegate {

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return (otherGestureRecognizer as? UITapGestureRecognizer)?.numberOfTouchesRequired == 1
}

}
Loading

0 comments on commit ebd68fa

Please sign in to comment.