Skip to content

Commit

Permalink
(iOS Keyboard) Adjust key heights and tool bar height
Browse files Browse the repository at this point in the history
  • Loading branch information
bingzheung committed Dec 31, 2024
1 parent 3caab68 commit f4ae4b4
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 99 deletions.
16 changes: 8 additions & 8 deletions Keyboard/SharedModels/KeyboardInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,30 @@ extension KeyboardInterface {
case .phoneLandscape:
return 36
case .phonePortrait:
let screenWidth = screenSize.width
if screenWidth > 300 && screenWidth < 350 {
let minDimension: CGFloat = min(screenSize.width, screenSize.height)
if minDimension > 300 && minDimension < 350 {
// iPhone SE1, iPod touch 7 (320 x 480)
return 48
} else if screenWidth < 385 {
} else if minDimension < 385 {
// iPhone 6s, 7, 8, SE2, SE3 (375 x 667)
// iPhone X, Xs, 11 Pro, 12 mini, 13 mini (375 x 812)
return 53
} else if screenWidth < 405 {
} else if minDimension < 405 {
// iPhone 12, 12 Pro, 13, 13 Pro, 14 (390 x 844)
// iPhone 14 Pro, 15, 15 Pro, 16 (393 x 852)
// iPhone 16 Pro (402 x 874)
return 54
} else if screenWidth < 425 {
} else if minDimension < 425 {
// iPhone 6s Plus, 7 Plus, 8 Plus (414 x 836)
// iPhone Xr, Xs Max, 11, 11 Pro Max (414 x 896)
return 55
} else if screenWidth < 445 {
return 56
} else if minDimension < 445 {
// iPhone 12 Pro Max, 13 Pro Max, 14 Plus (428 x 926)
// iPhone 14 Pro Max, 15 Plus, 15 Pro Max, 16 Plus (430 x 932)
// iPhone 16 Pro Max (440 x 956)
return 56
} else {
let extra: Int = Int(screenWidth - 300) / 20
let extra: Int = Int(minDimension - 300) / 20
return CGFloat(50 + extra)
}
}
Expand Down
3 changes: 3 additions & 0 deletions Keyboard/SharedModels/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ enum CommentStyle: Int {
case aboveCandidates = 1
case belowCandidates = 2
case noComments = 3
var isAbove: Bool { self == .aboveCandidates }
var isBelow: Bool { self == .belowCandidates }
var isHidden: Bool { self == .noComments }
}
enum CommentToneStyle: Int {
case normal = 1
Expand Down
2 changes: 1 addition & 1 deletion Keyboard/SharedModels/PresetConstant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SwiftUI

struct PresetConstant {

static let toolBarHeight: CGFloat = 60
static let toolBarHeight: CGFloat = 56

/// CandidateBoard top-right collapse button
static let collapseWidth: CGFloat = 44
Expand Down
40 changes: 12 additions & 28 deletions Keyboard/SharedViews/CandidateBarScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,19 @@ struct CandidateBarScrollView: View {
) {
ZStack {
Color.interactiveClear
switch commentStyle {
case .aboveCandidates:
ZStack(alignment: .top) {
Color.clear
RomanizationLabel(candidate: candidate, toneStyle: toneStyle)
.padding(.horizontal, 1)
.padding(.top, isCompactKeyboard ? 5 : 3)
.frame(height: 20)
}
Text(text)
.font(isCompactKeyboard ? .candidate : .iPadCandidate)
.minimumScaleFactor(0.4)
.lineLimit(1)
case .belowCandidates:
VStack(spacing: -2) {
Text(text)
.font(isCompactKeyboard ? .candidate : .iPadCandidate)
.minimumScaleFactor(0.4)
.lineLimit(1)
RomanizationLabel(candidate: candidate, toneStyle: toneStyle)
}
.padding(.horizontal, 1)
.padding(.bottom, 8)
case .noComments:
Text(text)
.font(isCompactKeyboard ? .candidate : .iPadCandidate)
.minimumScaleFactor(0.4)
.lineLimit(1)
ZStack(alignment: commentStyle.isBelow ? .bottom : .top) {
Color.clear
RomanizationLabel(candidate: candidate, toneStyle: toneStyle)
.frame(height: 20)
.padding(.horizontal, 1)
.padding(.bottom, commentStyle.isBelow ? 6 : 0)
}
.opacity(commentStyle.isHidden ? 0 : 1)
Text(text)
.font(isCompactKeyboard ? .candidate : .iPadCandidate)
.minimumScaleFactor(0.4)
.lineLimit(1)
.padding(.bottom, commentStyle.isBelow ? 14 : 0)
}
.frame(width: candidate.width)
.frame(maxHeight: .infinity)
Expand Down
40 changes: 12 additions & 28 deletions Keyboard/SharedViews/CandidateBarScrollViewIOS17.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,19 @@ struct CandidateBarScrollViewIOS17: View {
) {
ZStack {
Color.interactiveClear
switch commentStyle {
case .aboveCandidates:
ZStack(alignment: .top) {
Color.clear
RomanizationLabel(candidate: candidate, toneStyle: toneStyle)
.padding(.horizontal, 1)
.padding(.top, isCompactKeyboard ? 5 : 3)
.frame(height: 20)
}
Text(text)
.font(isCompactKeyboard ? .candidate : .iPadCandidate)
.minimumScaleFactor(0.4)
.lineLimit(1)
case .belowCandidates:
VStack(spacing: -2) {
Text(text)
.font(isCompactKeyboard ? .candidate : .iPadCandidate)
.minimumScaleFactor(0.4)
.lineLimit(1)
RomanizationLabel(candidate: candidate, toneStyle: toneStyle)
}
.padding(.horizontal, 1)
.padding(.bottom, 8)
case .noComments:
Text(text)
.font(isCompactKeyboard ? .candidate : .iPadCandidate)
.minimumScaleFactor(0.4)
.lineLimit(1)
ZStack(alignment: commentStyle.isBelow ? .bottom : .top) {
Color.clear
RomanizationLabel(candidate: candidate, toneStyle: toneStyle)
.frame(height: 20)
.padding(.horizontal, 1)
.padding(.bottom, commentStyle.isBelow ? 6 : 0)
}
.opacity(commentStyle.isHidden ? 0 : 1)
Text(text)
.font(isCompactKeyboard ? .candidate : .iPadCandidate)
.minimumScaleFactor(0.4)
.lineLimit(1)
.padding(.bottom, commentStyle.isBelow ? 14 : 0)
}
.frame(width: candidate.width)
.frame(maxHeight: .infinity)
Expand Down
40 changes: 12 additions & 28 deletions Keyboard/SharedViews/CandidateBarScrollViewIOS18.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,19 @@ struct CandidateBarScrollViewIOS18: View {
) {
ZStack {
Color.interactiveClear
switch commentStyle {
case .aboveCandidates:
ZStack(alignment: .top) {
Color.clear
RomanizationLabel(candidate: candidate, toneStyle: toneStyle)
.padding(.horizontal, 1)
.padding(.top, isCompactKeyboard ? 5 : 3)
.frame(height: 20)
}
Text(text)
.font(isCompactKeyboard ? .candidate : .iPadCandidate)
.minimumScaleFactor(0.4)
.lineLimit(1)
case .belowCandidates:
VStack(spacing: -2) {
Text(text)
.font(isCompactKeyboard ? .candidate : .iPadCandidate)
.minimumScaleFactor(0.4)
.lineLimit(1)
RomanizationLabel(candidate: candidate, toneStyle: toneStyle)
}
.padding(.horizontal, 1)
.padding(.bottom, 8)
case .noComments:
Text(text)
.font(isCompactKeyboard ? .candidate : .iPadCandidate)
.minimumScaleFactor(0.4)
.lineLimit(1)
ZStack(alignment: commentStyle.isBelow ? .bottom : .top) {
Color.clear
RomanizationLabel(candidate: candidate, toneStyle: toneStyle)
.frame(height: 20)
.padding(.horizontal, 1)
.padding(.bottom, commentStyle.isBelow ? 6 : 0)
}
.opacity(commentStyle.isHidden ? 0 : 1)
Text(text)
.font(isCompactKeyboard ? .candidate : .iPadCandidate)
.minimumScaleFactor(0.4)
.lineLimit(1)
.padding(.bottom, commentStyle.isBelow ? 14 : 0)
}
.frame(width: candidate.width)
.frame(maxHeight: .infinity)
Expand Down
4 changes: 1 addition & 3 deletions Keyboard/SharedViews/CantoneseABCSwitch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ struct CantoneseABCSwitch: View {
private let partHeight: CGFloat = 26
private let cornerRadius: CGFloat = 5

private var cantoneseLabelText: String { Options.characterStandard.isSimplified ? "" : "" }

var body: some View {
let textBackColor: Color = {
switch colorScheme {
Expand All @@ -35,7 +33,7 @@ struct CantoneseABCSwitch: View {
}
}()
HStack(spacing: 0) {
Text(verbatim: cantoneseLabelText)
Text(verbatim: Options.characterStandard.isSimplified ? "" : "")
.font(isCantoneseSelected ? .body : .footnote)
.frame(width: partWidth, height: partHeight)
.background(isCantoneseSelected ? textBackColor : Color.clear, in: RoundedRectangle(cornerRadius: cornerRadius, style: .continuous))
Expand Down
6 changes: 3 additions & 3 deletions Keyboard/SharedViews/ToolBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct ToolBar: View {
imageName: "gear",
width: buttonWidth,
height: buttonHeight,
insets: EdgeInsets(top: 18, leading: 0, bottom: 18, trailing: 0)
insets: EdgeInsets(top: 16, leading: 0, bottom: 16, trailing: 0)
) {
AudioFeedback.modified()
context.triggerHapticFeedback()
Expand Down Expand Up @@ -64,7 +64,7 @@ struct ToolBar: View {
imageName: editingButtonImageName,
width: buttonWidth,
height: buttonHeight,
insets: EdgeInsets(top: 20, leading: 0, bottom: 20, trailing: 0)
insets: EdgeInsets(top: 18, leading: 0, bottom: 18, trailing: 0)
) {
AudioFeedback.modified()
context.triggerHapticFeedback()
Expand All @@ -76,7 +76,7 @@ struct ToolBar: View {
imageName: "keyboard.chevron.compact.down",
width: buttonWidth,
height: buttonHeight,
insets: EdgeInsets(top: 19, leading: 0, bottom: 20, trailing: 0)
insets: EdgeInsets(top: 17, leading: 0, bottom: 18, trailing: 0)
) {
AudioFeedback.modified()
context.triggerHapticFeedback()
Expand Down

0 comments on commit f4ae4b4

Please sign in to comment.