Skip to content
Notification Group preview
Rendered from the SwiftUI source on this page.

Notification Group

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

A collapsible 'Today' group of notifications.

Accordions · SwiftUI · iOS 17

  • accordion
  • swiftui

The actual source

AccNotifGroup.swift
// Notification Group · syxUI · https://syxui.dev/components/acc-notif-group
// 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)
    }
}

// Collapsible notification group
struct AccNotifGroup: View {
    @State private var open = true
    let notifs = [("heart.fill", "James liked your post", "2m"), ("person.fill.badge.plus", "Mia started following you", "10m"), ("bubble.right.fill", "New comment from Sam", "1h")]
    var body: some View {
        VStack(spacing: 0) {
            HStack {
                Text("Today").font(.system(size: 13, weight: .semibold)).foregroundStyle(.secondary)
                Spacer()
                Image(systemName: "chevron.down").font(.system(size: 11, weight: .semibold)).foregroundStyle(.secondary).rotationEffect(.degrees(open ? 0 : -90))
            }.padding(.vertical, 10).contentShape(Rectangle()).onTapGesture { open.toggle() }
            if open {
                ForEach(Array(notifs.enumerated()), id: \.offset) { _, n in
                    HStack(spacing: 12) {
                        Image(systemName: n.0).font(.system(size: 13)).foregroundStyle(.white).frame(width: 32, height: 32).background(accBlue, in: Circle())
                        Text(n.1).font(.system(size: 14))
                        Spacer()
                        Text(n.2).font(.system(size: 12)).foregroundStyle(.secondary)
                    }.padding(.vertical, 8)
                }
            }
        }.formaCard(16).frame(width: 330)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17