Build Modular SwiftUI Widgets with Ease

A powerful SwiftUI widget system for creating modular, reusable UI components with event-driven communication and state management.

WidgetSystemKit.swift

struct TextWidget: AnyWidget {
    @Published var state: TextWidgetState
    
    var body: some View {
        Text(state.text)
            .font(.system(size: state.fontSize))
            .onTapGesture {
                sendWidgetEvent(.didTap)
            }
    }
}
                    

Why WidgetSystemKit?

🧩

Modular Architecture

Create reusable widgets with encapsulated state and behavior. Build complex UIs from simple, composable components.

Event-Driven

Widgets communicate through typed events using Combine. Clean separation of concerns with reactive programming.

🎛️

State Management

Built-in state management with visibility controls. Show, hide, or disable widgets with smooth animations.

🏭

Factory Pattern

Create and configure widgets using the factory pattern. Easy to extend and maintain.

🎨

Animation Support

Smooth transitions when showing/hiding widgets. Customizable animations for better UX.

🛡️

Type Safety

Generic types ensure compile-time safety. Catch errors early with strong typing.

Quick Start

1

Install WidgetSystemKit


dependencies: [
    .package(url: "https://github.com/dimzfresh/WidgetSystemKit.git", from: "1.0.0")
]
                        
2

Create a Widget


struct TextWidget: AnyWidget {
    @Published var state: TextWidgetState
    
    var body: some View {
        Text(state.text)
            .font(.system(size: state.fontSize))
            .onTapGesture {
                sendWidgetEvent(.didTap)
            }
    }
}
                        
3

Use in Your App


struct HomeView: View {
    @StateObject private var viewModel = HomeViewModel()
    
    var body: some View {
        ForEach(viewModel.widgets) { widget in
            WidgetItemContainer(widget: widget) {
                $0.view()
            }
        }
    }
}
                        

Examples

Profile Widget

A complete profile screen with multiple widgets

👤 Profile
📊 Stats
⚙️ Settings

Dashboard Widget

Interactive dashboard with real-time updates

📈 Chart
📋 List
🔔 Notifications