Skip to content
Expandable Row preview
Rendered from the SwiftUI source on this page.

Expandable Row

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

A row that expands to reveal detail.

Cards · SwiftUI · iOS 17

  • cards
  • swiftui

The actual source

ExpandRow.swift
// Expandable Row · syxUI · https://syxui.dev/components/list-expand
// 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)
    }
}

// Expandable row
struct ExpandRow: View {
    @State private var open = true
    var body: some View {
        VStack(spacing: 0) {
            HStack { Text("Advanced Options").font(.system(size: 15, weight: .medium)); Spacer(); Image(systemName: "chevron.down").font(.system(size: 12, weight: .semibold)).foregroundStyle(.secondary).rotationEffect(.degrees(open ? 180 : 0)) }.padding(.vertical, 11).contentShape(Rectangle()).onTapGesture { open.toggle() }
            if open { Divider(); Text("These settings are for advanced users. Changing them may affect performance.").font(.system(size: 13)).foregroundStyle(.secondary).frame(maxWidth: .infinity, alignment: .leading).padding(.top, 10) }
        }.formaCard(14).frame(width: 320)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17