完善阅读器主题与批注界面

This commit is contained in:
shenlei
2026-07-13 13:01:14 +09:00
parent adc24d3f36
commit 6a0a1223b1
22 changed files with 133 additions and 189 deletions
@@ -8,6 +8,7 @@ final class RDEPUBReaderBottomToolView: RDEPUBReaderToolView, RDEPUBReaderBottom
var onShowHighlights: (() -> Void)?
@available(*, deprecated, message: "Use the text selection menu to create annotations.")
var onAddHighlight: (() -> Void)?
var onShowSettings: (() -> Void)?
@@ -25,9 +26,8 @@ final class RDEPUBReaderBottomToolView: RDEPUBReaderToolView, RDEPUBReaderBottom
private let bookmarksButton = RDEPUBReaderTintButton(type: .system)
private let highlightsButton = RDEPUBReaderTintButton(type: .system)
private let addHighlightButton = RDEPUBReaderTintButton(type: .system)
/// 线 /
private let annotationListButton = RDEPUBReaderTintButton(type: .system)
private let settingsButton = RDEPUBReaderTintButton(type: .system)
@@ -39,8 +39,7 @@ final class RDEPUBReaderBottomToolView: RDEPUBReaderToolView, RDEPUBReaderBottom
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.addArrangedSubview(chapterButton)
stackView.addArrangedSubview(bookmarksButton)
stackView.addArrangedSubview(highlightsButton)
stackView.addArrangedSubview(addHighlightButton)
stackView.addArrangedSubview(annotationListButton)
stackView.addArrangedSubview(settingsButton)
NSLayoutConstraint.activate([
@@ -52,23 +51,20 @@ final class RDEPUBReaderBottomToolView: RDEPUBReaderToolView, RDEPUBReaderBottom
configureButton(chapterButton, systemName: "list.bullet", fallbackTitle: "目录")
configureButton(bookmarksButton, systemName: "bookmark", fallbackTitle: "书签")
configureButton(highlightsButton, systemName: "note.text", fallbackTitle: "标注")
configureButton(addHighlightButton, systemName: "highlighter", fallbackTitle: "标注")
configureButton(annotationListButton, systemName: "note.text", fallbackTitle: "标注")
configureButton(settingsButton, systemName: "textformat.size", fallbackTitle: "设置")
chapterButton.accessibilityIdentifier = "epub.reader.toc"
bookmarksButton.accessibilityIdentifier = "epub.reader.bookmarks"
highlightsButton.accessibilityIdentifier = "epub.reader.highlights"
addHighlightButton.accessibilityIdentifier = "epub.reader.add-highlight"
annotationListButton.accessibilityIdentifier = "epub.reader.highlights"
settingsButton.accessibilityIdentifier = "epub.reader.settings"
[chapterButton, bookmarksButton, highlightsButton, addHighlightButton, settingsButton].forEach { button in
[chapterButton, bookmarksButton, annotationListButton, settingsButton].forEach { button in
button.heightAnchor.constraint(greaterThanOrEqualToConstant: 44).isActive = true
}
chapterButton.addTarget(self, action: #selector(chapterAction), for: .touchUpInside)
bookmarksButton.addTarget(self, action: #selector(bookmarksAction), for: .touchUpInside)
highlightsButton.addTarget(self, action: #selector(highlightsAction), for: .touchUpInside)
addHighlightButton.addTarget(self, action: #selector(highlightAction), for: .touchUpInside)
annotationListButton.addTarget(self, action: #selector(annotationListAction), for: .touchUpInside)
settingsButton.addTarget(self, action: #selector(settingsAction), for: .touchUpInside)
}
@@ -82,20 +78,21 @@ final class RDEPUBReaderBottomToolView: RDEPUBReaderToolView, RDEPUBReaderBottom
override func apply(theme: RDEPUBReaderTheme) {
super.apply(theme: theme)
[chapterButton, bookmarksButton, highlightsButton, addHighlightButton, settingsButton].forEach { button in
button.tintColor = .black
button.setTitleColor(.black, for: .normal)
[chapterButton, bookmarksButton, annotationListButton, settingsButton].forEach { button in
button.tintColor = theme.toolControlTextColor
button.setTitleColor(theme.toolControlTextColor, for: .normal)
}
}
func setAddHighlightEnabled(_ isEnabled: Bool) {
addHighlightButton.isEnabled = isEnabled
addHighlightButton.alpha = isEnabled ? 1 : 0.45
func setHighlightsEnabled(_ isEnabled: Bool) {
annotationListButton.isEnabled = isEnabled
annotationListButton.alpha = isEnabled ? 1 : 0.45
}
func setHighlightsEnabled(_ isEnabled: Bool) {
highlightsButton.isEnabled = isEnabled
highlightsButton.alpha = isEnabled ? 1 : 0.45
@available(*, deprecated, message: "Use the text selection menu to create annotations.")
func setAddHighlightEnabled(_ isEnabled: Bool) {
// The built-in toolbar no longer exposes this action. Keep the method so
// custom toolbar integrations compiled against previous SDKs remain valid.
}
func setBookmarksEnabled(_ isEnabled: Bool) {
@@ -110,8 +107,7 @@ final class RDEPUBReaderBottomToolView: RDEPUBReaderToolView, RDEPUBReaderBottom
) {
chapterButton.isHidden = !showsTableOfContents
bookmarksButton.isHidden = false
highlightsButton.isHidden = !allowsHighlights
addHighlightButton.isHidden = !allowsHighlights
annotationListButton.isHidden = !allowsHighlights
settingsButton.isHidden = !showsSettingsPanel
}
@@ -132,14 +128,10 @@ final class RDEPUBReaderBottomToolView: RDEPUBReaderToolView, RDEPUBReaderBottom
onShowBookmarks?()
}
@objc private func highlightsAction() {
@objc private func annotationListAction() {
onShowHighlights?()
}
@objc private func highlightAction() {
onAddHighlight?()
}
@objc private func settingsAction() {
onShowSettings?()
}