From d5dc153e9211cefa2ea36fb41eb02b46acd5b342 Mon Sep 17 00:00:00 2001 From: Max Rozdobudko Date: Tue, 11 Aug 2026 19:59:59 +0300 Subject: [PATCH 01/16] feat: add Skip framework compatibility for Android Make ThemeKit cross-compile for Android via Skip (skip.dev) in native (Fuse) mode: - Package.swift: skip + skip-fuse-ui dependencies, skipstone plugin on the ThemeKit target, .dynamic library product (required for JNI), and a SKIP_ZERO=1 block that strips all Skip machinery for Apple-only consumers. Skip/skip.yml declares the module as native mode. - Gate Apple-only APIs with #if !os(Android): ShapeStyle conformances (SkipFuseUI has no resolve(in:) customization point), MeshGradient, ShadowStyle, and hex encoding of colors (no UIColor/NSColor). - Work around SkipSwiftUI's non-public Gradient.Stop initializer when decoding gradients on Android. - Add resolved(colorScheme:sizeClass:) as the cross-platform explicit resolution path (environment values cannot be read outside @Environment on Android). - Generator: emit a classic EnvironmentKey instead of @Entry (SkipFuseUI ships no macros) and #if !os(Android) guards in ThemeShapeStyle, ThemeShadowedStyle, ShapeStyle extension, and preview templates so generated files compile in shared Skip app modules. - Document the Android support surface in README and CLAUDE.md. Verified: swift test (225 tests), SKIP_ZERO=1 swift build, skip android build --target ThemeKit, and an end-to-end Skip app probe consuming the package plus generated theme files, built for both macOS and Android. Co-Authored-By: Claude Fable 5 --- CLAUDE.md | 9 ++ Package.resolved | 114 ++++++++++++++++++ Package.swift | 47 +++++++- README.md | 29 +++++ Sources/ThemeKit/Color+Hex.swift | 16 ++- Sources/ThemeKit/Gradient+Codable.swift | 16 ++- Sources/ThemeKit/MeshGradient+Codable.swift | 5 + Sources/ThemeKit/Shadow.swift | 4 + Sources/ThemeKit/Skip/skip.yml | 6 + .../ThemeAdaptiveStyle+Defaults.swift | 1 + .../ThemeAdaptiveStyle+Resolved.swift | 37 ++++++ .../ThemeAdaptiveStyle+Resolver.swift | 1 + .../ThemeAdaptiveStyle+ShapeStyle.swift | 5 + .../EnvironmentThemeGenerator.swift | 9 +- .../ShapeStyleExtensionGenerator.swift | 4 + .../ThemePreviewGenerator.swift | 3 + .../ThemeShadowedStyleGenerator.swift | 3 + .../ThemeShapeStyleGenerator.swift | 3 + .../ThemeFileGeneratorTests.swift | 7 +- .../ThemePreviewGeneratorTests.swift | 1 + .../ThemeAdaptiveStyleTests.swift | 37 ++++++ 21 files changed, 345 insertions(+), 12 deletions(-) create mode 100644 Package.resolved create mode 100644 Sources/ThemeKit/Skip/skip.yml create mode 100644 Sources/ThemeKit/ThemeAdaptiveStyle+Resolved.swift diff --git a/CLAUDE.md b/CLAUDE.md index e98259e..0d1465e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -90,3 +90,12 @@ A Svelte SPA at `.github/pages/` that lets users build `theme.json` visually ins - Generated `ShapeStyle` extensions constrain `Self` to `ThemeShapeStyle` - Shadow tokens also generate unconstrained instance properties on `ShapeStyle` for composition โ€” static and instance properties coexist without conflict - Test targets use stub implementations of generated types for testing core types + +## Skip / Android Compatibility + +The `ThemeKit` target cross-compiles for Android via [Skip](https://skip.dev) in native (Fuse) mode: `Sources/ThemeKit/Skip/skip.yml`, skipstone plugin + SkipFuseUI dependency in Package.swift, `.dynamic` library product. `SKIP_ZERO=1` strips all Skip machinery (block at the bottom of Package.swift โ€” keep it in sync when editing targets/products). + +- Apple-only APIs are gated with `#if !os(Android)`: ShapeStyle conformances (`resolve(in:)` doesn't exist in SkipFuseUI), `MeshGradient`, `ShadowStyle`, hex *encoding* of colors (no UIColor/NSColor). Generator templates emit the same gates in ShapeStyle/preview files and use a classic `EnvironmentKey` instead of `@Entry` (no macros in SkipFuseUI). +- Cross-platform resolution API: `resolved(colorScheme:sizeClass:)` (environment values can't be read outside `@Environment` on Android). +- The `meshGradients` config category generates Apple-only code by design โ€” gating it would break the generated root `Theme` struct. +- Verify Android compilation with: `skip android build --plain --target ThemeKit` (requires the skip CLI and a Swift Android SDK; `--target` scoping avoids the Darwin-only GeneratedCode* verification targets). diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..d37222e --- /dev/null +++ b/Package.resolved @@ -0,0 +1,114 @@ +{ + "originHash" : "d0b8383f31559f70e816864f8f25f727f35317ef5fc1f07a73ef4c571df653e3", + "pins" : [ + { + "identity" : "skip", + "kind" : "remoteSourceControl", + "location" : "https://source.skip.tools/skip.git", + "state" : { + "revision" : "885f0c520e1ebdbec1f0e296d713293dadc5a2f4", + "version" : "1.9.5" + } + }, + { + "identity" : "skip-android-bridge", + "kind" : "remoteSourceControl", + "location" : "https://source.skip.tools/skip-android-bridge.git", + "state" : { + "revision" : "545ea1b2d7ba4abc82daa2be00f81f4ea8e64e5b", + "version" : "0.6.4" + } + }, + { + "identity" : "skip-bridge", + "kind" : "remoteSourceControl", + "location" : "https://source.skip.tools/skip-bridge.git", + "state" : { + "revision" : "72b7b1d4734332cfdc4b519539b5beec0fb3ac00", + "version" : "0.17.2" + } + }, + { + "identity" : "skip-foundation", + "kind" : "remoteSourceControl", + "location" : "https://source.skip.tools/skip-foundation.git", + "state" : { + "revision" : "94d47aeed3bb8027ef3ad8e07a8771b52529c238", + "version" : "1.4.2" + } + }, + { + "identity" : "skip-fuse", + "kind" : "remoteSourceControl", + "location" : "https://source.skip.tools/skip-fuse.git", + "state" : { + "revision" : "8f3295094ad29075730284c5197c7f1d94c0f2d9", + "version" : "1.0.2" + } + }, + { + "identity" : "skip-fuse-ui", + "kind" : "remoteSourceControl", + "location" : "https://source.skip.tools/skip-fuse-ui.git", + "state" : { + "revision" : "d27fc109268b21feb98a48bc1a3f4558e162d9ca", + "version" : "1.18.1" + } + }, + { + "identity" : "skip-lib", + "kind" : "remoteSourceControl", + "location" : "https://source.skip.tools/skip-lib.git", + "state" : { + "revision" : "76e7da8a870b5b66ea0c3264f648b58b73bcdc0d", + "version" : "1.4.0" + } + }, + { + "identity" : "skip-model", + "kind" : "remoteSourceControl", + "location" : "https://source.skip.tools/skip-model.git", + "state" : { + "revision" : "54c7914e985e5ae07b1a8fe29e7aac7156b88874", + "version" : "1.7.6" + } + }, + { + "identity" : "skip-ui", + "kind" : "remoteSourceControl", + "location" : "https://source.skip.tools/skip-ui.git", + "state" : { + "revision" : "ef7bbdd541cdf2efd3ce6ecde72337e1beb92366", + "version" : "1.59.1" + } + }, + { + "identity" : "skip-unit", + "kind" : "remoteSourceControl", + "location" : "https://source.skip.tools/skip-unit.git", + "state" : { + "revision" : "c89af47fd645e04db863e938ade39f91e1bb62b8", + "version" : "1.7.0" + } + }, + { + "identity" : "swift-android-native", + "kind" : "remoteSourceControl", + "location" : "https://source.skip.tools/swift-android-native.git", + "state" : { + "revision" : "7e6e833e6f163a2b75340f75c70b1d96ea6b8135", + "version" : "1.5.1" + } + }, + { + "identity" : "swift-jni", + "kind" : "remoteSourceControl", + "location" : "https://source.skip.tools/swift-jni.git", + "state" : { + "revision" : "fe76ac21aca639976833b5ea3e875dc072519ac4", + "version" : "0.5.0" + } + } + ], + "version" : 3 +} diff --git a/Package.swift b/Package.swift index 097a67b..e4f2a70 100644 --- a/Package.swift +++ b/Package.swift @@ -15,6 +15,7 @@ let package = Package( products: [ .library( name: "ThemeKit", + type: .dynamic, targets: ["ThemeKit"] ), .plugin( @@ -22,9 +23,17 @@ let package = Package( targets: ["Generate Theme Files"] ), ], + dependencies: [ + .package(url: "https://source.skip.tools/skip.git", from: "1.9.5"), + .package(url: "https://source.skip.tools/skip-fuse-ui.git", from: "1.0.0"), + ], targets: [ .target( - name: "ThemeKit" + name: "ThemeKit", + dependencies: [ + .product(name: "SkipFuseUI", package: "skip-fuse-ui") + ], + plugins: [.plugin(name: "skipstone", package: "skip")] ), .target( name: "ThemeKitGenerator" @@ -96,3 +105,39 @@ let package = Package( ), ] ) + +// Setting the SKIP_ZERO=1 environment strips the Skip plugin and all Skip dependencies, +// restoring a plain SwiftPM package for Apple-only consumers. +if Context.environment["SKIP_ZERO"] ?? "0" != "0" { + package.targets.forEach { target in + target.plugins?.removeAll(where: { + if case .plugin(let name, _) = $0 { + return name == "skipstone" + } else { + return false + } + }) + + target.dependencies.removeAll(where: { dependency in + if case .productItem(_, let package, _, _) = dependency { + return package == "skip" || package?.hasPrefix("skip-") == true + } else { + return false + } + }) + } + + package.dependencies.removeAll(where: { dependency in + if case .sourceControl(_, let url, _) = dependency.kind { + return url.hasPrefix("https://source.skip.dev/") || url.hasPrefix("https://source.skip.tools/") + } else { + return false + } + }) + + // Restore the default (automatic) library type โ€” dynamic is only needed for Android/JNI loading. + package.products = [ + .library(name: "ThemeKit", targets: ["ThemeKit"]), + .plugin(name: "Generate Theme Files", targets: ["Generate Theme Files"]), + ] +} diff --git a/README.md b/README.md index ee1191d..67c2ad2 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ ThemeKit gives your app a design token system that works exactly like SwiftUI's - ๐Ÿช„ **Easy Setup** โ€” declare tokens in JSON, run the plugin once, fill in your colors, done. **Zero imports** required in your app code. - ๐Ÿ“– **Transparent Logic** โ€” the thin core and generated files are easy to read. Each file has a clear, specific role that is obvious at a glance. - ๐ŸŽ›๏ธ **Full Control** โ€” generated files live in your project, fully readable and yours to extend. +- ๐Ÿค– **Skip / Android Ready** โ€” the core library cross-compiles for Android with [Skip](https://skip.dev) (native/Fuse mode), so theme definitions, JSON (de)serialization, and explicit token resolution work in shared Swift code. ## ๐Ÿฟ Demo @@ -231,6 +232,34 @@ Every type conforms to `Codable`, so themes can come from a remote API, a bundle let theme = try JSONDecoder().decode(Theme.self, from: data) ``` +## ๐Ÿค– Skip / Android + +ThemeKit is compatible with [Skip](https://skip.dev) in **native (Skip Fuse) mode**: the `ThemeKit` module cross-compiles for Android as-is (`import SwiftUI` resolves to Skip's SwiftUI facade there), and the package ships the `skipstone` plugin and `Skip/skip.yml` configuration Skip needs to process it as a module of a Skip app. + +**What works on Android:** + +- `ThemeAdaptiveStyle` and all theme/token data types, including `Codable` round-trips of `theme.json` and remote themes (decoding colors and gradients from hex strings). +- Explicit resolution via `resolved(colorScheme:sizeClass:)` โ€” pass values read with `@Environment` in your views: + +```swift +// Note: Skip requires @Environment properties to be non-private in shared views. +@Environment(\.theme) var theme +@Environment(\.colorScheme) var colorScheme + +var body: some View { + Text("Hello") + .foregroundStyle(theme.colors.primary.resolved(colorScheme: colorScheme) ?? .primary) +} +``` + +**What stays Apple-only** (Skip's SwiftUI facade has no `ShapeStyle.resolve(in:)` customization point, and environment values cannot be read outside `@Environment`): + +- The implicit `ShapeStyle` sugar (`.foregroundStyle(.surface)`) and `resolved(in: EnvironmentValues)` โ€” generated files guard these with `#if !os(Android)`, so they compile in a shared Skip module but the sugar is only callable on Apple platforms. +- `MeshGradient` and `ShadowStyle` (`Shadow` remains available as data). Theme configs using the `meshGradients` category generate Apple-only code โ€” omit that category in themes shared with Android. +- Encoding colors back to hex strings (decoding works everywhere). + +**Apple-only projects:** if you don't use Skip, set the `SKIP_ZERO=1` environment variable when resolving packages to strip all Skip dependencies and plugins โ€” ThemeKit then behaves as a plain SwiftPM package. + ## โš™๏ธ How It Works The generated `ThemeShapeStyle