mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 10:29:58 +02:00
feat(apple): native SwiftUI app for iOS and macOS
Add a native SwiftUI VniDrop app (Send/Receive/Settings) talking to the Rust core via generated UniFFI Swift bindings, plus the uniffi-bindgen helper crate. iOS uses a TabView, macOS a NavigationSplitView sidebar.
This commit is contained in:
56
apple/VniDrop/UI/Theme/VniDropTheme.swift
Normal file
56
apple/VniDrop/UI/Theme/VniDropTheme.swift
Normal file
@@ -0,0 +1,56 @@
|
||||
import SwiftUI
|
||||
|
||||
/// User-facing theme selection, mirrors `ThemeMode` in the Compose theme.
|
||||
enum ThemeMode: String, CaseIterable, Codable, Sendable {
|
||||
case system
|
||||
case light
|
||||
case dark
|
||||
|
||||
/// SwiftUI color-scheme override (`nil` follows the system).
|
||||
var preferredColorScheme: ColorScheme? {
|
||||
switch self {
|
||||
case .system: return nil
|
||||
case .light: return .light
|
||||
case .dark: return .dark
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func resolveDarkTheme(_ mode: ThemeMode, systemDark: Bool) -> Bool {
|
||||
switch mode {
|
||||
case .system: return systemDark
|
||||
case .light: return false
|
||||
case .dark: return true
|
||||
}
|
||||
}
|
||||
|
||||
private struct VniDropColorsKey: EnvironmentKey {
|
||||
static let defaultValue = VniDropColors.light
|
||||
}
|
||||
|
||||
extension EnvironmentValues {
|
||||
/// Semantic VniDrop tokens for the active theme. Read with
|
||||
/// `@Environment(\.vniColors) private var colors`.
|
||||
var vniColors: VniDropColors {
|
||||
get { self[VniDropColorsKey.self] }
|
||||
set { self[VniDropColorsKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
/// Provides the semantic token set matching the resolved light/dark theme to the
|
||||
/// whole subtree. Apply once near the app root.
|
||||
struct VniDropTheme: ViewModifier {
|
||||
let isDark: Bool
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.environment(\.vniColors, isDark ? .dark : .light)
|
||||
.tint(VniDropColors.brandPurple)
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
func vniDropTheme(isDark: Bool) -> some View {
|
||||
modifier(VniDropTheme(isDark: isDark))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user