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
26 changes: 24 additions & 2 deletions src-tauri/swift/notch/notch_indicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ struct IndicatorExpandableText: View {
let contentPadding: CGFloat

private let textFontSize: CGFloat = 12
private let expandedHeight: CGFloat = 80
private let maxExpandedHeight: CGFloat = 80
@State private var measuredTextHeight: CGFloat = 0

var body: some View {
ScrollViewReader { proxy in
Expand All @@ -216,18 +217,39 @@ struct IndicatorExpandableText: View {
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, contentPadding)
.padding(.vertical, 14)
.background(
GeometryReader { proxy in
Color.clear
.preference(
key: ExpandableTextHeightPreferenceKey.self,
value: proxy.size.height
)
}
)
.id("bottom")
}
.frame(height: expanded ? expandedHeight : 0)
.frame(height: expanded ? min(measuredTextHeight, maxExpandedHeight) : 0)
.clipped()
.onChange(of: text) { _ in
proxy.scrollTo("bottom", anchor: .bottom)
}
.onPreferenceChange(ExpandableTextHeightPreferenceKey.self) { newHeight in
guard abs(measuredTextHeight - newHeight) > 0.5 else { return }
measuredTextHeight = newHeight
}
}
.transaction { $0.disablesAnimations = true }
}
}

private struct ExpandableTextHeightPreferenceKey: PreferenceKey {
static var defaultValue: CGFloat = 0

static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
}

// Helpers

private func formatDuration(_ seconds: TimeInterval) -> String {
Expand Down