Skip to content
Contact Expand preview
Rendered from the SwiftUI source on this page.

Contact Expand

From syxUI — written for both platforms, not translated between them.

A person row that expands to phone and email.

Accordions · SwiftUI · iOS 17

  • accordion
  • swiftui

The actual source

AccAvatar.swift
// Contact Expand · syxUI · https://syxui.dev/components/acc-avatar
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

extension View {
    func formaCard(_ pad: CGFloat = 18) -> some View {
        self.padding(pad)
            .background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: 20, style: .continuous))
            .overlay(RoundedRectangle(cornerRadius: 20, style: .continuous).stroke(Color.primary.opacity(0.06), lineWidth: 1))
            .shadow(color: .black.opacity(0.05), radius: 14, x: 0, y: 6)
    }
}

// Person row expands to contact details
struct AccAvatar: View {
    @State private var open = true
    var body: some View {
        VStack(spacing: 0) {
            HStack(spacing: 12) {
                Image("person_4").resizable().scaledToFill().frame(width: 44, height: 44).clipShape(Circle())
                VStack(alignment: .leading, spacing: 2) {
                    Text("Arjun Patel").font(.system(size: 15, weight: .semibold))
                    Text("Lead Engineer").font(.system(size: 13)).foregroundStyle(.secondary)
                }
                Spacer()
                Image(systemName: "chevron.down").font(.system(size: 12, weight: .semibold)).foregroundStyle(.secondary).rotationEffect(.degrees(open ? 180 : 0))
            }.padding(.vertical, 6).contentShape(Rectangle()).onTapGesture { open.toggle() }
            if open {
                Divider().padding(.vertical, 8)
                VStack(spacing: 10) {
                    HStack { Image(systemName: "envelope").font(.system(size: 13)).foregroundStyle(.secondary).frame(width: 22); Text("arjun@company.com").font(.system(size: 14)); Spacer() }
                    HStack { Image(systemName: "phone").font(.system(size: 13)).foregroundStyle(.secondary).frame(width: 22); Text("+1 (415) 555-0148").font(.system(size: 14)); Spacer() }
                }
            }
        }.formaCard(16).frame(width: 320)
    }
}
iOS 17 · 1 dependencies

Dependencies

SwiftUI
  • person_4 (image asset)

Requires iOS 17