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

[Chore] Tab -> KeyboardTab (because of SwiftUI.Tab) #470

Merged
merged 1 commit into from
Jun 21, 2024
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Tab.swift
// KeyboardTab.swift
// azooKey
//
// Created by ensan on 2022/12/20.
Expand All @@ -14,7 +14,7 @@ public enum UpsideComponent: Equatable, Sendable {
case search([ConverterBehaviorSemantics.ReplacementTarget])
}

public enum Tab: Equatable {
public enum KeyboardTab: Equatable {
case existential(ExistentialTab)
case user_dependent(UserDependentTab)
case last_tab
Expand Down
40 changes: 20 additions & 20 deletions AzooKeyCore/Sources/KeyboardViews/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import enum KanaKanjiConverterModule.InputStyle
import enum KanaKanjiConverterModule.KeyboardLanguage

extension TabData {
func tab(config: any TabManagerConfiguration) -> Tab {
func tab(config: any TabManagerConfiguration) -> KeyboardTab {
switch self {
case let .system(tab):
switch tab {
Expand Down Expand Up @@ -73,11 +73,11 @@ public struct TabManager {
private var lastTab: ManagerTab?

public enum ManagerTab {
case existential(Tab.ExistentialTab)
case user_dependent(Tab.UserDependentTab)
case existential(KeyboardTab.ExistentialTab)
case user_dependent(KeyboardTab.UserDependentTab)
}

@MainActor func inputStyle(of tab: Tab) -> InputStyle {
@MainActor func inputStyle(of tab: KeyboardTab) -> InputStyle {
switch tab {
case let .existential(tab):
return tab.inputStyle
Expand All @@ -89,7 +89,7 @@ public struct TabManager {
}
}

@MainActor func layout(of tab: Tab) -> KeyboardLayout {
@MainActor func layout(of tab: KeyboardTab) -> KeyboardLayout {
switch tab {
case let .existential(tab):
return tab.layout
Expand All @@ -101,7 +101,7 @@ public struct TabManager {
}
}

@MainActor func language(of tab: Tab) -> KeyboardLanguage? {
@MainActor func language(of tab: KeyboardTab) -> KeyboardLanguage? {
switch tab {
case let .existential(tab):
return tab.language
Expand All @@ -113,7 +113,7 @@ public struct TabManager {
}
}

@MainActor static func existentialTab(of tab: ManagerTab, config: any TabManagerConfiguration) -> Tab.ExistentialTab {
@MainActor static func existentialTab(of tab: ManagerTab, config: any TabManagerConfiguration) -> KeyboardTab.ExistentialTab {
switch tab {
case let .existential(tab):
return tab
Expand All @@ -122,11 +122,11 @@ public struct TabManager {
}
}

@MainActor public func existentialTab() -> Tab.ExistentialTab {
@MainActor public func existentialTab() -> KeyboardTab.ExistentialTab {
Self.existentialTab(of: self.tab, config: config)
}

@MainActor static func actualTab(of tab: Tab.UserDependentTab, config: any TabManagerConfiguration) -> Tab.ExistentialTab {
@MainActor static func actualTab(of tab: KeyboardTab.UserDependentTab, config: any TabManagerConfiguration) -> KeyboardTab.ExistentialTab {
// ユーザの設定に合わせて遷移先のタブ(非user_dependent)を返す
switch tab {
case .english:
Expand All @@ -150,7 +150,7 @@ public struct TabManager {
}
}

@MainActor func isCurrentTab(tab: Tab) -> Bool {
@MainActor func isCurrentTab(tab: KeyboardTab) -> Bool {
switch tab {
case let .existential(actualTab):
return Self.existentialTab(of: self.tab, config: config) == actualTab
Expand All @@ -164,7 +164,7 @@ public struct TabManager {
@MainActor mutating func initialize(variableStates: VariableStates) {
switch lastTab {
case .none:
let targetTab: Tab = {
let targetTab: KeyboardTab = {
switch config.preferredLanguage.first {
case .en_US:
return .user_dependent(.english)
Expand All @@ -186,7 +186,7 @@ public struct TabManager {
self.lastTab = self.currentTab
}

@MainActor mutating private func moveTab(to destination: Tab.ExistentialTab, variableStates: VariableStates) {
@MainActor mutating private func moveTab(to destination: KeyboardTab.ExistentialTab, variableStates: VariableStates) {
// VariableStateの状態を遷移先のタブに合わせて適切に変更する
variableStates.setKeyboardLayout(destination.layout)
variableStates.setInputStyle(destination.inputStyle)
Expand All @@ -209,19 +209,19 @@ public struct TabManager {
}
}

@MainActor private static func getDefaultTab(config: any TabManagerConfiguration) -> (existentialTab: Tab.ExistentialTab, managerTab: ManagerTab) {
@MainActor private static func getDefaultTab(config: any TabManagerConfiguration) -> (existentialTab: KeyboardTab.ExistentialTab, managerTab: ManagerTab) {
switch config.preferredLanguage.first {
case .ja_JP:
return (actualTab(of: Tab.UserDependentTab.japanese, config: config), .user_dependent(.japanese))
return (actualTab(of: KeyboardTab.UserDependentTab.japanese, config: config), .user_dependent(.japanese))
case .en_US:
return (actualTab(of: Tab.UserDependentTab.english, config: config), .user_dependent(.english))
return (actualTab(of: KeyboardTab.UserDependentTab.english, config: config), .user_dependent(.english))
default:
return (actualTab(of: Tab.UserDependentTab.japanese, config: config), .user_dependent(.japanese))
return (actualTab(of: KeyboardTab.UserDependentTab.japanese, config: config), .user_dependent(.japanese))
}
}

@MainActor mutating func setTemporalTab(_ destination: Tab, variableStates: VariableStates) {
let actualTab: Tab.ExistentialTab
@MainActor mutating func setTemporalTab(_ destination: KeyboardTab, variableStates: VariableStates) {
let actualTab: KeyboardTab.ExistentialTab
switch destination {
case let .existential(tab):
self.updateVariableStates(variableStates, layout: tab.layout, inputStyle: tab.inputStyle, language: tab.language)
Expand All @@ -241,7 +241,7 @@ public struct TabManager {
}
}

@MainActor mutating func moveTab(to destination: Tab, variableStates: VariableStates) {
@MainActor mutating func moveTab(to destination: KeyboardTab, variableStates: VariableStates) {
switch destination {
case let .existential(tab):
self.updateVariableStates(variableStates, layout: tab.layout, inputStyle: tab.inputStyle, language: tab.language)
Expand All @@ -263,7 +263,7 @@ public struct TabManager {

case .last_tab:
// 適切なタブを取得する
let actualTab: Tab.ExistentialTab
let actualTab: KeyboardTab.ExistentialTab
if let lastTab,
Self.existentialTab(of: lastTab, config: config) != Self.existentialTab(of: currentTab, config: config) {
actualTab = Self.existentialTab(of: lastTab, config: config)
Expand Down
2 changes: 1 addition & 1 deletion AzooKeyCore/Sources/KeyboardViews/VariableStates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public final class VariableStates: ObservableObject {
}
}

@MainActor private func setTab(_ tab: Tab, temporary: Bool = false) {
@MainActor private func setTab(_ tab: KeyboardTab, temporary: Bool = false) {
if temporary {
self.tabManager.setTemporalTab(tab, variableStates: self)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ struct FlickTabKeyModel<Extension: ApplicationSpecificKeyboardViewExtension>: Fl
self.data.flick
}

private var tab: Tab
private var tab: KeyboardTab

@MainActor private init(tab: Tab, key: CustomizableFlickKey) {
@MainActor private init(tab: KeyboardTab, key: CustomizableFlickKey) {
self.data = Extension.SettingProvider.get(key)
self.tab = tab
}
Expand Down
6 changes: 3 additions & 3 deletions AzooKeyCore/Sources/KeyboardViews/View/KeyboardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public struct KeyboardView<Extension: ApplicationSpecificKeyboardViewExtension>:
@Environment(\.showMessage) private var showMessage
@EnvironmentObject private var variableStates: VariableStates

private let defaultTab: Tab.ExistentialTab?
private let defaultTab: KeyboardTab.ExistentialTab?

public init(defaultTab: Tab.ExistentialTab? = nil) {
public init(defaultTab: KeyboardTab.ExistentialTab? = nil) {
self.defaultTab = defaultTab
}

Expand Down Expand Up @@ -89,7 +89,7 @@ public struct KeyboardView<Extension: ApplicationSpecificKeyboardViewExtension>:
}

@MainActor @ViewBuilder
func keyboardView(tab: Tab.ExistentialTab) -> some View {
func keyboardView(tab: KeyboardTab.ExistentialTab) -> some View {
switch tab {
case .flick_hira:
FlickKeyboardView<Extension>(keyModels: FlickDataProvider<Extension>.hiraKeyboard, interfaceSize: variableStates.interfaceSize, keyboardOrientation: variableStates.keyboardOrientation)
Expand Down
4 changes: 2 additions & 2 deletions MainApp/General/KeyboardPreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct KeyboardPreview: View {
private let theme: AzooKeyTheme

private let scale: CGFloat
private let defaultTab: Tab.ExistentialTab?
private let defaultTab: KeyboardTab.ExistentialTab?
@StateObject private var variableStates = VariableStates(
interfaceWidth: UIScreen.main.bounds.width,
orientation: MainAppDesign.keyboardOrientation,
Expand All @@ -35,7 +35,7 @@ struct KeyboardPreview: View {
userDefaults: UserDefaults.standard
)

init(theme: AzooKeyTheme? = nil, scale: CGFloat = 1, defaultTab: Tab.ExistentialTab? = nil) {
init(theme: AzooKeyTheme? = nil, scale: CGFloat = 1, defaultTab: KeyboardTab.ExistentialTab? = nil) {
self.theme = theme ?? AzooKeySpecificTheme.default(layout: defaultTab?.layout ?? .flick)
self.scale = scale
self.defaultTab = defaultTab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct LanguageLayoutSettingView<SettingKey: LanguageLayoutKeyboardSetting>: Vie
}
}

private var tab: Tab.ExistentialTab {
private var tab: KeyboardTab.ExistentialTab {
switch (selection, language) {
case (.flick, .japanese):
return .flick_hira
Expand Down
2 changes: 1 addition & 1 deletion MainApp/Theme/ThemeEditView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ struct ThemeEditView: CancelableEditor {
.foregroundStyle(.red)
}
}
let tab: Tab.ExistentialTab = {
let tab: KeyboardTab.ExistentialTab = {
switch appStates.japaneseLayout {
case .flick:
return .flick_hira
Expand Down
2 changes: 1 addition & 1 deletion MainApp/Theme/ThemeTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct ThemeTabView: View {
)
}

private var tab: Tab.ExistentialTab {
private var tab: KeyboardTab.ExistentialTab {
switch appStates.japaneseLayout {
case .flick:
return .flick_hira
Expand Down
Loading