~ knotless Search/
↑↓ move↵ open⇧↵ all results

geesawra.industries/old-fella

Old people's social media app

0
1
main
32 lines · 1.2 KB Raw History
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)
    }
}