feat: add keyboard shortcuts for tabs
This commit is contained in:
parent
11cc256ab1
commit
5cbfa28b93
|
@ -78,7 +78,10 @@
|
|||
"home": "Home",
|
||||
"search": "Search",
|
||||
"notification": "Notification",
|
||||
"profile": "Profile"
|
||||
"profile": "Profile",
|
||||
"keyboard": {
|
||||
"switch_to_tab": "Switch to %s"
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"user_reblogged": "%s reblogged",
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<key>CoreDataStack.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>14</integer>
|
||||
<integer>15</integer>
|
||||
</dict>
|
||||
<key>Mastodon - RTL.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
|
@ -32,7 +32,7 @@
|
|||
<key>NotificationService.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>15</integer>
|
||||
<integer>14</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
|
|
|
@ -278,6 +278,12 @@ internal enum L10n {
|
|||
internal static let profile = L10n.tr("Localizable", "Common.Controls.Tabs.Profile")
|
||||
/// Search
|
||||
internal static let search = L10n.tr("Localizable", "Common.Controls.Tabs.Search")
|
||||
internal enum Keyboard {
|
||||
/// Switch to %@
|
||||
internal static func switchToTab(_ p1: Any) -> String {
|
||||
return L10n.tr("Localizable", "Common.Controls.Tabs.Keyboard.SwitchToTab", String(describing: p1))
|
||||
}
|
||||
}
|
||||
}
|
||||
internal enum Timeline {
|
||||
internal enum Accessibility {
|
||||
|
|
|
@ -91,6 +91,7 @@ Please check your internet connection.";
|
|||
"Common.Controls.Status.UserReblogged" = "%@ reblogged";
|
||||
"Common.Controls.Status.UserRepliedTo" = "Replied to %@";
|
||||
"Common.Controls.Tabs.Home" = "Home";
|
||||
"Common.Controls.Tabs.Keyboard.SwitchToTab" = "Switch to %@";
|
||||
"Common.Controls.Tabs.Notification" = "Notification";
|
||||
"Common.Controls.Tabs.Profile" = "Profile";
|
||||
"Common.Controls.Tabs.Search" = "Search";
|
||||
|
|
|
@ -91,6 +91,7 @@ Please check your internet connection.";
|
|||
"Common.Controls.Status.UserReblogged" = "%@ reblogged";
|
||||
"Common.Controls.Status.UserRepliedTo" = "Replied to %@";
|
||||
"Common.Controls.Tabs.Home" = "Home";
|
||||
"Common.Controls.Tabs.Keyboard.SwitchToTab" = "Switch to %@";
|
||||
"Common.Controls.Tabs.Notification" = "Notification";
|
||||
"Common.Controls.Tabs.Profile" = "Profile";
|
||||
"Common.Controls.Tabs.Search" = "Search";
|
||||
|
|
|
@ -189,3 +189,29 @@ extension MainTabBarController {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
extension MainTabBarController {
|
||||
|
||||
override var keyCommands: [UIKeyCommand]? {
|
||||
var commands: [UIKeyCommand] = []
|
||||
for (i, tab) in Tab.allCases.enumerated() {
|
||||
let title = L10n.Common.Controls.Tabs.Keyboard.switchToTab(tab.title)
|
||||
let input = String(i + 1)
|
||||
let command = UIKeyCommand(title: title, image: nil, action: #selector(MainTabBarController.switchToTab(_:)), input: input, modifierFlags: .control, propertyList: tab.rawValue, alternates: [], discoverabilityTitle: nil, attributes: [], state: .off)
|
||||
commands.append(command)
|
||||
|
||||
}
|
||||
return commands
|
||||
}
|
||||
|
||||
@objc private func switchToTab(_ sender: UIKeyCommand) {
|
||||
guard let rawValue = sender.propertyList as? Int,
|
||||
let tab = Tab(rawValue: rawValue) else { return }
|
||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: %s", ((#file as NSString).lastPathComponent), #line, #function, tab.title)
|
||||
|
||||
guard let index = Tab.allCases.firstIndex(of: tab) else { return }
|
||||
selectedIndex = index
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue