1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import SwiftUI
struct ComposerSuggestionDropdown<Content: View>: View {
let caret: CGRect
let viewport: CGSize
let contentHeight: CGFloat
@ViewBuilder var content: () -> Content
var body: some View {
let width = min(320, max(0, viewport.width - 32))
let left = max(16, viewport.width - width - 16)
let below = max(0, viewport.height - caret.maxY - 12)
let above = max(0, caret.minY - 12)
let opensBelow = below >= min(180, above)
let available = min(240, opensBelow ? below : above)
let height = min(contentHeight, available)
let top = opensBelow ? caret.maxY + 6 : max(6, caret.minY - height - 6)
ScrollView {
content()
}
.scrollBounceBehavior(.basedOnSize)
.frame(width: width, height: height)
.background(Color(uiColor: .secondarySystemBackground), in: RoundedRectangle(cornerRadius: 12))
.overlay {
RoundedRectangle(cornerRadius: 12).strokeBorder(Color(uiColor: .separator).opacity(0.5), lineWidth: 0.5)
.allowsHitTesting(false)
}
.clipShape(RoundedRectangle(cornerRadius: 12))
.shadow(color: .black.opacity(0.14), radius: 12, y: 4)
.offset(x: left, y: top)
}
}