Skip to content
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
17 changes: 17 additions & 0 deletions App/Resources/RenderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,23 @@ Awful.setShowAvatars = function(showAvatars) {
};


/**
Toggles aria-hidden on post metadata so iOS Spoken Content / VoiceOver skips usernames, regdates, and post dates.

@param {boolean} hide - `true` to mark the post header and post date as aria-hidden, `false` to restore them.
*/
Awful.setHidePostMetadataForReader = function(hide) {
var els = document.querySelectorAll('post > header, post > footer');
Array.prototype.forEach.call(els, function(el) {
if (hide) {
el.setAttribute('aria-hidden', 'true');
} else {
el.removeAttribute('aria-hidden');
}
});
};


/**
Updates the stylesheet for the currently-selected theme.

Expand Down
3 changes: 2 additions & 1 deletion App/Templates/Post.html.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<header
class="userid-{{ author.userID|htmlEscape }} {% if customTitleHTML %} responsive {% endif %}"
{% if hideMetadataForReader %} aria-hidden="true" {% endif %}
{% if hiddenAvatarURL %} data-awful-avatar="{{ hiddenAvatarURL|htmlEscape }}" {% endif %}>

{% if visibleAvatarURL and not customTitleHTML %}
Expand Down Expand Up @@ -42,7 +43,7 @@
{{ htmlContents }}
</section>

<footer>
<footer {% if hideMetadataForReader %} aria-hidden="true" {% endif %}>
<span class="divider{% if beenSeen %} divider-seen {% endif %}"></span>
<span class="postdate">
{% if postDateRaw %}
Expand Down
8 changes: 7 additions & 1 deletion App/View Controllers/Posts/PostRenderModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct PostRenderModel: StencilContextConvertible {
"beenSeen": post.beenSeen,
"customTitleHTML": (enableCustomTitlePostLayout ? post.author?.customTitleHTML : nil) as Any,
"hiddenAvatarURL": hiddenAvatarURL as Any,
"hideMetadataForReader": hidePostMetadataForReader,
"htmlContents": htmlContents,
"postDate": post.postDate as Any,
"postDateRaw": postDateRaw as String,
Expand All @@ -77,7 +78,7 @@ struct PostRenderModel: StencilContextConvertible {
"showRegdate": showRegdate,
"visibleAvatarURL": visibleAvatarURL as Any]
}

init(author: User, isOP: Bool, postDate: String, postHTML: String) {
context = [
"author": [
Expand All @@ -86,6 +87,7 @@ struct PostRenderModel: StencilContextConvertible {
"username": author.username as Any],
"beenSeen": false,
"hiddenAvatarURL": (showAvatars ? author.avatarURL : nil) as Any,
"hideMetadataForReader": hidePostMetadataForReader,
"customTitleHTML": (enableCustomTitlePostLayout ? author.customTitleHTML : nil) as Any,
"htmlContents": massageHTML(postHTML, isIgnored: false, forumID: ""),
"postDate": postDate,
Expand Down Expand Up @@ -126,6 +128,10 @@ private var showAvatars: Bool {
UserDefaults.standard.defaultingValue(for: Settings.showAvatars)
}

private var hidePostMetadataForReader: Bool {
UserDefaults.standard.defaultingValue(for: Settings.hidePostMetadataForReader)
}

private var enableCustomTitlePostLayout: Bool {
switch UIDevice.current.userInterfaceIdiom {
case .mac, .pad:
Expand Down
7 changes: 7 additions & 0 deletions App/View Controllers/Posts/PostsPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ final class PostsPageViewController: ViewController {
@FoilDefaultStorage(Settings.fontScale) private var fontScale
@FoilDefaultStorage(Settings.frogAndGhostEnabled) private var frogAndGhostEnabled
@FoilDefaultStorage(Settings.handoffEnabled) private var handoffEnabled
@FoilDefaultStorage(Settings.hidePostMetadataForReader) private var hidePostMetadataForReader
private var jumpToLastPost = false
@FoilDefaultStorageOptional(Settings.lastOfferedPasteboardURLString) private var lastOfferedPasteboardURLString
@FoilDefaultStorageOptional(Settings.userID) private var loggedInUserID
Expand Down Expand Up @@ -1900,6 +1901,12 @@ final class PostsPageViewController: ViewController {
}
.store(in: &cancellables)

$hidePostMetadataForReader
.dropFirst()
.receive(on: RunLoop.main)
.sink { [weak self] in self?.postsView.renderView.setHidePostMetadataForReader($0) }
.store(in: &cancellables)

$pullForNext
.receive(on: RunLoop.main)
.sink { [weak self] _ in self?.updateUserInterface() }
Expand Down
11 changes: 11 additions & 0 deletions App/Views/RenderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,17 @@ extension RenderView {
}
}

/// Marks (when `true`) or unmarks (when `false`) post header and footer with `aria-hidden="true"` so iOS Spoken Content / VoiceOver skip them.
func setHidePostMetadataForReader(_ hide: Bool) {
Task {
do {
try await webView.eval("if (window.Awful) Awful.setHidePostMetadataForReader(\(hide ? "true" : "false"))")
} catch {
self.mentionError(error, explanation: "could not evaluate setHidePostMetadataForReader")
}
}
}

/// Turns all avatars on (when `true`) or off (when `false`).
func setShowAvatars(_ showAvatars: Bool) {
Task {
Expand Down
3 changes: 3 additions & 0 deletions AwfulSettings/Sources/AwfulSettings/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public enum Settings {
/// Offer to hand off the current thread page to other devices.
public static let handoffEnabled = Setting(key: "handoff_enabled", default: false)

/// Mark post header (username, regdate, role labels) and post date as `aria-hidden` so iOS Spoken Content / VoiceOver skip them and read post bodies more directly.
public static let hidePostMetadataForReader = Setting(key: "hide_post_metadata_for_reader", default: false)

/// Hide the sidebar in landscape orientation (assuming the display is wide enough to show the sidebar at all).
public static let hideSidebarInLandscape = Setting(key: "hide_sidebar_in_landscape", default: false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
},
"Handoff allows you to continue reading threads on nearby devices." : {

},
"Hide Post Metadata from Screen Reader" : {

},
"Hide Sidebar in Landscape" : {

Expand Down Expand Up @@ -180,6 +183,9 @@
},
"Sidebar" : {

},
"Skips usernames, post dates, and join dates when iOS reads posts aloud (Speak Screen and VoiceOver)." : {

},
"Sort Unread Bookmarks First" : {

Expand Down Expand Up @@ -207,4 +213,4 @@
}
},
"version" : "1.0"
}
}
5 changes: 5 additions & 0 deletions AwfulSettingsUI/Sources/AwfulSettingsUI/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public struct SettingsView: View {
@AppStorage(Settings.fontScale) private var fontScale
@AppStorage(Settings.frogAndGhostEnabled) private var frogAndGhostEnabled
@AppStorage(Settings.handoffEnabled) private var handoffEnabled
@AppStorage(Settings.hidePostMetadataForReader) private var hidePostMetadataForReader
@AppStorage(Settings.hideSidebarInLandscape) private var hideSidebarInLandscape
@AppStorage(Settings.immersiveModeEnabled) private var immersiveModeEnabled
@AppStorage(Settings.loadImages) private var loadImages
Expand Down Expand Up @@ -157,9 +158,13 @@ public struct SettingsView: View {
if isPad {
Toggle("Enable Custom Title Post Layout", bundle: .module, isOn: $customTitlePostLayout)
}
Toggle("Hide Post Metadata from Screen Reader", bundle: .module, isOn: $hidePostMetadataForReader)
} header: {
Text("Posts", bundle: .module)
.header()
} footer: {
Text("Skips usernames, post dates, and join dates when iOS reads posts aloud (Speak Screen and VoiceOver).", bundle: .module)
.footer()
}
.section()

Expand Down
Loading