LiveActivities design fix

- Fixed issue where long subject names did not fit. 
- Formatting improvements on DynamicIsland and LockScreen notifications. 
- Smarter wrapping for long subjects.
This commit is contained in:
Geryy 2024-05-09 14:46:01 +02:00 committed by GitHub
parent 122a5ea210
commit 56a0c2c02e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -64,7 +64,7 @@ struct LockScreenLiveActivityView: View {
.padding(.trailing, 90) .padding(.trailing, 90)
} else { } else {
Text(context.state.index + " " + context.state.title) MultilineTextView(text: "\(context.state.index) \(context.state.title)", limit: 25)
.font(.body) .font(.body)
.bold() .bold()
.multilineTextAlignment(.center) .multilineTextAlignment(.center)
@ -74,6 +74,7 @@ struct LockScreenLiveActivityView: View {
if (!context.state.subtitle.isEmpty) { if (!context.state.subtitle.isEmpty) {
Text(context.state.subtitle) Text(context.state.subtitle)
.italic() .italic()
.bold()
.font(.system(size: 13)) .font(.system(size: 13))
} }
} }
@ -164,7 +165,7 @@ struct LiveCardWidget: Widget {
.font(.body) .font(.body)
.bold() .bold()
.padding(.leading, 15) .padding(.leading, 15)
Text(context.state.nextSubject) MultilineTextView(text: "\(context.state.index) \(context.state.title)", limit: 25)
.font(.body) .font(.body)
.padding(.leading, 15) .padding(.leading, 15)
@ -196,7 +197,7 @@ struct LiveCardWidget: Widget {
} else { } else {
// Amikor óra van, expanded DynamicIsland // Amikor óra van, expanded DynamicIsland
Text(context.state.index + context.state.title) MultilineTextView(text: "\(context.state.index) \(context.state.title)", limit: 25)
.lineLimit(1) .lineLimit(1)
.font(.body) .font(.body)
.bold() .bold()
@ -204,20 +205,24 @@ struct LiveCardWidget: Widget {
Text(context.state.subtitle) Text(context.state.subtitle)
.lineLimit(1) .lineLimit(1)
.font(.subheadline) .italic()
.bold()
.font(.system(size: 13))
.padding(.trailing, -50) .padding(.trailing, -50)
Spacer(minLength: 5) Spacer(minLength: 5)
if(context.state.nextRoom != "" && context.state.nextSubject != "") { if(context.state.nextRoom != "" && context.state.nextSubject != "") {
Text("Következő óra és terem:") Text("Következő óra és terem:")
.font(.system(size: 13)) .font(.system(size: 14))
.padding(.trailing, -35) .padding(.trailing, -35)
Spacer(minLength: 2)
Text(context.state.nextSubject) Text(context.state.nextSubject)
.font(.caption) .modifier(DynamicFontSizeModifier(text: context.state.nextSubject))
.padding(.trailing, -35) .padding(.trailing, -35)
Text(context.state.nextRoom) Text(context.state.nextRoom)
.font(.caption2) // ignore: based on nextSubject characters, I check that the font size of the room is the same as the next subject.
.modifier(DynamicFontSizeModifier(text: context.state.nextSubject))
.padding(.trailing, -35) .padding(.trailing, -35)
} else { } else {
Text("Ez az utolsó óra! Kitartást!") Text("Ez az utolsó óra! Kitartást!")
@ -270,3 +275,55 @@ struct LiveCardWidget: Widget {
} }
} }
} }
struct MultilineTextView: View {
var text: String
var limit: Int = 20 // default is 20 character
var body: some View {
let words = text.split(separator: " ")
var currentLine = ""
var lines: [String] = []
for word in words {
if (currentLine.count + word.count + 1) > limit {
lines.append(currentLine)
currentLine = ""
}
if !currentLine.isEmpty {
currentLine += " "
}
currentLine += word
}
if !currentLine.isEmpty {
lines.append(currentLine)
}
return VStack(alignment: .center) {
ForEach(lines, id: \.self) { line in
Text(line)
}
Spacer(minLength: 1)
}
}
}
struct DynamicFontSizeModifier: ViewModifier {
var text: String
func body(content: Content) -> some View {
content
.font(.system(size: fontSize(for: text)))
}
private func fontSize(for text: String) -> CGFloat {
let length = text.count
if length < 10 {
return 12
} else if length < 20 {
return 12
} else {
return 11
}
}
}