-
Notifications
You must be signed in to change notification settings - Fork 120
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
add findElementLocator
#273
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,24 @@ export function findFirstVisibleLocator() { | |
}; | ||
} | ||
|
||
export function findLocatorAtPoint(x, y) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind refactoring to avoid the code duplication with |
||
const element = document.elementFromPoint(x, y); | ||
if (!element) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
href: "#", | ||
type: "application/xhtml+xml", | ||
locations: { | ||
cssSelector: getCssSelector(element), | ||
}, | ||
text: { | ||
highlight: element.textContent, | ||
}, | ||
}; | ||
} | ||
|
||
function findElement(rootElement) { | ||
var foundElement = undefined; | ||
for (var i = rootElement.children.length - 1; i >= 0; i--) { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -31,6 +31,9 @@ public protocol VisualNavigator: Navigator { | |||||||||
|
||||||||||
/// Returns the `Locator` to the first content element that begins on the current screen. | ||||||||||
func firstVisibleElementLocator(completion: @escaping (Locator?) -> Void) | ||||||||||
|
||||||||||
/// Returns the `Locator` to the first content element located at the given point | ||||||||||
func elementLocator(at point: CGPoint, completion: @escaping (Locator?) -> Void) | ||||||||||
Comment on lines
+35
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest renaming
Suggested change
|
||||||||||
} | ||||||||||
|
||||||||||
public extension VisualNavigator { | ||||||||||
|
@@ -40,6 +43,12 @@ public extension VisualNavigator { | |||||||||
completion(currentLocation) | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
func elementLocator(at point: CGPoint, completion: @escaping (Locator?) -> Void) { | ||||||||||
DispatchQueue.main.async { | ||||||||||
completion(currentLocation) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize you reused the default logic from When an app calls Apps can still fallback on |
||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
@discardableResult | ||||||||||
func goLeft(animated: Bool = false, completion: @escaping () -> Void = {}) -> Bool { | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is useful stuff but also easy to get it wrong, depending on the iOS version or FXL vs reflowable layouts.
Maybe we could add an equivalent to these two APIs but in the other direction (
fromNavigatorSpace
)?swift-toolkit/Sources/Navigator/EPUB/EPUBSpreadView.swift
Lines 216 to 226 in 4f082ee
For inspiration, here's the reflowable implementation:
swift-toolkit/Sources/Navigator/EPUB/EPUBReflowableSpreadView.swift
Lines 133 to 158 in 4f082ee
and the FXL implementation:
swift-toolkit/Sources/Navigator/EPUB/EPUBFixedSpreadView.swift
Lines 100 to 115 in 4f082ee