Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 51 additions & 5 deletions iosApp/iosApp/Screens/People/PersonDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,7 @@ private struct PhonePersonDetailContent: View {
metadataWrap

if let bio = clean(person.bio) {
Text(bio)
.font(.siloBody)
.foregroundColor(.siloSecondaryText)
.lineLimit(8)
.fixedSize(horizontal: false, vertical: true)
PersonBiography(text: bio)
}
}
}
Expand Down Expand Up @@ -639,6 +635,56 @@ private struct PhonePersonDetailContent: View {
}
#endif

#if !os(tvOS)
/// The biography, clipped to eight lines. When that cuts text off, a More
/// control (or a tap on the text) shows all of it; a short biography shows
/// no control.
private struct PersonBiography: View {
let text: String

@State private var isExpanded = false
@State private var clippedHeight: CGFloat = 0
@State private var fullHeight: CGFloat = 0

private var isClipped: Bool { fullHeight > clippedHeight + 1 }

var body: some View {
VStack(alignment: .leading, spacing: 6) {
Text(text)
.font(.siloBody)
.foregroundColor(.siloSecondaryText)
.lineLimit(isExpanded ? nil : 8)
.fixedSize(horizontal: false, vertical: true)
.onGeometryChange(for: CGFloat.self, of: \.size.height) { height in
if !isExpanded { clippedHeight = height }
}
// The same text at the same width with no line limit, to
// learn whether eight lines cut anything off.
.background(alignment: .top) {
Text(text)
.font(.siloBody)
.fixedSize(horizontal: false, vertical: true)
.hidden()
.onGeometryChange(for: CGFloat.self, of: \.size.height) { fullHeight = $0 }
}
.contentShape(Rectangle())
.onTapGesture { if isClipped { toggle() } }

if isClipped {
Button(isExpanded ? "Less" : "More", action: toggle)
.buttonStyle(.plain)
.font(.siloBody.weight(.semibold))
.foregroundColor(.siloOnSurface)
}
}
}

private func toggle() {
withAnimation(.easeInOut(duration: SiloTheme.normalDuration)) { isExpanded.toggle() }
}
}
#endif

private struct PersonPortrait: View {
let person: Person
let width: CGFloat
Expand Down
Loading