Skip to content

Commit 62eb13b

Browse files
author
Your Name
committed
Fix iOS chat Dynamic Type text
1 parent 8910969 commit 62eb13b

4 files changed

Lines changed: 63 additions & 11 deletions

File tree

apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatComposer.swift

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct OpenClawChatComposer: View {
5555
#else
5656
@State private var shouldFocusTextView = false
5757
#endif
58+
@ScaledMetric(relativeTo: .body) private var scaledBodyLineHeight: CGFloat = 22
5859

5960
var body: some View {
6061
VStack(alignment: .leading, spacing: 4) {
@@ -337,15 +338,15 @@ struct OpenClawChatComposer: View {
337338

338339
HStack(alignment: .center, spacing: 8) {
339340
self.editorOverlay
340-
.frame(minHeight: self.cleanControlHeight)
341+
.frame(minHeight: self.cleanEditorMinHeight)
341342

342343
if let talkControl {
343344
self.compactTalkButton(talkControl)
344345
}
345346
}
346347
.padding(.leading, 14)
347348
.padding(.trailing, 6)
348-
.frame(height: self.cleanControlHeight)
349+
.frame(minHeight: self.cleanEditorMinHeight)
349350
.background(
350351
Capsule(style: .continuous)
351352
.fill(OpenClawChatTheme.composerField)
@@ -356,7 +357,7 @@ struct OpenClawChatComposer: View {
356357
self.sendButton
357358
.frame(width: self.cleanControlHeight, height: self.cleanControlHeight)
358359
}
359-
.frame(height: self.cleanControlHeight)
360+
.frame(minHeight: self.cleanEditorMinHeight)
360361

361362
if self.showsConnectionPill {
362363
self.connectionPill
@@ -488,6 +489,7 @@ struct OpenClawChatComposer: View {
488489
ZStack(alignment: self.editorOverlayAlignment) {
489490
if self.viewModel.input.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
490491
Text(self.placeholderText)
492+
.font(.body)
491493
.foregroundStyle(.tertiary)
492494
.padding(.horizontal, self.cleanFieldTextInset)
493495
.padding(.vertical, self.composerChrome == .clean ? 0 : 4)
@@ -513,7 +515,7 @@ struct OpenClawChatComposer: View {
513515
"",
514516
text: self.$viewModel.input,
515517
axis: .vertical)
516-
.font(.system(size: 15))
518+
.font(.body)
517519
.lineLimit(1...4)
518520
.submitLabel(.send)
519521
.onSubmit {
@@ -614,13 +616,25 @@ struct OpenClawChatComposer: View {
614616
}
615617

616618
private var textMinHeight: CGFloat {
617-
if self.style == .onboarding { return 24 }
618-
return self.composerChrome == .clean ? 24 : 28
619+
let base: CGFloat = if self.style == .onboarding {
620+
24
621+
} else {
622+
self.composerChrome == .clean ? 24 : 28
623+
}
624+
return max(base, self.scaledBodyLineHeight)
619625
}
620626

621627
private var textMaxHeight: CGFloat {
622-
if self.style == .onboarding { return 52 }
623-
return self.composerChrome == .clean ? 48 : 64
628+
let base: CGFloat = if self.style == .onboarding {
629+
52
630+
} else {
631+
self.composerChrome == .clean ? 48 : 64
632+
}
633+
return max(base, self.scaledBodyLineHeight * 4)
634+
}
635+
636+
private var cleanEditorMinHeight: CGFloat {
637+
max(self.cleanControlHeight, self.textMinHeight)
624638
}
625639

626640
private var sendButtonSize: CGFloat {

apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatMessageViews.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ private struct ChatMessageBody: View {
274274
text: text,
275275
context: .user,
276276
variant: self.markdownVariant,
277-
font: .system(size: 14),
277+
font: .body,
278278
textColor: textColor)
279279
} else {
280280
ChatAssistantTextBody(
@@ -747,7 +747,7 @@ private struct ChatAssistantTextBody: View {
747747
let segments = AssistantTextParser.segments(from: self.text, includeThinking: self.includesThinking)
748748
VStack(alignment: .leading, spacing: 10) {
749749
ForEach(segments) { segment in
750-
let font = segment.kind == .thinking ? Font.system(size: 14).italic() : Font.system(size: 14)
750+
let font = segment.kind == .thinking ? Font.callout.italic() : Font.body
751751
ChatMarkdownRenderer(
752752
text: segment.text,
753753
context: .assistant,

apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ private struct ChatAssistantIntroCard: View {
649649

650650
var body: some View {
651651
Text(self.text)
652-
.font(.system(size: 15))
652+
.font(.body)
653653
.lineSpacing(4)
654654
.foregroundStyle(OpenClawChatTheme.assistantText)
655655
.multilineTextAlignment(.leading)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Foundation
2+
import Testing
3+
4+
struct ChatDynamicTypeSourceGuardTests {
5+
@Test func `chat text avoids fixed point fonts`() throws {
6+
let sources = try Self.scopedChatTextSources()
7+
8+
#expect(!sources.messageViews.contains("font: .system(size: 14)"))
9+
#expect(!sources.messageViews.contains("Font.system(size: 14)"))
10+
#expect(!sources.chatView.contains(".font(.system(size: 15))"))
11+
#expect(!sources.composer.contains(".font(.system(size: 15))"))
12+
#expect(!sources.composer.contains(".frame(height: self.cleanControlHeight)"))
13+
#expect(!sources.composer.contains("return self.composerChrome == .clean ? 48 : 64"))
14+
#expect(sources.composer.contains("@ScaledMetric(relativeTo: .body)"))
15+
}
16+
17+
private static func scopedChatTextSources() throws -> (
18+
messageViews: String,
19+
chatView: String,
20+
composer: String)
21+
{
22+
let root = URL(fileURLWithPath: #filePath)
23+
.deletingLastPathComponent()
24+
.deletingLastPathComponent()
25+
.deletingLastPathComponent()
26+
27+
return try (
28+
messageViews: String(
29+
contentsOf: root.appendingPathComponent("Sources/OpenClawChatUI/ChatMessageViews.swift"),
30+
encoding: .utf8),
31+
chatView: String(
32+
contentsOf: root.appendingPathComponent("Sources/OpenClawChatUI/ChatView.swift"),
33+
encoding: .utf8),
34+
composer: String(
35+
contentsOf: root.appendingPathComponent("Sources/OpenClawChatUI/ChatComposer.swift"),
36+
encoding: .utf8))
37+
}
38+
}

0 commit comments

Comments
 (0)