Skip to content

Commit

Permalink
Merge pull request #376 from ensan-hcl/develop_iOS16_2.2.2
Browse files Browse the repository at this point in the history
[Merge ver 2.2.2]
  • Loading branch information
ensan-hcl authored Nov 13, 2023
2 parents 46686c2 + 7046e17 commit 2c217dd
Show file tree
Hide file tree
Showing 22 changed files with 927 additions and 494 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public enum AzooKeyKeyboardViewExtension: ApplicationSpecificKeyboardViewExtensi
UseShiftKey.value
}

public static var useNextCandidateKey: Bool {
UseNextCandidateKey.value
}

public static var displayCursorBarAutomatically: Bool {
DisplayCursorBarAutomatically.value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ public extension KeyboardSettingKey where Self == UseShiftKey {
static var useShiftKey: Self { .init() }
}

public struct UseNextCandidateKey: BoolKeyboardSettingKey {
public static let title: LocalizedStringKey = "次候補キーを使う"
public static let explanation: LocalizedStringKey = "キーボードで入力中、空白キーに「次候補」機能を表示します"
public static let defaultValue = false
public static let key: String = "use_next_candidate_key"
}

public extension KeyboardSettingKey where Self == UseNextCandidateKey {
static var useNextCandidateKey: Self { .init() }
}

public struct HideResetButtonInOneHandedMode: BoolKeyboardSettingKey {
public static let title: LocalizedStringKey = "片手モードで解除ボタンを表示しない"
public static let explanation: LocalizedStringKey = "片手モードの際に表示される解除ボタンを非表示にします。片手モードの調整はタブバーのボタンから行えます。"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Foundation
static var enablePasteButton: Bool { get }
static var hideResetButtonInOneHandedMode: Bool { get }
static var useShiftKey: Bool { get }
static var useNextCandidateKey: Bool { get }

/// タブバーボタンを表示する
/// - note: このオプションは一度削除を決めたが、ユーザから強い要望があったので維持することにした。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ struct FlickDataProvider<Extension: ApplicationSpecificKeyboardViewExtension> {
Extension.SettingProvider.preferredLanguage
}

// 第5列
@MainActor static func functionalKeys() -> [any FlickKeyModelProtocol<Extension>] {
return [
FlickKeyModel.delete,
Extension.SettingProvider.useNextCandidateKey ? FlickNextCandidateKeyModel.shared : FlickSpaceKeyModel.shared,
FlickEnterKeyModel.shared
]
}

// 第1列
@MainActor static func TabKeys() -> [any FlickKeyModelProtocol<Extension>] {
let first: any FlickKeyModelProtocol<Extension> = {
switch preferredLanguage.first {
Expand Down Expand Up @@ -262,12 +272,7 @@ struct FlickDataProvider<Extension: ApplicationSpecificKeyboardViewExtension> {
FlickKanaSymbolsKeyModel.shared
],
// 第5列
[
FlickKeyModel.delete,
FlickSpaceKeyModel.shared,
FlickEnterKeyModel.shared
]

Self.functionalKeys()
]
}

Expand Down Expand Up @@ -426,11 +431,7 @@ struct FlickDataProvider<Extension: ApplicationSpecificKeyboardViewExtension> {
])
],
// 第5列
[
FlickKeyModel.delete,
FlickSpaceKeyModel.shared,
FlickEnterKeyModel.shared
]
Self.functionalKeys()
]
}
// 縦に並べる
Expand Down Expand Up @@ -617,11 +618,7 @@ struct FlickDataProvider<Extension: ApplicationSpecificKeyboardViewExtension> {
])
],
// 第5列
[
FlickKeyModel.delete,
FlickSpaceKeyModel.shared,
FlickEnterKeyModel.shared
]
Self.functionalKeys()
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,25 @@ struct FlickNextCandidateKeyModel<Extension: ApplicationSpecificKeyboardViewExte
if variableStates.resultModel.results.isEmpty {
.init(start: [.setCursorBar(.toggle)])
} else {
.init(start: [.input(" ")])
.init(repeat: [.selectCandidate(.offset(1))])
}
}
func flickKeys(variableStates: VariableStates) -> [CustardKit.FlickDirection: FlickedKeyModel] {
[
.left: FlickedKeyModel(
let leftFlickKey = if variableStates.resultModel.selection != nil {
FlickedKeyModel(
labelType: .text("前候補"),
pressActions: [.selectCandidate(.offset(-1))],
longPressActions: .init(repeat: [.selectCandidate(.offset(-1))])
)
} else {
FlickedKeyModel(
labelType: .text(""),
pressActions: [.moveCursor(-1)],
longPressActions: .init(repeat: [.moveCursor(-1)])
),
)
}
return [
.left: leftFlickKey,
.top: FlickedKeyModel(
labelType: .text("全角"),
pressActions: [.input(" ")]
Expand Down
97 changes: 54 additions & 43 deletions AzooKeyCore/Sources/KeyboardViews/View/KeyboardBar/ResultBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ struct ResultBar<Extension: ApplicationSpecificKeyboardViewExtension>: View {
tabBarButton
}
if let undoButtonAction {
Button {
Button("取り消す", systemImage: "arrow.uturn.backward") {
KeyboardFeedback<Extension>.click()
self.action.registerAction(undoButtonAction.action, variableStates: variableStates)
} label: {
Label("取り消す", systemImage: "arrow.uturn.backward")
}
.buttonStyle(ResultButtonStyle<Extension>(height: buttonHeight))
}
Expand Down Expand Up @@ -103,7 +101,7 @@ struct ResultBar<Extension: ApplicationSpecificKeyboardViewExtension>: View {
KeyboardFeedback<Extension>.click()
self.pressed(candidate: data.candidate)
}
.buttonStyle(ResultButtonStyle<Extension>(height: buttonHeight, selected: data.id == variableStates.resultModel.selection))
.buttonStyle(ResultButtonStyle<Extension>(height: buttonHeight, selected: .init(selection: variableStates.resultModel.selection, index: data.id)))
.contextMenu {
ResultContextMenuView(candidate: data.candidate, displayResetLearningButton: Extension.SettingProvider.canResetLearningForCandidate, index: data.id)
}
Expand All @@ -121,7 +119,7 @@ struct ResultBar<Extension: ApplicationSpecificKeyboardViewExtension>: View {
.onChange(of: variableStates.resultModel.selection) { value in
if let value {
withAnimation(.easeIn(duration: 0.05)) {
scrollViewProxy.scrollTo(value, anchor: .trailing)
scrollViewProxy.scrollTo(value, anchor: .center)
}
}
}
Expand All @@ -146,7 +144,7 @@ struct ResultBar<Extension: ApplicationSpecificKeyboardViewExtension>: View {
}
}
}
.animation(.easeIn(duration: 0.2), value: variableStates.resultModel.displayState)
.animation(.easeIn(duration: 0.2), value: variableStates.resultModel.displayState == .nothing)
}

private func pressed(candidate: any ResultViewItemData) {
Expand All @@ -172,68 +170,81 @@ struct ResultContextMenuView: View {
}

var body: some View {
Group {
Button(action: {
variableStates.magnifyingText = candidate.text
variableStates.boolStates.isTextMagnifying = true
}) {
Text("大きな文字で表示する")
Image(systemName: "plus.magnifyingglass")
}
if displayResetLearningButton {
Button(action: {
action.notifyForgetCandidate(candidate, variableStates: variableStates)
}) {
Text("この候補の学習をリセットする")
Image(systemName: "clear")
}
Button("大きな文字で表示", systemImage: "plus.magnifyingglass") {
variableStates.magnifyingText = candidate.text
variableStates.boolStates.isTextMagnifying = true
}
if displayResetLearningButton {
Button("この候補の学習をリセットする", systemImage: "clear") {
action.notifyForgetCandidate(candidate, variableStates: variableStates)
}
if SemiStaticStates.shared.hasFullAccess {
Button {
Task { @MainActor in
await action.notifyReportWrongConversion(candidate, index: index, variableStates: variableStates)
}
} label: {
Label("誤変換を報告", systemImage: "exclamationmark.bubble")
}
if SemiStaticStates.shared.hasFullAccess {
Button("誤変換を報告", systemImage: "exclamationmark.bubble") {
Task { @MainActor in
await action.notifyReportWrongConversion(candidate, index: index, variableStates: variableStates)
}
}
#if DEBUG
Button(action: {
debug(self.candidate.getDebugInformation())
}) {
Text("デバッグ情報を表示する")
Image(systemName: "ladybug.fill")
}
#endif
}
#if DEBUG
Button("デバッグ情報を表示する", systemImage: "ladybug.fill"){
debug(self.candidate.getDebugInformation())
}
#endif
}
}

struct ResultButtonStyle<Extension: ApplicationSpecificKeyboardViewExtension>: ButtonStyle {
enum SelectionState: Sendable {
case nothing
case this
case other
init(selection: Int?, index: Int) {
if let selection {
if selection == index {
self = .this
} else {
self = .other
}
} else {
self = .nothing
}
}
}
private let height: CGFloat
private let userSizePreference: Double
private let selected: Bool
private let selected: SelectionState

@Environment(Extension.Theme.self) private var theme

@MainActor init(height: CGFloat, selected: Bool = false) {
@MainActor init(height: CGFloat, selected: SelectionState = .nothing) {
self.userSizePreference = Extension.SettingProvider.resultViewFontSize
self.height = height
self.selected = selected
}

private func background(configuration: Configuration) -> any ShapeStyle {
if configuration.isPressed {
theme.pushedKeyFillColor.color.opacity(0.5)
} else {
switch self.selected {
case .nothing: theme.resultBackgroundColor.color
case .this: Material.thin
case .other: theme.resultBackgroundColor.color.opacity(0.5)
}
}
}

func makeBody(configuration: Configuration) -> some View {
configuration.label
.font(Design.fonts.resultViewFont(theme: theme, userSizePrefrerence: self.userSizePreference))
.frame(height: height)
.padding(.all, 5)
.foregroundStyle(theme.resultTextColor.color) // 文字色は常に不透明度1で描画する
.background(
(configuration.isPressed || self.selected) ?
theme.pushedKeyFillColor.color.opacity(0.5) :
theme.resultBackgroundColor.color
)
.background(AnyShapeStyle(background(configuration: configuration)))
.cornerRadius(5.0)
.compositingGroup()
.contentShape(Rectangle())
.animation(nil, value: configuration.isPressed)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ struct QwertyDataProvider<Extension: ApplicationSpecificKeyboardViewExtension> {
)
}

@MainActor static func spaceKey() -> any QwertyKeyModelProtocol {
Extension.SettingProvider.useNextCandidateKey ? QwertyNextCandidateKeyModel<Extension>() : QwertySpaceKeyModel<Extension>()
}

// 横に並べる
@MainActor static var numberKeyboard: [[any QwertyKeyModelProtocol<Extension>]] {[
[
Expand Down Expand Up @@ -240,7 +244,7 @@ struct QwertyDataProvider<Extension: ApplicationSpecificKeyboardViewExtension> {
[
Self.tabKeys(rowInfo: (0, 2, 1, 1)).languageKey,
Self.tabKeys(rowInfo: (0, 2, 1, 1)).changeKeyboardKey,
QwertyNextCandidateKeyModel(),
Self.spaceKey(),
QwertyEnterKeyModel.shared
]
]
Expand Down Expand Up @@ -462,7 +466,7 @@ struct QwertyDataProvider<Extension: ApplicationSpecificKeyboardViewExtension> {
[
Self.tabKeys(rowInfo: (0, 2, 1, 1)).languageKey,
Self.tabKeys(rowInfo: (0, 2, 1, 1)).changeKeyboardKey,
QwertyNextCandidateKeyModel(),
Self.spaceKey(),
QwertyEnterKeyModel.shared
]
]}
Expand Down Expand Up @@ -507,7 +511,7 @@ struct QwertyDataProvider<Extension: ApplicationSpecificKeyboardViewExtension> {
[
Self.tabKeys(rowInfo: (0, 2, 1, 1)).numbersKey,
Self.tabKeys(rowInfo: (0, 2, 1, 1)).changeKeyboardKey,
QwertyNextCandidateKeyModel(),
Self.spaceKey(),
QwertyEnterKeyModel.shared
]
]}
Expand Down Expand Up @@ -564,7 +568,7 @@ struct QwertyDataProvider<Extension: ApplicationSpecificKeyboardViewExtension> {
[
Self.tabKeys(rowInfo: (0, 2, 1, 1)).numbersKey,
Self.tabKeys(rowInfo: (0, 2, 1, 1)).changeKeyboardKey,
QwertyNextCandidateKeyModel(),
Self.spaceKey(),
QwertyEnterKeyModel.shared
]
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,8 @@ struct EmojiTab<Extension: ApplicationSpecificKeyboardViewExtension>: View {
}), width: functionKeyWidth, height: footerHeight)
}

private func tabBarKey() -> SimpleKeyView<Extension> {
SimpleKeyView(model: SimpleKeyModel<Extension>(keyLabelType: .image("list.bullet"), unpressedKeyColorType: .special, pressActions: [.setTabBar(.toggle)], longPressActions: .none), width: functionKeyWidth, height: footerHeight)
}

private func backTabKey() -> SimpleKeyView<Extension> {
SimpleKeyView(model: SimpleKeyModel<Extension>(keyLabelType: .image("arrow.uturn.backward"), unpressedKeyColorType: .special, pressActions: [.moveTab(.system(.last_tab))], longPressActions: .none), width: functionKeyWidth, height: footerHeight)
SimpleKeyView(model: SimpleKeyModel<Extension>(keyLabelType: .text("戻る"), unpressedKeyColorType: .special, pressActions: [.moveTab(.system(.last_tab))], longPressActions: .none), width: functionKeyWidth * 2, height: footerHeight)
}

private func genreKey(_ genre: Genre) -> some View {
Expand Down Expand Up @@ -332,7 +328,6 @@ struct EmojiTab<Extension: ApplicationSpecificKeyboardViewExtension>: View {

HStack(spacing: 0) {
backTabKey()
tabBarKey()
ForEach(allGenre, id: \.self) { genre in
if !self.emojis[genre, default: []].isEmpty {
genreKey(genre)
Expand Down
Loading

0 comments on commit 2c217dd

Please sign in to comment.