Files
TUIkit/Sources/TUIkitExample/AppState.swift
T
phranck 282d1662c1 Refactor: Eliminate AppState singleton
- Replace AppState.shared with AppState.active (settable static property)
- Make AppState.init() public instead of private
- Update all 15 source references across State.swift, App.swift,
  StatusBarState.swift, ThemeManager.swift, AppStorage.swift
- Update all 28 test references in AppStateTests and StatePropertyTests
- Serialize Environment Property Wrapper tests (shared-state race fix)
2026-01-30 23:08:22 +01:00

61 lines
1.4 KiB
Swift

//
// AppState.swift
// TUIkitExample
//
// Global state management for the example app.
//
import TUIkit
// MARK: - Demo Page Enum
/// The available demo pages in the example app.
enum DemoPage: Int, CaseIterable {
case menu
case textStyles
case colors
case containers
case overlays
case layout
case buttons
}
// MARK: - App State
/// Global state for the example app.
///
/// This class manages the current page and menu selection.
/// Changes trigger automatic re-renders via `AppState`.
///
/// Status bar items are now managed declaratively via the
/// `.statusBarItems()` modifier in `ContentView`.
final class ExampleAppState: @unchecked Sendable {
/// The shared instance for the example app.
///
/// This is acceptable for the example app since it is a simple demo.
/// In production code, prefer dependency injection via Environment.
static let shared = ExampleAppState()
/// The current page being displayed.
var currentPage: DemoPage = .menu {
didSet {
AppState.active.setNeedsRender()
}
}
/// The selected menu index.
var menuSelection: Int = 0 {
didSet { AppState.active.setNeedsRender() }
}
/// Binding for menu selection.
var menuSelectionBinding: Binding<Int> {
Binding(
get: { self.menuSelection },
set: { self.menuSelection = $0 }
)
}
private init() {}
}