Merge branch 'feature/visibility-menu-state' into release/0.6.1

This commit is contained in:
CMK 2021-06-15 18:59:10 +08:00
commit 65abb60eb9
2 changed files with 33 additions and 15 deletions

View File

@ -368,6 +368,7 @@ extension ComposeViewController {
guard let self = self else { return }
let image = type.image(interfaceStyle: self.traitCollection.userInterfaceStyle)
self.composeToolbarView.visibilityButton.setImage(image, for: .normal)
self.composeToolbarView.activeVisibilityType.value = type
}
.store(in: &disposeBag)
@ -676,7 +677,7 @@ extension ComposeViewController: TextEditorViewTextAttributesDelegate {
updateAttributedString attributedString: NSAttributedString,
completion: @escaping (NSAttributedString?) -> Void
) {
// FIXME: needs O(1) update completion to fix profermance issue
// FIXME: needs O(1) update completion to fix performance issue
DispatchQueue.global().async {
let string = attributedString.string
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: update: %s", ((#file as NSString).lastPathComponent), #line, #function, string)
@ -1291,7 +1292,8 @@ extension ComposeViewController {
case togglePoll
case toggleContentWarning
case selectVisibilityPublic
case selectVisibilityUnlisted
// TODO: remove selectVisibilityUnlisted from codebase
// case selectVisibilityUnlisted
case selectVisibilityPrivate
case selectVisibilityDirect
@ -1305,7 +1307,7 @@ extension ComposeViewController {
case .togglePoll: return L10n.Scene.Compose.Keyboard.togglePoll
case .toggleContentWarning: return L10n.Scene.Compose.Keyboard.toggleContentWarning
case .selectVisibilityPublic: return L10n.Scene.Compose.Keyboard.selectVisibilityEntry(L10n.Scene.Compose.Visibility.public)
case .selectVisibilityUnlisted: return L10n.Scene.Compose.Keyboard.selectVisibilityEntry(L10n.Scene.Compose.Visibility.unlisted)
// case .selectVisibilityUnlisted: return L10n.Scene.Compose.Keyboard.selectVisibilityEntry(L10n.Scene.Compose.Visibility.unlisted)
case .selectVisibilityPrivate: return L10n.Scene.Compose.Keyboard.selectVisibilityEntry(L10n.Scene.Compose.Visibility.private)
case .selectVisibilityDirect: return L10n.Scene.Compose.Keyboard.selectVisibilityEntry(L10n.Scene.Compose.Visibility.direct)
}
@ -1322,9 +1324,9 @@ extension ComposeViewController {
case .togglePoll: return "p" // + shift + command
case .toggleContentWarning: return "c" // + shift + command
case .selectVisibilityPublic: return "1" // + command
case .selectVisibilityUnlisted: return "2" // + command
case .selectVisibilityPrivate: return "3" // + command
case .selectVisibilityDirect: return "4" // + command
// case .selectVisibilityUnlisted: return "2" // + command
case .selectVisibilityPrivate: return "2" // + command
case .selectVisibilityDirect: return "3" // + command
}
}
@ -1338,7 +1340,7 @@ extension ComposeViewController {
case .togglePoll: return [.shift, .command]
case .toggleContentWarning: return [.shift, .command]
case .selectVisibilityPublic: return [.command]
case .selectVisibilityUnlisted: return [.command]
// case .selectVisibilityUnlisted: return [.command]
case .selectVisibilityPrivate: return [.command]
case .selectVisibilityDirect: return [.command]
}
@ -1390,8 +1392,8 @@ extension ComposeViewController {
composeToolbarView.contentWarningButton.sendActions(for: .touchUpInside)
case .selectVisibilityPublic:
viewModel.selectedStatusVisibility.value = .public
case .selectVisibilityUnlisted:
viewModel.selectedStatusVisibility.value = .unlisted
// case .selectVisibilityUnlisted:
// viewModel.selectedStatusVisibility.value = .unlisted
case .selectVisibilityPrivate:
viewModel.selectedStatusVisibility.value = .private
case .selectVisibilityDirect:

View File

@ -7,6 +7,7 @@
import os.log
import UIKit
import Combine
import MastodonSDK
protocol ComposeToolbarViewDelegate: AnyObject {
@ -19,6 +20,8 @@ protocol ComposeToolbarViewDelegate: AnyObject {
final class ComposeToolbarView: UIView {
var disposeBag = Set<AnyCancellable>()
static let toolbarButtonSize: CGSize = CGSize(width: 44, height: 44)
static let toolbarHeight: CGFloat = 44
@ -76,6 +79,8 @@ final class ComposeToolbarView: UIView {
return label
}()
let activeVisibilityType = CurrentValueSubject<VisibilitySelectionType, Never>(.public)
override init(frame: CGRect) {
super.init(frame: frame)
_init()
@ -142,6 +147,15 @@ extension ComposeToolbarView {
visibilityButton.showsMenuAsPrimaryAction = true
updateToolbarButtonUserInterfaceStyle()
// update menu when selected visibility type changed
activeVisibilityType
.receive(on: RunLoop.main)
.sink { [weak self] type in
guard let self = self else { return }
self.visibilityButton.menu = self.createVisibilityContextMenu(interfaceStyle: self.traitCollection.userInterfaceStyle)
}
.store(in: &disposeBag)
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
@ -161,14 +175,15 @@ extension ComposeToolbarView {
enum VisibilitySelectionType: String, CaseIterable {
case `public`
case unlisted
// TODO: remove unlisted option from codebase
// case unlisted
case `private`
case direct
var title: String {
switch self {
case .public: return L10n.Scene.Compose.Visibility.public
case .unlisted: return L10n.Scene.Compose.Visibility.unlisted
// case .unlisted: return L10n.Scene.Compose.Visibility.unlisted
case .private: return L10n.Scene.Compose.Visibility.private
case .direct: return L10n.Scene.Compose.Visibility.direct
}
@ -181,7 +196,7 @@ extension ComposeToolbarView {
case .light: return UIImage(systemName: "person.3", withConfiguration: UIImage.SymbolConfiguration(pointSize: 15, weight: .medium))!
default: return UIImage(systemName: "person.3.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 15, weight: .medium))!
}
case .unlisted: return UIImage(systemName: "eye.slash", withConfiguration: UIImage.SymbolConfiguration(pointSize: 18, weight: .regular))!
// case .unlisted: return UIImage(systemName: "eye.slash", withConfiguration: UIImage.SymbolConfiguration(pointSize: 18, weight: .regular))!
case .private: return UIImage(systemName: "person.crop.circle.badge.plus", withConfiguration: UIImage.SymbolConfiguration(pointSize: 18, weight: .regular))!
case .direct: return UIImage(systemName: "at", withConfiguration: UIImage.SymbolConfiguration(pointSize: 19, weight: .regular))!
}
@ -190,7 +205,7 @@ extension ComposeToolbarView {
func imageNameForTimeline() -> String {
switch self {
case .public: return "person.3"
case .unlisted: return "eye.slash"
// case .unlisted: return "eye.slash"
case .private: return "person.crop.circle.badge.plus"
case .direct: return "at"
}
@ -199,7 +214,7 @@ extension ComposeToolbarView {
var visibility: Mastodon.Entity.Status.Visibility {
switch self {
case .public: return .public
case .unlisted: return .unlisted
// case .unlisted: return .unlisted
case .private: return .private
case .direct: return .direct
}
@ -268,7 +283,8 @@ extension ComposeToolbarView {
private func createVisibilityContextMenu(interfaceStyle: UIUserInterfaceStyle) -> UIMenu {
let children: [UIMenuElement] = VisibilitySelectionType.allCases.map { type in
UIAction(title: type.title, image: type.image(interfaceStyle: interfaceStyle), identifier: nil, discoverabilityTitle: nil, attributes: [], state: .off) { [weak self] action in
let state: UIMenuElement.State = activeVisibilityType.value == type ? .on : .off
return UIAction(title: type.title, image: type.image(interfaceStyle: interfaceStyle), identifier: nil, discoverabilityTitle: nil, attributes: [], state: state) { [weak self] action in
guard let self = self else { return }
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: visibilitySelectionType: %s", ((#file as NSString).lastPathComponent), #line, #function, type.rawValue)
self.delegate?.composeToolbarView(self, visibilityButtonDidPressed: self.visibilityButton, visibilitySelectionType: type)