Change VoiceOver focus after jumping from table of contents

Fixes #6
This commit is contained in:
Shadowfacts 2021-06-17 23:12:28 -04:00
parent 1ce48bc77e
commit 984ecc8879
1 changed files with 12 additions and 2 deletions

View File

@ -283,11 +283,21 @@ class BrowserWebViewController: UIViewController {
let y = result * scrollView.zoomScale - scrollView.safeAreaInsets.top let y = result * scrollView.zoomScale - scrollView.safeAreaInsets.top
let maxY = scrollView.contentSize.height - scrollView.bounds.height + scrollView.safeAreaInsets.bottom let maxY = scrollView.contentSize.height - scrollView.bounds.height + scrollView.safeAreaInsets.bottom
let finalOffsetY = min(y, maxY) let finalOffsetY = min(y, maxY)
self.webView.scrollView.setContentOffset(CGPoint(x: 0, y: finalOffsetY), animated: true) UIView.animate(withDuration: 0.25, delay: 0, options: []) {
self.webView.scrollView.setContentOffset(CGPoint(x: 0, y: finalOffsetY), animated: false)
} completion: { _ in
// calling focus() causes VoiceOver to move to that element
self.webView.evaluateJavaScript("document.getElementById('l\(index)').focus();")
}
} }
} else { } else {
webView.evaluateJavaScript("document.getElementById('l\(index)').scrollIntoView();") webView.evaluateJavaScript("""
const el = document.getElementById('l\(index)');
el.scrollIntoView();
el.focus();
""")
} }
} }
private static let preamble = """ private static let preamble = """