Skip to content

Commit d3ae547

Browse files
authored
Merge pull request #42 from nsswifter/feature/6-implement-session-module
Feature/6 implement session module
2 parents 6705cec + 47061f8 commit d3ae547

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

AISightQuest/Common/View/TextView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct TextView: UIViewRepresentable {
2222
textView.showsHorizontalScrollIndicator = false
2323
textView.showsVerticalScrollIndicator = false
2424
textView.tintColor = .darkBlue500
25-
textView.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: UIFont.systemFont(ofSize: 17))
25+
textView.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .preferredFont(forTextStyle: .body))
2626
return textView
2727
}
2828

AISightQuest/Modules/Session/View/SessionView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct SessionView: View {
9090

9191
Button {
9292
setAttributedText("")
93+
questionText = ""
9394
clearAttributedTextButtonTapped += 1
9495
} label: {
9596
Image(systemName: "xmark")
@@ -132,7 +133,7 @@ private extension SessionView {
132133
attributes: [.foregroundColor: colorScheme == .dark
133134
? UIColor.white : UIColor.black,
134135
.font: UIFontMetrics(forTextStyle: .body)
135-
.scaledFont(for: UIFont.systemFont(ofSize: 17))])
136+
.scaledFont(for: .preferredFont(forTextStyle: .body))])
136137
}
137138
}
138139

@@ -194,7 +195,7 @@ private extension SessionView {
194195
.font(.title)
195196
.padding(.trailing)
196197
}
197-
.hidden(questionText.isEmpty/*, remove: questionText.isEmpty*/)
198+
.hidden(questionText.isEmpty)
198199
.sensoryFeedback(.impact(flexibility: .rigid, intensity: 1),
199200
trigger: clearQuestionButtonTapped)
200201
}

AISightQuest/Modules/Session/ViewModel/SessionViewModel.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,22 @@ extension SessionView {
4242
// Highlight the answer substring in the original text.
4343
var attributedText: NSAttributedString?
4444
if answer.base == context {
45-
let mutableAttributedText = NSMutableAttributedString(string: context,
46-
attributes: [.foregroundColor: colorScheme == .dark
47-
? UIColor.white : UIColor.black,
48-
.font: UIFontMetrics(forTextStyle: .body)
49-
.scaledFont(for: UIFont.systemFont(ofSize: 17))])
45+
let bodyFont = UIFont.preferredFont(forTextStyle: .body)
46+
let boldFont = UIFont.systemFont(ofSize: bodyFont.pointSize, weight: .bold)
5047

48+
let bodyScaledFont = UIFontMetrics(forTextStyle: .body).scaledFont(for: bodyFont)
49+
let boldScaledFont = UIFontMetrics(forTextStyle: .body).scaledFont(for: boldFont)
50+
51+
let mutableAttributedText = NSMutableAttributedString(string: context,
52+
attributes: [.foregroundColor: colorScheme == .dark ? UIColor.white : UIColor.black,
53+
.font: bodyScaledFont])
54+
5155
let location = answer.startIndex.utf16Offset(in: context)
5256
let length = answer.endIndex.utf16Offset(in: context) - location
5357
let answerRange = NSRange(location: location, length: length)
54-
58+
5559
mutableAttributedText.addAttributes([.foregroundColor: UIColor.darkBlue500,
56-
.font: UIFontMetrics(forTextStyle: .body)
57-
.scaledFont(for: UIFont(name: "Avenir-HeavyOblique", size: 17) ?? UIFont.boldSystemFont(ofSize: 17))],
60+
.font: boldScaledFont],
5861
range: answerRange)
5962
attributedText = mutableAttributedText
6063
}

0 commit comments

Comments
 (0)