Skip to content
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

Fixes warning since iOS 15 minimum target #814

Merged
merged 3 commits into from
Nov 30, 2023
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
2 changes: 1 addition & 1 deletion ZShare/Controllers/RedirectWebViewHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ final class RedirectWebViewHandler: NSObject {
let userAgent = payload["userAgent"] as? String,
let referrer = payload["referrer"] as? String else {
DDLogError("RedirectWebViewHandler: extracted data missing response")
DDLogError("\(data as? [String: Any])")
DDLogError("\(String(describing: data as? [String: Any]))")
completion(nil, nil, nil)
return
}
Expand Down
2 changes: 1 addition & 1 deletion ZShare/Controllers/TranslationWebViewHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ final class TranslationWebViewHandler {
let userAgent = payload["userAgent"] as? String,
let referrer = payload["referrer"] as? String else {
DDLogError("WebViewHandler: extracted data missing response")
DDLogError("\(data as? [String: Any])")
DDLogError("\(String(describing: data as? [String: Any]))")
return Single.error(Error.webExtractionMissingData)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,14 @@ final class AnnotationViewController: UIViewController {
}

if editability != .notEditable {
var configuration = UIButton.Configuration.plain()
configuration.attributedTitle = AttributedString(L10n.Pdf.AnnotationPopover.delete, attributes: AttributeContainer([.font: UIFont.preferredFont(forTextStyle: .body)]))
configuration.baseForegroundColor = .red
configuration.contentInsets = NSDirectionalEdgeInsets(top: 12, leading: 0, bottom: 12, trailing: 0)
michalrentka marked this conversation as resolved.
Show resolved Hide resolved
let button = UIButton()
button.configuration = configuration
button.addTarget(self, action: #selector(AnnotationViewController.deleteAnnotation), for: .touchUpInside)
button.setTitle(L10n.Pdf.AnnotationPopover.delete, for: .normal)
button.titleLabel?.adjustsFontForContentSizeCategory = true
button.titleLabel?.font = .preferredFont(forTextStyle: .body)
button.setTitleColor(.red, for: .normal)
button.contentEdgeInsets = UIEdgeInsets(top: 11, left: 0, bottom: 12, right: 0)
self.deleteButton = button

self.containerStackView.addArrangedSubview(button)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,27 +178,33 @@ final class AnnotationViewHeader: UIView {
authorLabel.setContentHuggingPriority(.defaultLow, for: .horizontal)
authorLabel.translatesAutoresizingMaskIntoConstraints = false

var shareConfig = UIButton.Configuration.plain()
shareConfig.image = UIImage(systemName: "square.and.arrow.up")
shareConfig.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: layout.horizontalInset, bottom: 0, trailing: (layout.horizontalInset / 2))
let shareButton = UIButton()
shareButton.setImage(UIImage(systemName: "square.and.arrow.up"), for: .normal)
shareButton.configuration = shareConfig
shareButton.tintColor = Asset.Colors.zoteroBlueWithDarkMode.color
shareButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: layout.horizontalInset, bottom: 0, right: (layout.horizontalInset / 2))
shareButton.setContentCompressionResistancePriority(.required, for: .horizontal)
shareButton.setContentHuggingPriority(.defaultHigh, for: .horizontal)


var menuConfig = UIButton.Configuration.plain()
michalrentka marked this conversation as resolved.
Show resolved Hide resolved
menuConfig.image = UIImage(systemName: "ellipsis")
menuConfig.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: (layout.horizontalInset / 2), bottom: 0, trailing: (layout.horizontalInset / 2))
let menuButton = UIButton()
menuButton.setImage(UIImage(systemName: "ellipsis"), for: .normal)
menuButton.configuration = menuConfig
menuButton.tintColor = Asset.Colors.zoteroBlueWithDarkMode.color
menuButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: (layout.horizontalInset / 2), bottom: 0, right: (layout.horizontalInset / 2))
menuButton.setContentCompressionResistancePriority(.required, for: .horizontal)
menuButton.setContentHuggingPriority(.defaultHigh, for: .horizontal)

var rightButtons: [UIView] = [shareButton, menuButton]

if layout.showDoneButton {
var doneConfig = UIButton.Configuration.plain()
doneConfig.title = L10n.done
doneConfig.baseForegroundColor = Asset.Colors.zoteroBlueWithDarkMode.color
doneConfig.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: (layout.horizontalInset / 2), bottom: 0, trailing: layout.horizontalInset)
let doneButton = UIButton()
doneButton.setTitle(L10n.done, for: .normal)
doneButton.setTitleColor(Asset.Colors.zoteroBlueWithDarkMode.color, for: .normal)
doneButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: (layout.horizontalInset / 2), bottom: 0, right: layout.horizontalInset)
doneButton.configuration = doneConfig
doneButton.titleLabel?.adjustsFontForContentSizeCategory = true
doneButton.setContentCompressionResistancePriority(.required, for: .horizontal)
doneButton.setContentHuggingPriority(.defaultHigh, for: .horizontal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class AnnotationToolbarViewController: UIViewController {
static let estimatedVerticalHeight: CGFloat = 500
private static let buttonSpacing: CGFloat = UIDevice.current.userInterfaceIdiom == .phone ? 12 : 12
private static let buttonCompactSpacing: CGFloat = 8
private static let buttonEdgeInsets: UIEdgeInsets = UIDevice.current.userInterfaceIdiom == .pad ? UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4) :
UIEdgeInsets(top: 2, left: 2, bottom: 2, right: 2)
private static let buttonContentInsets: NSDirectionalEdgeInsets = UIDevice.current.userInterfaceIdiom == .pad ? NSDirectionalEdgeInsets(top: 4, leading: 4, bottom: 4, trailing: 4) :
NSDirectionalEdgeInsets(top: 2, leading: 2, bottom: 2, trailing: 2)
private static let toolsToAdditionalFullOffset: CGFloat = 70
private static let toolsToAdditionalCompactOffset: CGFloat = 20
private let disposeBag: DisposeBag
Expand Down Expand Up @@ -354,37 +354,36 @@ class AnnotationToolbarViewController: UIViewController {
}

private func createToolButtons(from tools: [Tool]) -> [UIView] {
var showMoreConfig = UIButton.Configuration.plain()
showMoreConfig.contentInsets = AnnotationToolbarViewController.buttonContentInsets
showMoreConfig.image = UIImage(systemName: "ellipsis")?.withRenderingMode(.alwaysTemplate)
let showMoreButton = UIButton(type: .custom)
showMoreButton.contentEdgeInsets = AnnotationToolbarViewController.buttonEdgeInsets
showMoreButton.configuration = showMoreConfig
showMoreButton.translatesAutoresizingMaskIntoConstraints = false
showMoreButton.showsLargeContentViewer = true
showMoreButton.accessibilityLabel = L10n.Accessibility.Pdf.showMoreTools
showMoreButton.largeContentTitle = L10n.Accessibility.Pdf.showMoreTools
showMoreButton.setContentCompressionResistancePriority(.required, for: .vertical)
showMoreButton.setContentCompressionResistancePriority(.required, for: .horizontal)
showMoreButton.setImage(UIImage(systemName: "ellipsis")?.withRenderingMode(.alwaysTemplate), for: .normal)
showMoreButton.tintColor = Asset.Colors.zoteroBlueWithDarkMode.color
showMoreButton.showsMenuAsPrimaryAction = true
showMoreButton.widthAnchor.constraint(equalTo: showMoreButton.heightAnchor).isActive = true

return tools.map { tool in
let button = CheckboxButton(type: .custom)
button.contentEdgeInsets = AnnotationToolbarViewController.buttonEdgeInsets
let button = CheckboxButton(image: tool.image.withRenderingMode(.alwaysTemplate), contentInsets: AnnotationToolbarViewController.buttonContentInsets)
button.translatesAutoresizingMaskIntoConstraints = false
button.showsLargeContentViewer = true
button.accessibilityLabel = tool.accessibilityLabel
button.largeContentTitle = tool.title
button.setImage(tool.image.withRenderingMode(.alwaysTemplate), for: .normal)
button.tintColor = Asset.Colors.zoteroBlueWithDarkMode.color
button.adjustsImageWhenHighlighted = false
button.deselectedBackgroundColor = .clear
button.deselectedTintColor = Asset.Colors.zoteroBlueWithDarkMode.color
button.selectedBackgroundColor = Asset.Colors.zoteroBlue.color
button.selectedTintColor = .white
button.layer.cornerRadius = 4
button.layer.masksToBounds = true
button.setContentCompressionResistancePriority(.required, for: .vertical)
button.setContentCompressionResistancePriority(.required, for: .horizontal)
button.isHidden = true
button.widthAnchor.constraint(equalTo: button.heightAnchor).isActive = true
button.setNeedsUpdateConfiguration()

let recognizer = UITapGestureRecognizer()
recognizer.delegate = self
Expand All @@ -396,13 +395,15 @@ class AnnotationToolbarViewController: UIViewController {
}

private func createAdditionalItems() -> [UIView] {
var undoConfig = UIButton.Configuration.plain()
undoConfig.contentInsets = AnnotationToolbarViewController.buttonContentInsets
undoConfig.image = UIImage(systemName: "arrow.uturn.left")?.applyingSymbolConfiguration(.init(scale: .large))
let undo = UIButton(type: .custom)
undo.configuration = undoConfig
undo.isEnabled = self.delegate?.canUndo ?? false
undo.contentEdgeInsets = AnnotationToolbarViewController.buttonEdgeInsets
undo.showsLargeContentViewer = true
undo.accessibilityLabel = L10n.Accessibility.Pdf.undo
undo.largeContentTitle = L10n.Accessibility.Pdf.undo
undo.setImage(UIImage(systemName: "arrow.uturn.left", withConfiguration: UIImage.SymbolConfiguration(scale: .large)), for: .normal)
undo.rx.controlEvent(.touchUpInside)
.subscribe(with: self, onNext: { `self`, _ in
guard self.delegate?.canUndo == true else { return }
Expand All @@ -411,13 +412,15 @@ class AnnotationToolbarViewController: UIViewController {
.disposed(by: self.disposeBag)
self.undoButton = undo

var redoConfig = UIButton.Configuration.plain()
redoConfig.contentInsets = AnnotationToolbarViewController.buttonContentInsets
redoConfig.image = UIImage(systemName: "arrow.uturn.right")?.applyingSymbolConfiguration(.init(scale: .large))
let redo = UIButton(type: .custom)
redo.configuration = redoConfig
redo.isEnabled = self.delegate?.canRedo ?? false
redo.contentEdgeInsets = AnnotationToolbarViewController.buttonEdgeInsets
redo.showsLargeContentViewer = true
redo.accessibilityLabel = L10n.Accessibility.Pdf.redo
redo.largeContentTitle = L10n.Accessibility.Pdf.redo
redo.setImage(UIImage(systemName: "arrow.uturn.right", withConfiguration: UIImage.SymbolConfiguration(scale: .large)), for: .normal)
redo.rx.controlEvent(.touchUpInside)
.subscribe(with: self, onNext: { `self`, _ in
guard self.delegate?.canRedo == true else { return }
Expand All @@ -426,19 +429,21 @@ class AnnotationToolbarViewController: UIViewController {
.disposed(by: self.disposeBag)
self.redoButton = redo

var closeConfig = UIButton.Configuration.plain()
closeConfig.contentInsets = AnnotationToolbarViewController.buttonContentInsets
closeConfig.image = UIImage(systemName: "xmark.circle")?.applyingSymbolConfiguration(.init(scale: .large))
let close = UIButton(type: .custom)
close.contentEdgeInsets = AnnotationToolbarViewController.buttonEdgeInsets
close.configuration = closeConfig
close.showsLargeContentViewer = true
close.accessibilityLabel = L10n.close
close.largeContentTitle = L10n.close
close.setImage(UIImage(systemName: "xmark.circle", withConfiguration: UIImage.SymbolConfiguration(scale: .large)), for: .normal)
close.rx.controlEvent(.touchUpInside)
.subscribe(with: self, onNext: { `self`, _ in
self.delegate?.closeAnnotationToolbar()
})
.disposed(by: self.disposeBag)

let handle = UIImageView(image: UIImage(systemName: "line.3.horizontal", withConfiguration: UIImage.SymbolConfiguration(scale: .large)))
let handle = UIImageView(image: UIImage(systemName: "line.3.horizontal")?.applyingSymbolConfiguration(.init(scale: .large)))
handle.showsLargeContentViewer = false
handle.contentMode = .center

Expand All @@ -454,8 +459,11 @@ class AnnotationToolbarViewController: UIViewController {
}

private func createColorPickerButton() -> UIButton {
var pickerConfig = UIButton.Configuration.plain()
pickerConfig.contentInsets = AnnotationToolbarViewController.buttonContentInsets
pickerConfig.image = UIImage(systemName: "circle.fill")?.applyingSymbolConfiguration(.init(scale: .large))
let picker = UIButton()
picker.contentEdgeInsets = AnnotationToolbarViewController.buttonEdgeInsets
picker.configuration = pickerConfig
picker.showsLargeContentViewer = true
picker.translatesAutoresizingMaskIntoConstraints = false
picker.setContentCompressionResistancePriority(.required, for: .horizontal)
Expand All @@ -464,7 +472,6 @@ class AnnotationToolbarViewController: UIViewController {
picker.isHidden = true
picker.accessibilityLabel = L10n.Accessibility.Pdf.colorPicker
picker.largeContentTitle = L10n.Accessibility.Pdf.colorPicker
picker.setImage(UIImage(systemName: "circle.fill", withConfiguration: UIImage.SymbolConfiguration(scale: .large)), for: .normal)
picker.rx.controlEvent(.touchUpInside)
.subscribe(with: self, onNext: { `self`, _ in
self.delegate?.showToolOptions(sender: .view(self.colorPickerButton, nil))
Expand Down
60 changes: 27 additions & 33 deletions Zotero/Scenes/Detail/PDF/Views/CheckboxButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,41 @@
import UIKit

final class CheckboxButton: UIButton {
var selectedBackgroundColor: UIColor = .clear {
didSet {
if self.isSelected {
self.backgroundColor = self.selectedBackgroundColor
}
}
}
var selectedBackgroundColor: UIColor = .clear
var deselectedBackgroundColor: UIColor = .clear
var selectedTintColor: UIColor = .black
var deselectedTintColor: UIColor = Asset.Colors.zoteroBlue.color

var deselectedBackgroundColor: UIColor = .clear {
override var isSelected: Bool {
didSet {
if !self.isSelected {
self.backgroundColor = self.deselectedBackgroundColor
}
setNeedsUpdateConfiguration()
}
}

var selectedTintColor: UIColor = .black {
didSet {
if self.isSelected {
self.tintColor = self.selectedTintColor
}
}
}
init(image: UIImage, contentInsets: NSDirectionalEdgeInsets) {
super.init(frame: .zero)

var deselectedTintColor: UIColor = Asset.Colors.zoteroBlue.color {
didSet {
if !self.isSelected {
self.tintColor = self.deselectedTintColor
}
}
}
var configuration = UIButton.Configuration.plain()
var background = configuration.background
background.cornerRadius = 4
configuration.image = image
configuration.contentInsets = contentInsets
self.configuration = configuration

override var isSelected: Bool {
didSet {
if self.isSelected {
self.backgroundColor = self.selectedBackgroundColor
self.tintColor = self.selectedTintColor
} else {
self.backgroundColor = self.deselectedBackgroundColor
self.tintColor = self.deselectedTintColor
self.configurationUpdateHandler = { [weak self] button in
let isSelected = self?.isSelected ?? false
var configuration = button.configuration
var background = configuration?.background
background?.backgroundColor = isSelected ? self?.selectedBackgroundColor : self?.deselectedBackgroundColor
if let background {
configuration?.background = background
}
configuration?.baseForegroundColor = isSelected ? self?.selectedTintColor : self?.deselectedTintColor
button.configuration = configuration
}
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
10 changes: 4 additions & 6 deletions Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,12 @@ class PDFReaderViewController: UIViewController {
private var undoBarButton: UIBarButtonItem?
private var redoBarButton: UIBarButtonItem?
private lazy var toolbarButton: UIBarButtonItem = {
let checkbox = CheckboxButton(type: .custom)
checkbox.setImage(UIImage(systemName: "pencil.and.outline", withConfiguration: UIImage.SymbolConfiguration(scale: .large)), for: .normal)
checkbox.adjustsImageWhenHighlighted = false
var configuration = UIButton.Configuration.plain()
let image = UIImage(systemName: "pencil.and.outline")?.applyingSymbolConfiguration(.init(scale: .large))
let checkbox = CheckboxButton(image: image!, contentInsets: NSDirectionalEdgeInsets(top: 11, leading: 6, bottom: 9, trailing: 6))
michalrentka marked this conversation as resolved.
Show resolved Hide resolved
checkbox.scalesLargeContentImage = true
checkbox.layer.cornerRadius = 4
checkbox.layer.masksToBounds = true
checkbox.deselectedBackgroundColor = .clear
checkbox.deselectedTintColor = self.viewModel.state.document.isLocked ? .gray : Asset.Colors.zoteroBlueWithDarkMode.color
checkbox.contentEdgeInsets = UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 6)
checkbox.selectedBackgroundColor = Asset.Colors.zoteroBlue.color
checkbox.selectedTintColor = .white
checkbox.isSelected = !self.viewModel.state.document.isLocked && self.toolbarState.visible
Expand Down
8 changes: 5 additions & 3 deletions Zotero/Scenes/Detail/PDF/Views/SearchBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ final class SearchBar: UIView {
clearConfiguration.image = clearImage
clear.configuration = clearConfiguration

var cancelConfiguration = UIButton.Configuration.plain()
cancelConfiguration.title = L10n.cancel
cancelConfiguration.baseForegroundColor = Asset.Colors.zoteroBlueWithDarkMode.color
cancelConfiguration.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: SearchBar.cancelOffset, bottom: 0, trailing: insets.right)
let cancel = UIButton(type: .custom)
cancel.configuration = clearConfiguration
cancel.translatesAutoresizingMaskIntoConstraints = false
cancel.setTitle(L10n.cancel, for: .normal)
cancel.accessibilityLabel = L10n.Searchbar.accessibilityCancel
cancel.setTitleColor(Asset.Colors.zoteroBlueWithDarkMode.color, for: .normal)
cancel.contentEdgeInsets = UIEdgeInsets(top: 0, left: SearchBar.cancelOffset, bottom: 0, right: self.insets.right)
cancel.setContentHuggingPriority(.defaultHigh, for: .horizontal)
cancel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
cancel.isHidden = true
Expand Down
Loading
Loading