theming + material you

This commit is contained in:
Boof2015
2026-07-06 20:38:42 -04:00
parent e1f99f6d61
commit efd2ebc91a
87 changed files with 1528 additions and 327 deletions
@@ -0,0 +1,18 @@
plugins {
id 'com.android.library'
id 'expo-module-gradle-plugin'
}
group = 'expo.modules.astrasystemcolors'
version = '0.1.0'
android {
namespace "expo.modules.astrasystemcolors"
defaultConfig {
versionCode 1
versionName "0.1.0"
}
lintOptions {
abortOnError false
}
}
@@ -0,0 +1,110 @@
package expo.modules.astrasystemcolors
import android.os.Build
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
/**
* Exposes Android 12+ monet system palettes (wallpaper-derived) to JS.
* Each ramp is 13 hex strings ordered by tone [0, 10, 50, 100..1000].
* Sync Functions on purpose: resource reads are microseconds, and it avoids
* the zero-arg Coroutine {} overload ambiguity in expo-modules-core.
*/
class AstraSystemColorsModule : Module() {
override fun definition() = ModuleDefinition {
Name("AstraSystemColors")
Function("isAvailable") { Build.VERSION.SDK_INT >= 31 }
Function("getSystemPalette") {
if (Build.VERSION.SDK_INT < 31) return@Function null
val context = appContext.reactContext ?: return@Function null
fun ramp(ids: IntArray) = ids.map { String.format("#%06x", context.getColor(it) and 0xFFFFFF) }
mapOf(
"accent1" to ramp(ACCENT1),
"accent2" to ramp(ACCENT2),
"accent3" to ramp(ACCENT3),
"neutral1" to ramp(NEUTRAL1),
"neutral2" to ramp(NEUTRAL2),
)
}
}
companion object {
private val ACCENT1 = intArrayOf(
android.R.color.system_accent1_0,
android.R.color.system_accent1_10,
android.R.color.system_accent1_50,
android.R.color.system_accent1_100,
android.R.color.system_accent1_200,
android.R.color.system_accent1_300,
android.R.color.system_accent1_400,
android.R.color.system_accent1_500,
android.R.color.system_accent1_600,
android.R.color.system_accent1_700,
android.R.color.system_accent1_800,
android.R.color.system_accent1_900,
android.R.color.system_accent1_1000,
)
private val ACCENT2 = intArrayOf(
android.R.color.system_accent2_0,
android.R.color.system_accent2_10,
android.R.color.system_accent2_50,
android.R.color.system_accent2_100,
android.R.color.system_accent2_200,
android.R.color.system_accent2_300,
android.R.color.system_accent2_400,
android.R.color.system_accent2_500,
android.R.color.system_accent2_600,
android.R.color.system_accent2_700,
android.R.color.system_accent2_800,
android.R.color.system_accent2_900,
android.R.color.system_accent2_1000,
)
private val ACCENT3 = intArrayOf(
android.R.color.system_accent3_0,
android.R.color.system_accent3_10,
android.R.color.system_accent3_50,
android.R.color.system_accent3_100,
android.R.color.system_accent3_200,
android.R.color.system_accent3_300,
android.R.color.system_accent3_400,
android.R.color.system_accent3_500,
android.R.color.system_accent3_600,
android.R.color.system_accent3_700,
android.R.color.system_accent3_800,
android.R.color.system_accent3_900,
android.R.color.system_accent3_1000,
)
private val NEUTRAL1 = intArrayOf(
android.R.color.system_neutral1_0,
android.R.color.system_neutral1_10,
android.R.color.system_neutral1_50,
android.R.color.system_neutral1_100,
android.R.color.system_neutral1_200,
android.R.color.system_neutral1_300,
android.R.color.system_neutral1_400,
android.R.color.system_neutral1_500,
android.R.color.system_neutral1_600,
android.R.color.system_neutral1_700,
android.R.color.system_neutral1_800,
android.R.color.system_neutral1_900,
android.R.color.system_neutral1_1000,
)
private val NEUTRAL2 = intArrayOf(
android.R.color.system_neutral2_0,
android.R.color.system_neutral2_10,
android.R.color.system_neutral2_50,
android.R.color.system_neutral2_100,
android.R.color.system_neutral2_200,
android.R.color.system_neutral2_300,
android.R.color.system_neutral2_400,
android.R.color.system_neutral2_500,
android.R.color.system_neutral2_600,
android.R.color.system_neutral2_700,
android.R.color.system_neutral2_800,
android.R.color.system_neutral2_900,
android.R.color.system_neutral2_1000,
)
}
}
@@ -0,0 +1,6 @@
{
"platforms": ["android"],
"android": {
"modules": ["expo.modules.astrasystemcolors.AstraSystemColorsModule"]
}
}
+28
View File
@@ -0,0 +1,28 @@
import { requireOptionalNativeModule, type NativeModule } from 'expo-modules-core';
/**
* Android 12+ monet system palettes (wallpaper-derived). Each ramp is 13 hex
* strings ordered by tone [0, 10, 50, 100, 200, ..., 900, 1000] — tone 0 is
* white-ish, tone 1000 black-ish.
*/
export interface SystemPalette {
accent1: string[];
accent2: string[];
accent3: string[];
neutral1: string[];
neutral2: string[];
}
declare class AstraSystemColorsModuleType extends NativeModule {
/** True on Android 12+ builds that include the native module. */
isAvailable(): boolean;
/** Current monet ramps, or null when unavailable. Sync — resource reads are microseconds. */
getSystemPalette(): SystemPalette | null;
}
const native = requireOptionalNativeModule<AstraSystemColorsModuleType>('AstraSystemColors');
export const AstraSystemColors = (native ?? {
isAvailable: () => false,
getSystemPalette: () => null,
}) as AstraSystemColorsModuleType;