@kbach/react-native 1.0.0-beta.2 → 1.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -26
- package/android/build.gradle +36 -0
- package/android/src/main/AndroidManifest.xml +14 -0
- package/android/src/main/java/com/kbachnative/KbachModule.kt +83 -0
- package/android/src/main/java/com/kbachnative/KbachPackage.kt +54 -0
- package/android/src/main/jniLibs/arm64-v8a/libkbach_core_engine.so +0 -0
- package/android/src/main/jniLibs/x86_64/libkbach_core_engine.so +0 -0
- package/dist/chunk-4KCCEMEN.mjs +66 -0
- package/dist/{chunk-YHF3QLRL.mjs → chunk-AEVOM2NB.mjs} +9 -12
- package/dist/{chunk-SVMYVXY6.mjs → chunk-DLIXI5OW.mjs} +23 -14
- package/dist/chunk-FG5E4NLJ.mjs +18 -0
- package/dist/chunk-KSDFO34H.mjs +32 -0
- package/dist/chunk-OJQAJLYT.mjs +14 -0
- package/dist/chunk-ZUE6SCTE.mjs +14 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +9 -2
- package/dist/index.mjs +9 -57
- package/dist/index.web.d.mts +7 -0
- package/dist/index.web.d.ts +7 -0
- package/dist/index.web.js +488 -0
- package/dist/index.web.mjs +32 -0
- package/dist/jsx-dev-runtime.d.mts +3 -12
- package/dist/jsx-dev-runtime.d.ts +3 -12
- package/dist/jsx-dev-runtime.js +61 -47
- package/dist/jsx-dev-runtime.mjs +8 -11
- package/dist/jsx-dev-runtime.web.d.mts +10 -0
- package/dist/jsx-dev-runtime.web.d.ts +10 -0
- package/dist/jsx-dev-runtime.web.js +437 -0
- package/dist/jsx-dev-runtime.web.mjs +17 -0
- package/dist/jsx-runtime.d.mts +3 -23
- package/dist/jsx-runtime.d.ts +3 -23
- package/dist/jsx-runtime.js +51 -38
- package/dist/jsx-runtime.mjs +6 -3
- package/dist/jsx-runtime.web.d.mts +7 -0
- package/dist/jsx-runtime.web.d.ts +7 -0
- package/dist/jsx-runtime.web.js +426 -0
- package/dist/jsx-runtime.web.mjs +14 -0
- package/package.json +27 -6
- package/react-native.config.js +29 -0
- package/specs/NativeKbachModule.ts +31 -0
package/README.md
CHANGED
|
@@ -4,11 +4,12 @@ Kbach's utility-class styling engine for React Native — the same class
|
|
|
4
4
|
names as [`@kbach/react`](https://www.npmjs.com/package/@kbach/react),
|
|
5
5
|
resolved to a real `StyleSheet`-ready style object instead of injected CSS.
|
|
6
6
|
|
|
7
|
-
> **Beta
|
|
8
|
-
>
|
|
9
|
-
>
|
|
10
|
-
>
|
|
11
|
-
>
|
|
7
|
+
> **Beta.** Native (Android-only, no iOS bridge yet) resolves through a
|
|
8
|
+
> Kotlin/JNI TurboModule; Expo Web / react-native-web resolves through the
|
|
9
|
+
> same Rust engine compiled to WASM instead — both call the identical
|
|
10
|
+
> resolution logic, so class semantics stay identical everywhere. The
|
|
11
|
+
> native module ships prebuilt (see Setup below) — no Rust toolchain or
|
|
12
|
+
> manual native wiring required on any platform.
|
|
12
13
|
|
|
13
14
|
## Setup
|
|
14
15
|
|
|
@@ -16,13 +17,13 @@ resolved to a real `StyleSheet`-ready style object instead of injected CSS.
|
|
|
16
17
|
npm install @kbach/react-native
|
|
17
18
|
```
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
autolinking discovers it automatically the moment it's
|
|
22
|
-
no manual `MainApplication.kt` edit needed. Works the
|
|
23
|
-
your app was created with the React Native CLI or with
|
|
24
|
-
Expo Go**, which can never load this (or any) custom
|
|
25
|
-
below.
|
|
20
|
+
One package, nothing else to install — the Kotlin TurboModule and its
|
|
21
|
+
prebuilt native `.so` ship inside this same package's own `android/`
|
|
22
|
+
folder. Android's autolinking discovers it automatically the moment it's
|
|
23
|
+
in `node_modules`; no manual `MainApplication.kt` edit needed. Works the
|
|
24
|
+
same way whether your app was created with the React Native CLI or with
|
|
25
|
+
Expo — **except Expo Go**, which can never load this (or any) custom
|
|
26
|
+
native module; see below.
|
|
26
27
|
|
|
27
28
|
### React Native CLI
|
|
28
29
|
|
|
@@ -46,13 +47,18 @@ one needs (a plain single-app install doesn't need any of that — it's
|
|
|
46
47
|
only relevant if you're linking packages locally instead of installing
|
|
47
48
|
from npm).
|
|
48
49
|
|
|
49
|
-
### Expo
|
|
50
|
+
### Expo (native — Android)
|
|
50
51
|
|
|
51
|
-
**Expo Go
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
**Expo Go can never work with this package, and that isn't specific to
|
|
53
|
+
Kbach.** Expo Go is a single fixed binary Expo pre-builds and ships
|
|
54
|
+
through the app stores, containing only the native code Expo bundled into
|
|
55
|
+
it at their own build time — there is no mechanism for *any* third-party
|
|
56
|
+
package to add native code to it at runtime, whether that's a raw
|
|
57
|
+
TurboModule (what this package uses) or even Expo's own Modules API. This
|
|
58
|
+
is exactly why the **dev client** concept exists: a custom build of your
|
|
59
|
+
app — built once via `expo prebuild`/`expo run:android`, functionally the
|
|
60
|
+
same "real native project" as the CLI path above — that *does* include
|
|
61
|
+
this module:
|
|
56
62
|
|
|
57
63
|
```js
|
|
58
64
|
// babel.config.js
|
|
@@ -68,7 +74,7 @@ npx expo run:android # builds and installs a dev client with the native module i
|
|
|
68
74
|
```
|
|
69
75
|
|
|
70
76
|
Also requires the New Architecture enabled (Expo's default in current SDK
|
|
71
|
-
versions) —
|
|
77
|
+
versions) — the native module is a TurboModule, which doesn't exist under
|
|
72
78
|
the legacy bridge at all. If you're on an older SDK/config with the New
|
|
73
79
|
Architecture off, turn it on in `app.json`
|
|
74
80
|
(`"newArchEnabled": true` under `expo`) before prebuilding.
|
|
@@ -76,6 +82,25 @@ Architecture off, turn it on in `app.json`
|
|
|
76
82
|
EAS Build works the same way — it runs the same `prebuild` step, so no
|
|
77
83
|
extra configuration beyond the two steps above.
|
|
78
84
|
|
|
85
|
+
### Expo Web
|
|
86
|
+
|
|
87
|
+
**Works — no extra setup, no separate package, no init call.** `expo start
|
|
88
|
+
--web` (and EAS's web builds) render through `react-native-web` —
|
|
89
|
+
`View`/`Text`/etc. become real DOM elements with real CSS, not a
|
|
90
|
+
Kotlin/JNI bridge, so on web this package resolves classes through the
|
|
91
|
+
same Rust engine [`@kbach/react`](https://www.npmjs.com/package/@kbach/react)
|
|
92
|
+
uses — WASM instead of JNI — automatically. Metro picks the right
|
|
93
|
+
implementation per platform on its own via this package's `"browser"`
|
|
94
|
+
export condition; your app code and JSX never change. The WASM module
|
|
95
|
+
initializes itself eagerly (synchronously, at import time — no `await`
|
|
96
|
+
needed before your first render, unlike a from-scratch WASM setup).
|
|
97
|
+
|
|
98
|
+
The only thing this doesn't cover on web is an iOS-parity feature gap —
|
|
99
|
+
everything web-side resolves through the exact same
|
|
100
|
+
[`resolve_style.rs`](https://github.com/semsakadanupol/kbach/blob/main/packages/core-engine/src/resolve_style.rs)
|
|
101
|
+
logic real native uses, so see this README's "What this is" section above
|
|
102
|
+
for what's covered.
|
|
103
|
+
|
|
79
104
|
## What this is
|
|
80
105
|
|
|
81
106
|
- A JSX runtime (`@kbach/react-native/jsx-runtime`) that intercepts
|
|
@@ -88,14 +113,22 @@ extra configuration beyond the two steps above.
|
|
|
88
113
|
scale — the same `ThemeConfig` shape `@kbach/react` uses, kept as an
|
|
89
114
|
independent type here so a native-only project isn't forced to depend on
|
|
90
115
|
a web-oriented package.
|
|
91
|
-
- `shadow-*` resolves to real native shadows —
|
|
92
|
-
`shadowColor`/`shadowOffset`/`shadowOpacity`/`shadowRadius`
|
|
93
|
-
`elevation
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
116
|
+
- `shadow-*` resolves to real native shadows — RN's discrete
|
|
117
|
+
`shadowColor`/`shadowOffset`/`shadowOpacity`/`shadowRadius` props plus
|
|
118
|
+
Android's `elevation` (both emitted together; `elevation` is what
|
|
119
|
+
actually renders a shadow on Android — the `shadow*` props are iOS-only
|
|
120
|
+
in RN itself, ready for whenever this package gets an iOS bridge),
|
|
121
|
+
derived from the same named tiers (`sm`/`DEFAULT`/`md`/`lg`/`xl`/`2xl`)
|
|
122
|
+
`@kbach/react`'s CSS `box-shadow` scale uses. `shadow-inner` and
|
|
123
|
+
arbitrary `shadow-[...]` values aren't supported — RN's native shadow
|
|
124
|
+
props can't express an inset shadow, and an arbitrary value is a raw CSS
|
|
98
125
|
string with no mechanical translation into discrete native props.
|
|
126
|
+
- Responsive breakpoints (`sm:`/`md:`/`lg:`/`xl:`/`2xl:`) — gated live
|
|
127
|
+
against the current window width (`Dimensions.get('window').width`),
|
|
128
|
+
same mobile-first "min-width and up" semantics as web, and freely
|
|
129
|
+
combinable with `dark:`/`active:` (e.g. `dark:md:bg-blue-8`). Call RN's
|
|
130
|
+
own `useWindowDimensions()` somewhere in your tree to re-render on
|
|
131
|
+
rotation/resize — same role `useColorScheme()` plays for `dark:` below.
|
|
99
132
|
|
|
100
133
|
## Dark mode
|
|
101
134
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
apply plugin: "com.android.library"
|
|
2
|
+
apply plugin: "org.jetbrains.kotlin.android"
|
|
3
|
+
apply plugin: "com.facebook.react"
|
|
4
|
+
|
|
5
|
+
def getExtOrDefault(name) {
|
|
6
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : null
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
android {
|
|
10
|
+
// NOT "com.kbachnative" — that's the app module's own namespace (Phase 5
|
|
11
|
+
// deliberately made the app's package match KbachModule's Kotlin package
|
|
12
|
+
// for simpler JNI symbol names), and AGP requires unique namespaces per
|
|
13
|
+
// module. This is purely a Gradle build-identity value, separate from
|
|
14
|
+
// the actual `package com.kbachnative` declared in the .kt files below —
|
|
15
|
+
// JNI symbol resolution depends on that Kotlin package, not this.
|
|
16
|
+
namespace "com.kbachnative.nativemodule"
|
|
17
|
+
compileSdkVersion getExtOrDefault("compileSdkVersion")
|
|
18
|
+
|
|
19
|
+
defaultConfig {
|
|
20
|
+
minSdkVersion getExtOrDefault("minSdkVersion")
|
|
21
|
+
targetSdkVersion getExtOrDefault("targetSdkVersion")
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
repositories {
|
|
26
|
+
google()
|
|
27
|
+
maven {
|
|
28
|
+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm.
|
|
29
|
+
url "$rootDir/../node_modules/react-native/android"
|
|
30
|
+
}
|
|
31
|
+
mavenCentral()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
dependencies {
|
|
35
|
+
implementation "com.facebook.react:react-native:+"
|
|
36
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Deliberately NO `package="..."` attribute here, even though this
|
|
3
|
+
module's Kotlin package (com.kbachnative, see KbachModule.kt) differs
|
|
4
|
+
from its Gradle build.gradle `namespace` (com.kbachnative.nativemodule)
|
|
5
|
+
— adding one here to help React Native's autolinking guess the right
|
|
6
|
+
Kotlin package (see react-native.config.js at this package's root, which
|
|
7
|
+
fixes that instead) breaks the actual Gradle build on AGP 9+: it now
|
|
8
|
+
hard-errors ("Setting the namespace via the package attribute in the
|
|
9
|
+
source AndroidManifest.xml is no longer supported") whenever the
|
|
10
|
+
manifest's package doesn't match the namespace exactly. If you're
|
|
11
|
+
tempted to add one back to fix an autolinking symbol-resolution error,
|
|
12
|
+
fix react-native.config.js's packageImportPath/packageInstance instead.
|
|
13
|
+
-->
|
|
14
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
package com.kbachnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Bridges to the same Rust core engine every other Kbach platform uses
|
|
7
|
+
* (packages/core-engine) — via JNI here instead of WASM. The native
|
|
8
|
+
* `generateCss`/`resolveStyle` externs below (in the companion object) must
|
|
9
|
+
* match `Java_com_kbachnative_KbachModule_generateCss`/`resolveStyle`'s
|
|
10
|
+
* signatures exactly (packages/core-engine/src/jni_bridge.rs): STATIC
|
|
11
|
+
* native methods (hence @JvmStatic in a companion object, not instance
|
|
12
|
+
* methods — the Rust side takes JClass, not JObject, as its second
|
|
13
|
+
* parameter).
|
|
14
|
+
*
|
|
15
|
+
* TurboModule since Phase 13 (was the legacy bridge's
|
|
16
|
+
* `isBlockingSynchronousMethod` support directly on `ReactContextBaseJavaModule`
|
|
17
|
+
* before) — extends the Codegen-generated `NativeKbachModuleSpec`
|
|
18
|
+
* (packages/react-native/specs/NativeKbachModule.ts -> this package's own
|
|
19
|
+
* codegenConfig in package.json, discovered via autolinking ->
|
|
20
|
+
* android/build/generated/source/codegen/java/com/kbachnative/NativeKbachModuleSpec.java),
|
|
21
|
+
* which already provides `getName()` and declares `generateCss`/`resolveStyle`
|
|
22
|
+
* as abstract `@ReactMethod(isBlockingSynchronousMethod = true)` methods —
|
|
23
|
+
* Codegen still routes a synchronously-returning TurboModule method through
|
|
24
|
+
* that same Android bridge mechanism; the real gain here is JSI-backed
|
|
25
|
+
* dispatch + build-time type checking against the JS spec, not the removal
|
|
26
|
+
* of `isBlockingSynchronousMethod` as a concept.
|
|
27
|
+
*
|
|
28
|
+
* The companion's JNI externs are named `nativeGenerateCss`/`nativeResolveStyle`
|
|
29
|
+
* — NOT the same names as the spec's `generateCss`/`resolveStyle` overrides.
|
|
30
|
+
* Tried keeping identical names first (disambiguated via an explicit
|
|
31
|
+
* `Companion.generateCss(...)` qualifier) since that would've meant zero
|
|
32
|
+
* Rust changes, but that fails to compile: `@JvmStatic` duplicates each
|
|
33
|
+
* companion function directly onto the outer class for Java-interop
|
|
34
|
+
* purposes, which collides at the JVM bytecode level with the identically-
|
|
35
|
+
* named, identically-shaped instance override ("platform declaration
|
|
36
|
+
* clash"), regardless of how the Kotlin-source call site is qualified. The
|
|
37
|
+
* rename requires matching `Java_com_kbachnative_KbachModule_nativeGenerateCss`/
|
|
38
|
+
* `nativeResolveStyle` `#[no_mangle]` export names in
|
|
39
|
+
* packages/core-engine/src/jni_bridge.rs — JNI's implicit symbol linking
|
|
40
|
+
* binds by the extern's own method name, not by whatever calls it.
|
|
41
|
+
*
|
|
42
|
+
* Moved here from apps/native-sandbox/android/app in Phase 13 — Android
|
|
43
|
+
* autolinking only discovers native modules from npm dependencies with
|
|
44
|
+
* their own `android/` folder, never from native code declared directly
|
|
45
|
+
* inside the app itself, so `KbachModule` had to become a real (locally
|
|
46
|
+
* `file:`-linked) package to be found by `TurboModuleRegistry.getEnforcing`.
|
|
47
|
+
* Originally that "real package" was a separate `@kbach/android` npm
|
|
48
|
+
* package; later folded directly into `@kbach/react-native` (this
|
|
49
|
+
* package's own `android/` folder, sibling to its `src/`) once it became
|
|
50
|
+
* clear the same autolinking requirement is satisfied just as well by a
|
|
51
|
+
* SINGLE npm package containing both JS and native code — the same layout
|
|
52
|
+
* react-native-safe-area-context itself uses — so consumers only ever run
|
|
53
|
+
* one `npm install @kbach/react-native`, not two.
|
|
54
|
+
*/
|
|
55
|
+
class KbachModule(reactContext: ReactApplicationContext) : NativeKbachModuleSpec(reactContext) {
|
|
56
|
+
|
|
57
|
+
companion object {
|
|
58
|
+
init {
|
|
59
|
+
System.loadLibrary("kbach_core_engine")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@JvmStatic
|
|
63
|
+
external fun nativeGenerateCss(classString: String, themeJson: String): String
|
|
64
|
+
|
|
65
|
+
@JvmStatic
|
|
66
|
+
external fun nativeResolveStyle(classString: String, themeJson: String, colorScheme: String, pressed: Boolean, width: Double): String
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
override fun generateCss(classString: String, themeJson: String): String {
|
|
70
|
+
return nativeGenerateCss(classString, themeJson)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* `colorScheme` ("light"/"dark", from Appearance.getColorScheme() on the
|
|
75
|
+
* JS side) gates whether `dark:` declarations are applied; `pressed`
|
|
76
|
+
* (only ever true when the caller is RN's Pressable) gates `active:`;
|
|
77
|
+
* `width` (the JS side's current `Dimensions.get('window').width`) gates
|
|
78
|
+
* `sm:`/`md:`/`lg:`/`xl:`/`2xl:` against the theme's `screens` scale.
|
|
79
|
+
*/
|
|
80
|
+
override fun resolveStyle(classString: String, themeJson: String, colorScheme: String, pressed: Boolean, width: Double): String {
|
|
81
|
+
return nativeResolveStyle(classString, themeJson, colorScheme, pressed, width)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
package com.kbachnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
+
import com.facebook.react.uimanager.ViewManager
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `BaseReactPackage` (not plain `ReactPackage`) since Phase 13's TurboModule
|
|
12
|
+
* migration — a plain `ReactPackage`'s `createNativeModules()`-provided
|
|
13
|
+
* modules stay visible to the legacy `NativeModules` interop but are never
|
|
14
|
+
* consulted by `TurboModuleRegistry`'s resolution path, which only walks
|
|
15
|
+
* packages that can answer `getModule(name, ...)` directly. Modeled on
|
|
16
|
+
* react-native-safe-area-context's own `SafeAreaContextPackage.kt` (a real,
|
|
17
|
+
* New-Architecture-compatible package already in this project's
|
|
18
|
+
* dependencies) rather than reflection over a `@ReactModule` annotation —
|
|
19
|
+
* KbachModule doesn't have one, and there's only ever this one module, so
|
|
20
|
+
* building its `ReactModuleInfo` directly is simpler than adding an
|
|
21
|
+
* annotation just to read it back via reflection.
|
|
22
|
+
*
|
|
23
|
+
* Auto-discovered via Android autolinking, not manually registered in
|
|
24
|
+
* apps/native-sandbox's MainApplication.kt — same as SafeAreaContextPackage
|
|
25
|
+
* already was, and the entire reason this module became a real npm package
|
|
26
|
+
* with its own `android/` folder (this one — `@kbach/react-native` itself,
|
|
27
|
+
* see KbachModule.kt's own doc comment) in Phase 13 rather than living
|
|
28
|
+
* inside the app.
|
|
29
|
+
*/
|
|
30
|
+
class KbachPackage : BaseReactPackage() {
|
|
31
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
32
|
+
return if (name == NativeKbachModuleSpec.NAME) KbachModule(reactContext) else null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
36
|
+
return ReactModuleInfoProvider {
|
|
37
|
+
mapOf(
|
|
38
|
+
NativeKbachModuleSpec.NAME to
|
|
39
|
+
ReactModuleInfo(
|
|
40
|
+
NativeKbachModuleSpec.NAME,
|
|
41
|
+
KbachModule::class.java.name,
|
|
42
|
+
false, // canOverrideExistingModule
|
|
43
|
+
false, // needsEagerInit
|
|
44
|
+
false, // isCxxModule
|
|
45
|
+
true, // isTurboModule
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
52
|
+
return emptyList()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getGlobalDarkMode,
|
|
3
|
+
getGlobalThemeMode,
|
|
4
|
+
seedDefaultMode,
|
|
5
|
+
setGlobalThemeMode,
|
|
6
|
+
subscribeGlobalDarkMode,
|
|
7
|
+
toggleGlobalDarkMode
|
|
8
|
+
} from "./chunk-AEVOM2NB.mjs";
|
|
9
|
+
|
|
10
|
+
// src/useGlobalDarkMode.ts
|
|
11
|
+
import { useSyncExternalStore } from "react";
|
|
12
|
+
function useGlobalDarkMode() {
|
|
13
|
+
return useSyncExternalStore(subscribeGlobalDarkMode, getGlobalDarkMode);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/ThemeContext.tsx
|
|
17
|
+
import { createContext, useContext } from "react";
|
|
18
|
+
var ThemeContext = createContext(null);
|
|
19
|
+
function useTheme() {
|
|
20
|
+
const ctx = useContext(ThemeContext);
|
|
21
|
+
if (!ctx) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
'useTheme() must be called within a <ThemeProvider>. For dark-mode state without a provider, use useGlobalDarkMode() (read) or toggleGlobalDarkMode()/setGlobalThemeMode() (write) from "@kbach/react-native" instead.'
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return ctx;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/ThemeProvider.tsx
|
|
30
|
+
import { useEffect, useMemo, useRef, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
31
|
+
import { jsx } from "react/jsx-runtime";
|
|
32
|
+
var mountedProviderCount = 0;
|
|
33
|
+
var warnedMultipleProviders = false;
|
|
34
|
+
function ThemeProvider({ children, defaultMode = "system" }) {
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
mountedProviderCount++;
|
|
37
|
+
if (mountedProviderCount > 1 && !warnedMultipleProviders) {
|
|
38
|
+
warnedMultipleProviders = true;
|
|
39
|
+
console.warn(
|
|
40
|
+
"[kbach] Multiple <ThemeProvider> instances are mounted at once. Dark-mode state is one global store (the same one useGlobalDarkMode()/toggleGlobalDarkMode() read and write), not scoped per-provider, so they will fight over the same state instead of each getting their own."
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return () => {
|
|
44
|
+
mountedProviderCount--;
|
|
45
|
+
};
|
|
46
|
+
}, []);
|
|
47
|
+
const seeded = useRef(false);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (seeded.current) return;
|
|
50
|
+
seeded.current = true;
|
|
51
|
+
seedDefaultMode(defaultMode);
|
|
52
|
+
}, []);
|
|
53
|
+
const isDark = useSyncExternalStore2(subscribeGlobalDarkMode, getGlobalDarkMode);
|
|
54
|
+
const mode = useSyncExternalStore2(subscribeGlobalDarkMode, getGlobalThemeMode);
|
|
55
|
+
const value = useMemo(
|
|
56
|
+
() => ({ mode, isDark, setMode: setGlobalThemeMode, toggle: toggleGlobalDarkMode }),
|
|
57
|
+
[mode, isDark]
|
|
58
|
+
);
|
|
59
|
+
return /* @__PURE__ */ jsx(ThemeContext.Provider, { value, children });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export {
|
|
63
|
+
useGlobalDarkMode,
|
|
64
|
+
useTheme,
|
|
65
|
+
ThemeProvider
|
|
66
|
+
};
|
|
@@ -289,7 +289,13 @@ var defaultTheme = {
|
|
|
289
289
|
"6": 24,
|
|
290
290
|
"8": 32
|
|
291
291
|
},
|
|
292
|
-
screens: {
|
|
292
|
+
screens: {
|
|
293
|
+
sm: 640,
|
|
294
|
+
md: 768,
|
|
295
|
+
lg: 1024,
|
|
296
|
+
xl: 1280,
|
|
297
|
+
"2xl": 1536
|
|
298
|
+
},
|
|
293
299
|
darkMode: "attribute"
|
|
294
300
|
};
|
|
295
301
|
var activeTheme = defaultTheme;
|
|
@@ -351,24 +357,15 @@ function seedDefaultMode(fallback) {
|
|
|
351
357
|
notify();
|
|
352
358
|
}
|
|
353
359
|
|
|
354
|
-
// src/nativeBridge.ts
|
|
355
|
-
import { TurboModuleRegistry } from "react-native";
|
|
356
|
-
function resolveStyle(classString, pressed = false) {
|
|
357
|
-
const KbachModule = TurboModuleRegistry.getEnforcing("KbachModule");
|
|
358
|
-
const colorScheme = getGlobalDarkMode() ? "dark" : "light";
|
|
359
|
-
const json = KbachModule.resolveStyle(classString, getThemeJson(), colorScheme, pressed);
|
|
360
|
-
return JSON.parse(json);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
360
|
export {
|
|
364
361
|
defaultTheme,
|
|
365
362
|
setTheme,
|
|
366
363
|
getTheme,
|
|
364
|
+
getThemeJson,
|
|
367
365
|
getGlobalDarkMode,
|
|
368
366
|
getGlobalThemeMode,
|
|
369
367
|
setGlobalThemeMode,
|
|
370
368
|
toggleGlobalDarkMode,
|
|
371
369
|
subscribeGlobalDarkMode,
|
|
372
|
-
seedDefaultMode
|
|
373
|
-
resolveStyle
|
|
370
|
+
seedDefaultMode
|
|
374
371
|
};
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
resolveStyle
|
|
3
|
-
} from "./chunk-YHF3QLRL.mjs";
|
|
4
|
-
|
|
5
|
-
// src/jsx-runtime.tsx
|
|
1
|
+
// src/jsxRuntimeCore.ts
|
|
6
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
3
|
import { Fragment } from "react";
|
|
8
4
|
import { Pressable } from "react-native";
|
|
9
5
|
function makeElement(isStaticChildren, type, props, key) {
|
|
10
6
|
return (isStaticChildren ? _jsxs : _jsx)(type, props, key);
|
|
11
7
|
}
|
|
12
|
-
function resolvedStyleFor(classStrRaw, userStyle, pressed) {
|
|
8
|
+
function resolvedStyleFor(resolveStyle, classStrRaw, userStyle, pressed) {
|
|
13
9
|
const resolved = resolveStyle(classStrRaw, pressed);
|
|
14
10
|
if (userStyle === void 0) {
|
|
15
11
|
return resolved;
|
|
@@ -19,7 +15,7 @@ function resolvedStyleFor(classStrRaw, userStyle, pressed) {
|
|
|
19
15
|
}
|
|
20
16
|
return [resolved, userStyle];
|
|
21
17
|
}
|
|
22
|
-
function processElement(type, rawProps, key, isStaticChildren) {
|
|
18
|
+
function processElement(resolveStyle, type, rawProps, key, isStaticChildren) {
|
|
23
19
|
if (type === null || typeof type === "symbol" || !rawProps) {
|
|
24
20
|
return makeElement(isStaticChildren, type, rawProps ?? {}, key);
|
|
25
21
|
}
|
|
@@ -27,18 +23,31 @@ function processElement(type, rawProps, key, isStaticChildren) {
|
|
|
27
23
|
if (typeof classStrRaw !== "string") {
|
|
28
24
|
return makeElement(isStaticChildren, type, rawProps, key);
|
|
29
25
|
}
|
|
30
|
-
const finalStyle = type === Pressable ? (state) => resolvedStyleFor(classStrRaw, userStyle, state.pressed) : resolvedStyleFor(classStrRaw, userStyle, false);
|
|
26
|
+
const finalStyle = type === Pressable ? (state) => resolvedStyleFor(resolveStyle, classStrRaw, userStyle, state.pressed) : resolvedStyleFor(resolveStyle, classStrRaw, userStyle, false);
|
|
31
27
|
return makeElement(isStaticChildren, type, { ...rest, style: finalStyle }, key);
|
|
32
28
|
}
|
|
33
|
-
function
|
|
34
|
-
|
|
29
|
+
function createJsxFunctions(resolveStyle) {
|
|
30
|
+
function jsx(type, props, key) {
|
|
31
|
+
return processElement(resolveStyle, type, props, key, false);
|
|
32
|
+
}
|
|
33
|
+
function jsxs(type, props, key) {
|
|
34
|
+
return processElement(resolveStyle, type, props, key, true);
|
|
35
|
+
}
|
|
36
|
+
return { jsx, jsxs };
|
|
35
37
|
}
|
|
36
|
-
function
|
|
37
|
-
return
|
|
38
|
+
function createJsxDEV(jsx, jsxs) {
|
|
39
|
+
return function jsxDEV(type, props, key, isStaticChildren, source, self) {
|
|
40
|
+
const element = (isStaticChildren ? jsxs : jsx)(type, props, key);
|
|
41
|
+
if (source && element && typeof element === "object" && Object.isExtensible(element)) {
|
|
42
|
+
element._source = source;
|
|
43
|
+
element._self = self;
|
|
44
|
+
}
|
|
45
|
+
return element;
|
|
46
|
+
};
|
|
38
47
|
}
|
|
39
48
|
|
|
40
49
|
export {
|
|
41
50
|
Fragment,
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
createJsxFunctions,
|
|
52
|
+
createJsxDEV
|
|
44
53
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getGlobalDarkMode,
|
|
3
|
+
getThemeJson
|
|
4
|
+
} from "./chunk-AEVOM2NB.mjs";
|
|
5
|
+
|
|
6
|
+
// src/nativeBridge.ts
|
|
7
|
+
import { Dimensions, TurboModuleRegistry } from "react-native";
|
|
8
|
+
function resolveStyle(classString, pressed = false) {
|
|
9
|
+
const KbachModule = TurboModuleRegistry.getEnforcing("KbachModule");
|
|
10
|
+
const colorScheme = getGlobalDarkMode() ? "dark" : "light";
|
|
11
|
+
const width = Dimensions.get("window").width;
|
|
12
|
+
const json = KbachModule.resolveStyle(classString, getThemeJson(), colorScheme, pressed, width);
|
|
13
|
+
return JSON.parse(json);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
resolveStyle
|
|
18
|
+
};
|