feat: add wizard for multiple account entry

This commit is contained in:
CMK 2021-09-15 20:18:19 +08:00
parent 46ebdd8059
commit 016d7b987d
16 changed files with 544 additions and 45 deletions

View File

@ -536,7 +536,12 @@
}
},
"account_list": {
"add_account": "Add Account"
"tab_bar_hint": "Current selected profile: %s. Double tap then hold to show account switcher",
"dismiss_account_switcher": "Dismiss Account Switcher",
"add_account": "Add Account",
},
"wizard": {
"multiple_account_switch_intro_description": "Switch between multiple accounts by holding the profile button."
}
}
}
}

View File

@ -202,6 +202,7 @@
DB0F8150264D1E2500F2A12B /* PickServerLoaderTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0F814F264D1E2500F2A12B /* PickServerLoaderTableViewCell.swift */; };
DB118A8225E4B6E600FAB162 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DB118A8125E4B6E600FAB162 /* Preview Assets.xcassets */; };
DB1D186C25EF5BA7003F1F23 /* PollTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB1D186B25EF5BA7003F1F23 /* PollTableView.swift */; };
DB1D61CF26F1B33600DA8662 /* WelcomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB1D61CE26F1B33600DA8662 /* WelcomeViewModel.swift */; };
DB1D842C26551A1C000346B3 /* StatusProvider+StatusTableViewKeyCommandNavigateable.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB1D842B26551A1C000346B3 /* StatusProvider+StatusTableViewKeyCommandNavigateable.swift */; };
DB1D842E26552C4D000346B3 /* StatusTableViewControllerNavigateable.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB1D842D26552C4D000346B3 /* StatusTableViewControllerNavigateable.swift */; };
DB1D843026566512000346B3 /* KeyboardPreference.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB1D842F26566512000346B3 /* KeyboardPreference.swift */; };
@ -262,6 +263,8 @@
DB482A45261335BA008AE74C /* UserTimelineViewController+Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB482A44261335BA008AE74C /* UserTimelineViewController+Provider.swift */; };
DB482A4B261340A7008AE74C /* APIService+UserTimeline.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB482A4A261340A7008AE74C /* APIService+UserTimeline.swift */; };
DB4924E226312AB200E9DB22 /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB4924E126312AB200E9DB22 /* NotificationService.swift */; };
DB4932B126F1FB5300EF46D4 /* WizardCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB4932B026F1FB5300EF46D4 /* WizardCardView.swift */; };
DB4932B326F2054200EF46D4 /* CircleAvatarButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB4932B226F2054200EF46D4 /* CircleAvatarButton.swift */; };
DB49A61425FF2C5600B98345 /* EmojiService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB49A61325FF2C5600B98345 /* EmojiService.swift */; };
DB49A61F25FF32AA00B98345 /* EmojiService+CustomEmojiViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB49A61E25FF32AA00B98345 /* EmojiService+CustomEmojiViewModel.swift */; };
DB49A62525FF334C00B98345 /* EmojiService+CustomEmojiViewModel+LoadState.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB49A62425FF334C00B98345 /* EmojiService+CustomEmojiViewModel+LoadState.swift */; };
@ -301,6 +304,8 @@
DB6180F826391D660018D199 /* MediaPreviewingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB6180F726391D660018D199 /* MediaPreviewingViewController.swift */; };
DB6180FA26391F2E0018D199 /* MediaPreviewViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB6180F926391F2E0018D199 /* MediaPreviewViewModel.swift */; };
DB63BE7F268DD1070011D3F9 /* NotificationViewController+StatusProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB63BE7E268DD1070011D3F9 /* NotificationViewController+StatusProvider.swift */; };
DB647C5726F1E97300F7F82C /* MainTabBarController+Wizard.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB647C5626F1E97300F7F82C /* MainTabBarController+Wizard.swift */; };
DB647C5926F1EA2700F7F82C /* WizardPreference.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB647C5826F1EA2700F7F82C /* WizardPreference.swift */; };
DB66728C25F9F8DC00D60309 /* ComposeViewModel+DataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB66728B25F9F8DC00D60309 /* ComposeViewModel+DataSource.swift */; };
DB66729625F9F91600D60309 /* ComposeStatusSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB66729525F9F91600D60309 /* ComposeStatusSection.swift */; };
DB66729C25F9F91F00D60309 /* ComposeStatusItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB66729B25F9F91F00D60309 /* ComposeStatusItem.swift */; };
@ -949,6 +954,7 @@
DB0F814F264D1E2500F2A12B /* PickServerLoaderTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PickServerLoaderTableViewCell.swift; sourceTree = "<group>"; };
DB118A8125E4B6E600FAB162 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
DB1D186B25EF5BA7003F1F23 /* PollTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PollTableView.swift; sourceTree = "<group>"; };
DB1D61CE26F1B33600DA8662 /* WelcomeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeViewModel.swift; sourceTree = "<group>"; };
DB1D842B26551A1C000346B3 /* StatusProvider+StatusTableViewKeyCommandNavigateable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StatusProvider+StatusTableViewKeyCommandNavigateable.swift"; sourceTree = "<group>"; };
DB1D842D26552C4D000346B3 /* StatusTableViewControllerNavigateable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusTableViewControllerNavigateable.swift; sourceTree = "<group>"; };
DB1D842F26566512000346B3 /* KeyboardPreference.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardPreference.swift; sourceTree = "<group>"; };
@ -1016,6 +1022,8 @@
DB482A44261335BA008AE74C /* UserTimelineViewController+Provider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserTimelineViewController+Provider.swift"; sourceTree = "<group>"; };
DB482A4A261340A7008AE74C /* APIService+UserTimeline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIService+UserTimeline.swift"; sourceTree = "<group>"; };
DB4924E126312AB200E9DB22 /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
DB4932B026F1FB5300EF46D4 /* WizardCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WizardCardView.swift; sourceTree = "<group>"; };
DB4932B226F2054200EF46D4 /* CircleAvatarButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleAvatarButton.swift; sourceTree = "<group>"; };
DB49A61325FF2C5600B98345 /* EmojiService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiService.swift; sourceTree = "<group>"; };
DB49A61E25FF32AA00B98345 /* EmojiService+CustomEmojiViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EmojiService+CustomEmojiViewModel.swift"; sourceTree = "<group>"; };
DB49A62425FF334C00B98345 /* EmojiService+CustomEmojiViewModel+LoadState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EmojiService+CustomEmojiViewModel+LoadState.swift"; sourceTree = "<group>"; };
@ -1079,6 +1087,8 @@
DB6180F726391D660018D199 /* MediaPreviewingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaPreviewingViewController.swift; sourceTree = "<group>"; };
DB6180F926391F2E0018D199 /* MediaPreviewViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaPreviewViewModel.swift; sourceTree = "<group>"; };
DB63BE7E268DD1070011D3F9 /* NotificationViewController+StatusProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NotificationViewController+StatusProvider.swift"; sourceTree = "<group>"; };
DB647C5626F1E97300F7F82C /* MainTabBarController+Wizard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MainTabBarController+Wizard.swift"; sourceTree = "<group>"; };
DB647C5826F1EA2700F7F82C /* WizardPreference.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WizardPreference.swift; sourceTree = "<group>"; };
DB66728B25F9F8DC00D60309 /* ComposeViewModel+DataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ComposeViewModel+DataSource.swift"; sourceTree = "<group>"; };
DB66729525F9F91600D60309 /* ComposeStatusSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeStatusSection.swift; sourceTree = "<group>"; };
DB66729B25F9F91F00D60309 /* ComposeStatusItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeStatusItem.swift; sourceTree = "<group>"; };
@ -1499,6 +1509,7 @@
children = (
DBABE3F125ECAC4E00879EE5 /* View */,
0FAA0FDE25E0B57E0017CCDE /* WelcomeViewController.swift */,
DB1D61CE26F1B33600DA8662 /* WelcomeViewModel.swift */,
);
path = Welcome;
sourceTree = "<group>";
@ -1676,6 +1687,7 @@
isa = PBXGroup;
children = (
DB0C947126A7D2D70088FB11 /* AvatarButton.swift */,
DB4932B226F2054200EF46D4 /* CircleAvatarButton.swift */,
DB71FD2B25F86A5100512AE1 /* AvatarStackContainerButton.swift */,
2D42FF8425C8224F004A627A /* HitTestExpandedButton.swift */,
0FAA101125E105390017CCDE /* PrimaryActionButton.swift */,
@ -2322,6 +2334,7 @@
isa = PBXGroup;
children = (
DBA465942696E387002B41DB /* AppPreference.swift */,
DB647C5826F1EA2700F7F82C /* WizardPreference.swift */,
DB6D1B3C2636857500ACB481 /* AppearancePreference.swift */,
DBE54AC52636C89F004E7C0B /* NotificationPreference.swift */,
DB1D842F26566512000346B3 /* KeyboardPreference.swift */,
@ -2602,6 +2615,7 @@
isa = PBXGroup;
children = (
DB8AF54F25C13703002E6C99 /* MainTabBarController.swift */,
DB647C5626F1E97300F7F82C /* MainTabBarController+Wizard.swift */,
);
path = MainTab;
sourceTree = "<group>";
@ -2847,6 +2861,7 @@
isa = PBXGroup;
children = (
DBABE3EB25ECAC4B00879EE5 /* WelcomeIllustrationView.swift */,
DB4932B026F1FB5300EF46D4 /* WizardCardView.swift */,
);
path = View;
sourceTree = "<group>";
@ -3966,10 +3981,12 @@
2D45E5BF25C9549700A6D639 /* PublicTimelineViewModel+State.swift in Sources */,
DB8AF55D25C138B7002E6C99 /* UIViewController.swift in Sources */,
DB7F48452620241000796008 /* ProfileHeaderViewModel.swift in Sources */,
DB647C5926F1EA2700F7F82C /* WizardPreference.swift in Sources */,
2D3F9E0425DFA133004262D9 /* UITapGestureRecognizer.swift in Sources */,
5DDDF1992617447F00311060 /* Mastodon+Entity+Tag.swift in Sources */,
5B90C45F262599800002E742 /* SettingsToggleTableViewCell.swift in Sources */,
2D694A7425F9EB4E0038ADDC /* ContentWarningOverlayView.swift in Sources */,
DB4932B126F1FB5300EF46D4 /* WizardCardView.swift in Sources */,
DBAE3F682615DD60004B8251 /* UserProvider.swift in Sources */,
DBAC6488267D388B007FE9FD /* ASTableNode.swift in Sources */,
DB6D9F76263587C7008423CD /* SettingFetchedResultController.swift in Sources */,
@ -4122,6 +4139,7 @@
DB9D6C3825E508BE0051B173 /* Attachment.swift in Sources */,
5DFC35DF262068D20045711D /* SearchViewController+Follow.swift in Sources */,
DB8AF52E25C13561002E6C99 /* ViewStateStore.swift in Sources */,
DB1D61CF26F1B33600DA8662 /* WelcomeViewModel.swift in Sources */,
2DA7D04A25CA52CB00804E11 /* TimelineBottomLoaderTableViewCell.swift in Sources */,
DBD376B2269302A4007FEC24 /* UITableViewCell.swift in Sources */,
DB4F0966269ED52200D62E92 /* SearchResultViewModel.swift in Sources */,
@ -4158,9 +4176,11 @@
DB49A62525FF334C00B98345 /* EmojiService+CustomEmojiViewModel+LoadState.swift in Sources */,
DB4924E226312AB200E9DB22 /* NotificationService.swift in Sources */,
DB6D9F6F2635807F008423CD /* Setting.swift in Sources */,
DB647C5726F1E97300F7F82C /* MainTabBarController+Wizard.swift in Sources */,
DB6F5E38264E994A009108F4 /* AutoCompleteTopChevronView.swift in Sources */,
DBB525412611ED54002F1F29 /* ProfileHeaderViewController.swift in Sources */,
DB9D6BFF25E4F5940051B173 /* ProfileViewController.swift in Sources */,
DB4932B326F2054200EF46D4 /* CircleAvatarButton.swift in Sources */,
0FB3D30825E524C600AAD544 /* PickServerCategoriesCell.swift in Sources */,
2D4AD8A226316CD200613EFC /* SelectedAccountSection.swift in Sources */,
DB789A1225F9F2CC0071ACA0 /* ComposeViewModel.swift in Sources */,

View File

@ -7,42 +7,42 @@
<key>AppShared.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>22</integer>
<integer>38</integer>
</dict>
<key>CoreDataStack.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>24</integer>
<integer>35</integer>
</dict>
<key>Mastodon - ASDK.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
<integer>3</integer>
</dict>
<key>Mastodon - RTL.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>12</integer>
<integer>13</integer>
</dict>
<key>Mastodon - Release.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>2</integer>
</dict>
<key>Mastodon - ar.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>7</integer>
<integer>10</integer>
</dict>
<key>Mastodon - ca.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>32</integer>
<integer>16</integer>
</dict>
<key>Mastodon - de.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>8</integer>
<integer>11</integer>
</dict>
<key>Mastodon - en.xcscheme_^#shared#^_</key>
<dict>
@ -52,42 +52,42 @@
<key>Mastodon - es-419.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>5</integer>
<integer>8</integer>
</dict>
<key>Mastodon - es.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>4</integer>
<integer>7</integer>
</dict>
<key>Mastodon - fr.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>6</integer>
<integer>9</integer>
</dict>
<key>Mastodon - jp.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>27</integer>
<integer>14</integer>
</dict>
<key>Mastodon - nl.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>9</integer>
<integer>12</integer>
</dict>
<key>Mastodon - ru.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
<integer>4</integer>
</dict>
<key>Mastodon - th.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
<integer>5</integer>
</dict>
<key>Mastodon - zh_Hans.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>30</integer>
<integer>15</integer>
</dict>
<key>Mastodon.xcscheme_^#shared#^_</key>
<dict>
@ -97,7 +97,7 @@
<key>MastodonIntent.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>26</integer>
<integer>36</integer>
</dict>
<key>MastodonIntents.xcscheme_^#shared#^_</key>
<dict>
@ -112,12 +112,12 @@
<key>NotificationService.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
<integer>6</integer>
</dict>
<key>ShareActionExtension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>23</integer>
<integer>37</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>

View File

@ -32,7 +32,7 @@ open class TableNodeDiffableDataSource<SectionIdentifierType: Hashable, ItemIden
self.cellProvider = cellProvider
super.init()
tableNode.dataSource = self
tableNode.delegate = self
}
/// Applies given snapshot to perform automatic diffing update.

View File

@ -0,0 +1,15 @@
//
// WizardPreference.swift
// Mastodon
//
// Created by Cirno MainasuK on 2021-9-15.
//
import UIKit
extension UserDefaults {
@objc dynamic var didShowMultipleAccountSwitchWizard: Bool {
get { return bool(forKey: #function) }
set { self[#function] = newValue }
}
}

View File

@ -9,6 +9,7 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import MastodonSDK
import MastodonMeta
final class AccountListViewModel {
@ -20,19 +21,31 @@ final class AccountListViewModel {
// output
let authentications = CurrentValueSubject<[Item], Never>([])
let activeUserID = CurrentValueSubject<Mastodon.Entity.Account.ID?, Never>(nil)
var diffableDataSource: UITableViewDiffableDataSource<Section, Item>!
init(context: AppContext) {
self.context = context
context.authenticationService.mastodonAuthentications
.map { authentications in
return authentications.map {
Item.authentication(objectID: $0.objectID)
Publishers.CombineLatest(
context.authenticationService.mastodonAuthentications,
context.authenticationService.activeMastodonAuthentication
)
.sink { [weak self] authentications, activeAuthentication in
guard let self = self else { return }
var items: [Item] = []
var activeUserID: Mastodon.Entity.Account.ID?
for authentication in authentications {
let item = Item.authentication(objectID: authentication.objectID)
items.append(item)
if authentication === activeAuthentication {
activeUserID = authentication.userID
}
}
.assign(to: \.value, on: authentications)
.store(in: &disposeBag)
self.authentications.value = items
self.activeUserID.value = activeUserID
}
.store(in: &disposeBag)
authentications
.receive(on: DispatchQueue.main)
@ -72,7 +85,11 @@ extension AccountListViewModel {
let authentication = managedObjectContext.object(with: objectID) as! MastodonAuthentication
let user = authentication.user
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AccountListTableViewCell.self), for: indexPath) as! AccountListTableViewCell
AccountListViewModel.configure(cell: cell, user: user)
AccountListViewModel.configure(
cell: cell,
user: user,
activeUserID: self.activeUserID.eraseToAnyPublisher()
)
return cell
case .addAccount:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AddAccountTableViewCell.self), for: indexPath) as! AddAccountTableViewCell
@ -87,7 +104,8 @@ extension AccountListViewModel {
static func configure(
cell: AccountListTableViewCell,
user: MastodonUser
user: MastodonUser,
activeUserID: AnyPublisher<Mastodon.Entity.Account.ID?, Never>
) {
// avatar
cell.configure(with: AvatarConfigurableViewConfiguration(avatarImageURL: user.avatarImageURL()))
@ -103,6 +121,17 @@ extension AccountListViewModel {
}
// username
cell.usernameLabel.configure(content: PlaintextMetaContent(string: user.acctWithDomain))
let usernameMetaContent = PlaintextMetaContent(string: "@" + user.acctWithDomain)
cell.usernameLabel.configure(content: usernameMetaContent)
// checkmark
activeUserID
.receive(on: DispatchQueue.main)
.sink { userID in
let isCurrentUser = user.id == userID
cell.tintColor = .label
cell.accessoryType = isCurrentUser ? .checkmark : .none
}
.store(in: &cell.disposeBag)
}
}

View File

@ -96,6 +96,14 @@ extension AccountListViewController {
tableView: tableView,
managedObjectContext: context.managedObjectContext
)
if UIAccessibility.isVoiceOverRunning {
let dragIndicatorTapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
dragIndicatorView.addGestureRecognizer(dragIndicatorTapGestureRecognizer)
dragIndicatorTapGestureRecognizer.addTarget(self, action: #selector(AccountListViewController.dragIndicatorTapGestureRecognizerHandler(_:)))
dragIndicatorView.isAccessibilityElement = true
dragIndicatorView.accessibilityLabel = "Dismiss Account Switcher"
}
}
private func setupBackgroundColor(theme: Theme) {
@ -110,6 +118,11 @@ extension AccountListViewController {
logger.debug("\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
coordinator.present(scene: .welcome, from: self, transition: .modal(animated: true, completion: nil))
}
@objc private func dragIndicatorTapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
dismiss(animated: true, completion: nil)
}
}

View File

@ -6,26 +6,24 @@
//
import UIKit
import Combine
import FLAnimatedImage
import MetaTextKit
final class CircleAvatarButton: AvatarButton {
override func layoutSubviews() {
super.layoutSubviews()
layer.masksToBounds = true
layer.cornerRadius = frame.width * 0.5
layer.borderColor = UIColor.systemFill.cgColor
layer.borderWidth = 1
}
}
final class AccountListTableViewCell: UITableViewCell {
var disposeBag = Set<AnyCancellable>()
let avatarButton = CircleAvatarButton()
let avatarButton = CircleAvatarButton(frame: .zero)
let nameLabel = MetaLabel(style: .accountListName)
let usernameLabel = MetaLabel(style: .accountListUsername)
let separatorLine = UIView.separatorLine
override func prepareForReuse() {
super.prepareForReuse()
disposeBag.removeAll()
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
@ -79,7 +77,7 @@ extension AccountListTableViewCell {
contentView.addSubview(separatorLine)
NSLayoutConstraint.activate([
separatorLine.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor),
separatorLine.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
separatorLine.trailingAnchor.constraint(equalTo: trailingAnchor), // needs align to edge
separatorLine.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
separatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: contentView)),
])

View File

@ -0,0 +1,124 @@
//
// MainTabBarController+Wizard.swift
// Mastodon
//
// Created by Cirno MainasuK on 2021-9-15.
//
import os.log
import UIKit
protocol WizardDelegate: AnyObject {
func spotlight(item: MainTabBarController.Wizard.Item) -> UIBezierPath
func layoutWizardCard(_ wizard: MainTabBarController.Wizard, item: MainTabBarController.Wizard.Item)
}
extension MainTabBarController {
class Wizard {
let logger = Logger(subsystem: "Wizard", category: "UI")
weak var delegate: WizardDelegate?
private(set) var items: [Item]
let backgroundView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.black.withAlphaComponent(0.7)
return view
}()
init() {
var items: [Item] = []
if !UserDefaults.shared.didShowMultipleAccountSwitchWizard {
items.append(.multipleAccountSwitch)
}
self.items = items
let backgroundTapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
backgroundTapGestureRecognizer.addTarget(self, action: #selector(MainTabBarController.Wizard.backgroundTapGestureRecognizerHandler(_:)))
backgroundView.addGestureRecognizer(backgroundTapGestureRecognizer)
}
}
}
extension MainTabBarController.Wizard {
enum Item {
case multipleAccountSwitch
var title: String {
return "New in Mastodon"
}
var description: String {
switch self {
case .multipleAccountSwitch:
return "Switch between multiple accounts by holding the profile button."
}
}
}
}
extension MainTabBarController.Wizard {
func setup(in view: UIView) {
assert(delegate != nil, "need set delegate before use")
backgroundView.frame = view.bounds
backgroundView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(backgroundView)
NSLayoutConstraint.activate([
backgroundView.topAnchor.constraint(equalTo: view.topAnchor),
backgroundView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
backgroundView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
backgroundView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
}
func consume() {
guard !items.isEmpty else {
backgroundView.removeFromSuperview()
return
}
let item = items.removeFirst()
perform(item: item)
}
private func perform(item: Item) {
guard let delegate = delegate else {
assertionFailure()
return
}
prepareForReuse()
// add spotlight
let spotlight = delegate.spotlight(item: item)
let maskLayer = CAShapeLayer()
let path = UIBezierPath(rect: backgroundView.bounds)
path.append(spotlight)
maskLayer.fillRule = .evenOdd
maskLayer.path = path.cgPath
backgroundView.layer.mask = maskLayer
// layout wizard card
delegate.layoutWizardCard(self, item: item)
}
private func prepareForReuse() {
backgroundView.subviews.forEach { subview in
subview.removeFromSuperview()
}
backgroundView.mask = nil
backgroundView.layer.mask = nil
}
}
extension MainTabBarController.Wizard {
@objc private func backgroundTapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
// TODO: toggle current item preference flag
consume()
}
}

View File

@ -18,7 +18,12 @@ class MainTabBarController: UITabBarController {
weak var context: AppContext!
weak var coordinator: SceneCoordinator!
static let avatarButtonSize = CGSize(width: 28, height: 28)
let avatarButton = CircleAvatarButton()
let wizard = Wizard()
var currentTab = Tab.home
enum Tab: Int, CaseIterable {
@ -210,6 +215,31 @@ extension MainTabBarController {
self.coordinator.present(scene: .thread(viewModel: threadViewModel), from: nil, transition: .show)
}
.store(in: &disposeBag)
layoutAvatarButton()
context.authenticationService.activeMastodonAuthentication
.receive(on: DispatchQueue.main)
.sink { [weak self] activeMastodonAuthentication in
guard let self = self else { return }
let avatarImageURL = activeMastodonAuthentication?.user.avatarImageURL()
self.avatarButton.avatarImageView.setImage(
url: avatarImageURL,
placeholder: .placeholder(color: .systemFill),
scaleToSize: MainTabBarController.avatarButtonSize
)
// a11y
let _profileTabItem = self.tabBar.items?.first { item in item.tag == Tab.me.tag }
guard let profileTabItem = _profileTabItem else { return }
let currentUserDisplayName = activeMastodonAuthentication?.user.displayNameWithFallback ?? "no user"
profileTabItem.accessibilityHint = "Current selected profile: \(currentUserDisplayName). Double tap then hold to show account switcher"
}
.store(in: &disposeBag)
wizard.delegate = self
wizard.setup(in: view)
let tabBarLongPressGestureRecognizer = UILongPressGestureRecognizer()
tabBarLongPressGestureRecognizer.addTarget(self, action: #selector(MainTabBarController.tabBarLongPressGestureRecognizerHandler(_:)))
@ -219,6 +249,12 @@ extension MainTabBarController {
// selectedIndex = 1
#endif
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
wizard.consume()
}
}
@ -249,6 +285,38 @@ extension MainTabBarController {
}
}
extension MainTabBarController {
private func layoutAvatarButton() {
guard avatarButton.superview == nil else { return }
let _profileTabItem = self.tabBar.items?.first { item in item.tag == Tab.me.tag }
guard let profileTabItem = _profileTabItem else { return }
guard let view = profileTabItem.value(forKey: "view") as? UIView else {
return
}
let _anchorImageView = view.subviews.first { subview in subview is UIImageView } as? UIImageView
guard let anchorImageView = _anchorImageView else {
assertionFailure()
return
}
anchorImageView.alpha = 0
self.avatarButton.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(self.avatarButton)
NSLayoutConstraint.activate([
self.avatarButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
self.avatarButton.centerYAnchor.constraint(equalTo: anchorImageView.centerYAnchor),
self.avatarButton.widthAnchor.constraint(equalToConstant: MainTabBarController.avatarButtonSize.width).priority(.required - 1),
self.avatarButton.heightAnchor.constraint(equalToConstant: MainTabBarController.avatarButtonSize.height).priority(.required - 1),
])
self.avatarButton.setContentHuggingPriority(.required - 1, for: .horizontal)
self.avatarButton.setContentHuggingPriority(.required - 1, for: .vertical)
self.avatarButton.isUserInteractionEnabled = false
}
}
extension MainTabBarController {
var notificationViewController: NotificationViewController? {
@ -277,6 +345,53 @@ extension MainTabBarController: UITabBarControllerDelegate {
}
}
// MARK: - WizardDataSource
extension MainTabBarController: WizardDelegate {
func spotlight(item: Wizard.Item) -> UIBezierPath {
switch item {
case .multipleAccountSwitch:
guard let avatarButtonFrameInView = avatarButtonFrameInView() else {
return UIBezierPath()
}
return UIBezierPath(ovalIn: avatarButtonFrameInView)
}
}
func layoutWizardCard(_ wizard: MainTabBarController.Wizard, item: Wizard.Item) {
switch item {
case .multipleAccountSwitch:
guard let avatarButtonFrameInView = avatarButtonFrameInView() else {
return
}
let anchorView = UIView()
anchorView.frame = avatarButtonFrameInView
wizard.backgroundView.addSubview(anchorView)
let wizardCardView = WizardCardView()
wizardCardView.arrowRectCorner = view.traitCollection.layoutDirection == .leftToRight ? .bottomRight : .bottomLeft
wizardCardView.titleLabel.text = item.title
wizardCardView.descriptionLabel.text = item.description
wizardCardView.translatesAutoresizingMaskIntoConstraints = false
wizard.backgroundView.addSubview(wizardCardView)
NSLayoutConstraint.activate([
anchorView.topAnchor.constraint(equalTo: wizardCardView.bottomAnchor, constant: 13), // 13pt spacing
wizardCardView.trailingAnchor.constraint(equalTo: anchorView.centerXAnchor),
wizardCardView.widthAnchor.constraint(equalTo: wizard.backgroundView.widthAnchor, multiplier: 2.0/3.0).priority(.required - 1),
])
wizardCardView.setContentHuggingPriority(.defaultLow, for: .vertical)
}
}
private func avatarButtonFrameInView() -> CGRect? {
guard let superview = avatarButton.superview else {
assertionFailure()
return nil
}
return superview.convert(avatarButton.frame, to: view)
}
}
// HIG: keyboard UX
// https://developer.apple.com/design/human-interface-guidelines/macos/user-interaction/keyboard/

View File

@ -0,0 +1,110 @@
//
// WizardCardView.swift
// Mastodon
//
// Created by Cirno MainasuK on 2021-9-15.
//
import UIKit
final class WizardCardView: UIView {
static let bubbleArrowHeight: CGFloat = 17
static let bubbleArrowWidth: CGFloat = 20
let contentView = UIView()
let backgroundShapeLayer = CAShapeLayer()
var arrowRectCorner: UIRectCorner = .bottomRight
let titleLabel: UILabel = {
let label = UILabel()
label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 15, weight: .semibold))
label.textColor = .black
return label
}()
let descriptionLabel: UILabel = {
let label = UILabel()
label.font = UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .systemFont(ofSize: 13, weight: .regular))
label.textColor = .black
label.numberOfLines = 0
return label
}()
override init(frame: CGRect) {
super.init(frame: frame)
_init()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
_init()
}
}
extension WizardCardView {
private func _init() {
layer.masksToBounds = false
layer.addSublayer(backgroundShapeLayer)
contentView.translatesAutoresizingMaskIntoConstraints = false
addSubview(contentView)
NSLayoutConstraint.activate([
contentView.topAnchor.constraint(equalTo: topAnchor, constant: WizardCardView.bubbleArrowHeight),
contentView.leadingAnchor.constraint(equalTo: leadingAnchor),
trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: WizardCardView.bubbleArrowHeight),
])
let containerStackView = UIStackView()
containerStackView.axis = .vertical
containerStackView.spacing = 2
containerStackView.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(containerStackView)
NSLayoutConstraint.activate([
containerStackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 5),
containerStackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 7),
contentView.trailingAnchor.constraint(equalTo: containerStackView.trailingAnchor, constant: 24),
contentView.bottomAnchor.constraint(equalTo: containerStackView.bottomAnchor, constant: 5),
])
containerStackView.addArrangedSubview(titleLabel)
containerStackView.addArrangedSubview(descriptionLabel)
}
override func layoutSubviews() {
super.layoutSubviews()
let radius: CGFloat = 5
let rect = contentView.frame
let path = UIBezierPath()
switch arrowRectCorner {
case .bottomRight:
path.move(to: CGPoint(x: rect.maxX - WizardCardView.bubbleArrowWidth, y: rect.maxY + radius))
path.addArc(withCenter: CGPoint(x: rect.minX, y: rect.maxY), radius: radius, startAngle: .pi / 2, endAngle: .pi, clockwise: true)
path.addArc(withCenter: CGPoint(x: rect.minX, y: rect.minY), radius: radius, startAngle: .pi, endAngle: .pi / 2 * 3, clockwise: true)
path.addArc(withCenter: CGPoint(x: rect.maxX, y: rect.minY), radius: radius, startAngle: .pi / 2 * 3, endAngle: .pi * 2, clockwise: true)
path.addLine(to: CGPoint(x: rect.maxX + radius, y: rect.maxY + radius + WizardCardView.bubbleArrowHeight))
path.close()
case .bottomLeft:
path.move(to: CGPoint(x: rect.minX + WizardCardView.bubbleArrowWidth, y: rect.maxY + radius))
path.addArc(withCenter: CGPoint(x: rect.maxX, y: rect.maxY), radius: radius, startAngle: .pi / 2, endAngle: 0, clockwise: false)
path.addArc(withCenter: CGPoint(x: rect.maxX, y: rect.minY), radius: radius, startAngle: 0, endAngle: -.pi / 2, clockwise: false)
path.addArc(withCenter: CGPoint(x: rect.minX, y: rect.minY), radius: radius, startAngle: -.pi / 2, endAngle: -.pi, clockwise: false)
path.addLine(to: CGPoint(x: rect.minX - radius, y: rect.maxY + radius + WizardCardView.bubbleArrowHeight))
path.close()
default:
assertionFailure("FIXME")
}
backgroundShapeLayer.lineCap = .round
backgroundShapeLayer.lineJoin = .round
backgroundShapeLayer.lineWidth = 3
backgroundShapeLayer.strokeColor = UIColor.white.cgColor
backgroundShapeLayer.fillColor = UIColor.white.cgColor
backgroundShapeLayer.path = path.cgPath
}
}

View File

@ -7,15 +7,21 @@
import os.log
import UIKit
import Combine
final class WelcomeViewController: UIViewController, NeedsDependency {
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
var disposeBag = Set<AnyCancellable>()
private(set) lazy var viewModel = WelcomeViewModel(context: context)
let welcomeIllustrationView = WelcomeIllustrationView()
var welcomeIllustrationViewBottomAnchorLayoutConstraint: NSLayoutConstraint?
private(set) lazy var dismissBarButtonItem = UIBarButtonItem(barButtonSystemItem: .close, target: self, action: #selector(WelcomeViewController.dismissBarButtonItemDidPressed(_:)))
private(set) lazy var logoImageView: UIImageView = {
let image = view.traitCollection.userInterfaceIdiom == .phone ? Asset.Scene.Welcome.mastodonLogo.image : Asset.Scene.Welcome.mastodonLogoBlackLarge.image
let imageView = UIImageView(image: image)
@ -90,6 +96,14 @@ extension WelcomeViewController {
signUpButton.addTarget(self, action: #selector(signUpButtonDidClicked(_:)), for: .touchUpInside)
signInButton.addTarget(self, action: #selector(signInButtonDidClicked(_:)), for: .touchUpInside)
viewModel.needsShowDismissEntry
.receive(on: DispatchQueue.main)
.sink { [weak self] needsShowDismissEntry in
guard let self = self else { return }
self.navigationItem.leftBarButtonItem = needsShowDismissEntry ? self.dismissBarButtonItem : nil
}
.store(in: &disposeBag)
}
override func viewSafeAreaInsetsDidChange() {
@ -213,6 +227,11 @@ extension WelcomeViewController {
private func signInButtonDidClicked(_ sender: UIButton) {
coordinator.present(scene: .mastodonPickServer(viewMode: MastodonPickServerViewModel(context: context, mode: .signIn)), from: self, transition: .show)
}
@objc
private func dismissBarButtonItemDidPressed(_ sender: UIButton) {
dismiss(animated: true, completion: nil)
}
}
// MARK: - OnboardingViewControllerAppearance

View File

@ -0,0 +1,30 @@
//
// WelcomeViewModel.swift
// Mastodon
//
// Created by Cirno MainasuK on 2021-9-15.
//
import Foundation
import Combine
final class WelcomeViewModel {
var disposeBag = Set<AnyCancellable>()
// input
let context: AppContext
// output
let needsShowDismissEntry = CurrentValueSubject<Bool, Never>(false)
init(context: AppContext) {
self.context = context
context.authenticationService.mastodonAuthentications
.map { !$0.isEmpty }
.assign(to: \.value, on: needsShowDismissEntry)
.store(in: &disposeBag)
}
}

View File

@ -28,6 +28,7 @@ class AvatarButton: UIControl {
}
func _init() {
avatarImageView.frame = bounds
avatarImageView.translatesAutoresizingMaskIntoConstraints = false
addSubview(avatarImageView)
NSLayoutConstraint.activate([

View File

@ -0,0 +1,20 @@
//
// CircleAvatarButton.swift
// Mastodon
//
// Created by Cirno MainasuK on 2021-9-15.
//
import UIKit
final class CircleAvatarButton: AvatarButton {
override func layoutSubviews() {
super.layoutSubviews()
layer.masksToBounds = true
layer.cornerRadius = frame.width * 0.5
layer.borderColor = UIColor.systemFill.cgColor
layer.borderWidth = 1
}
}

View File

@ -121,7 +121,7 @@ final class StatusNode: ASCellNode {
// }
for imageNode in mediaMultiplexImageNodes {
imageNode.dataSource = self
imageNode.delegate = self
}
}