Skip to content
File Tree preview
Rendered from the SwiftUI source on this page.

File Tree

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

A folder that expands into a file list, tree-style.

Accordions · SwiftUI · iOS 17

  • accordion
  • swiftui

The actual source

AccTree.swift
// File Tree · syxUI · https://syxui.dev/components/acc-tree
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

let accBlue = Color(red: 0.0, green: 0.47, blue: 1.0)

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)
    }
}

// File tree accordion
struct AccTree: View {
    @State private var open = true
    let files = [("swift", "ContentView.swift"), ("swift", "Model.swift"), ("photo", "Assets.xcassets")]
    var body: some View {
        VStack(alignment: .leading, spacing: 0) {
            HStack(spacing: 8) {
                Image(systemName: open ? "chevron.down" : "chevron.right").font(.system(size: 11, weight: .semibold)).foregroundStyle(.secondary)
                Image(systemName: "folder.fill").font(.system(size: 14)).foregroundStyle(accBlue)
                Text("Sources").font(.system(size: 14, weight: .medium))
                Spacer()
            }.padding(.vertical, 9).contentShape(Rectangle()).onTapGesture { open.toggle() }
            if open {
                ForEach(Array(files.enumerated()), id: \.offset) { _, f in
                    HStack(spacing: 8) {
                        Image(systemName: f.0 == "swift" ? "swift" : "photo").font(.system(size: 13)).foregroundStyle(f.0 == "swift" ? .orange : .secondary)
                        Text(f.1).font(.system(size: 14)).foregroundStyle(.secondary)
                        Spacer()
                    }.padding(.vertical, 7).padding(.leading, 27)
                }
            }
        }.formaCard(16).frame(width: 300)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17