@kbach/react-native 1.0.0-beta.1 → 1.0.0-beta.11
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 +87 -66
- 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-4DQXTAM3.mjs +63 -0
- package/dist/chunk-5MU6PEXV.mjs +14 -0
- package/dist/chunk-H5Z24XX5.mjs +192 -0
- package/dist/{chunk-YHF3QLRL.mjs → chunk-HK6PDJJK.mjs} +61 -68
- package/dist/chunk-RBJXE32L.mjs +73 -0
- package/dist/chunk-TDWBXJH5.mjs +186 -0
- package/dist/chunk-XHL653X2.mjs +1211 -0
- package/dist/chunk-YOC3SHF5.mjs +40 -0
- package/dist/index.d.mts +37 -102
- package/dist/index.d.ts +37 -102
- package/dist/index.js +1411 -38
- package/dist/index.mjs +19 -61
- package/dist/index.web.d.mts +15 -0
- package/dist/index.web.d.ts +15 -0
- package/dist/index.web.js +829 -0
- package/dist/index.web.mjs +38 -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 +1313 -36
- package/dist/jsx-dev-runtime.mjs +9 -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 +659 -0
- package/dist/jsx-dev-runtime.web.mjs +18 -0
- package/dist/jsx-runtime.d.mts +3 -23
- package/dist/jsx-runtime.d.ts +3 -23
- package/dist/jsx-runtime.js +1304 -28
- package/dist/jsx-runtime.mjs +7 -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 +602 -0
- package/dist/jsx-runtime.web.mjs +12 -0
- package/dist/useColors-C6jyCLuG.d.mts +239 -0
- package/dist/useColors-C6jyCLuG.d.ts +239 -0
- package/package.json +57 -8
- package/react-native.config.js +29 -0
- package/specs/NativeKbachModule.ts +31 -0
- package/src/babel-plugin.js +74 -2
- package/dist/chunk-SVMYVXY6.mjs +0 -44
package/README.md
CHANGED
|
@@ -2,27 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
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
|
-
resolved to a
|
|
5
|
+
resolved to a `StyleSheet`-ready style object instead of injected CSS.
|
|
6
6
|
|
|
7
|
-
>
|
|
8
|
-
>
|
|
9
|
-
> identical across web and native. The native module ships prebuilt (see
|
|
10
|
-
> Setup below) — no Rust toolchain or manual native wiring required — but
|
|
11
|
-
> there's no iOS bridge yet.
|
|
7
|
+
> Beta. Native is Android-only (no iOS bridge yet). Ships a prebuilt native
|
|
8
|
+
> module — no Rust toolchain or manual native wiring required.
|
|
12
9
|
|
|
13
|
-
##
|
|
10
|
+
## Install
|
|
14
11
|
|
|
15
12
|
```sh
|
|
16
13
|
npm install @kbach/react-native
|
|
17
14
|
```
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
too — the actual native module — as a real dependency. Android's
|
|
21
|
-
autolinking discovers it automatically the moment it's in `node_modules`;
|
|
22
|
-
no manual `MainApplication.kt` edit needed.
|
|
23
|
-
|
|
24
|
-
Add the Babel plugin so your app's JSX routes through Kbach's JSX runtime
|
|
25
|
-
instead of `react/jsx-runtime`:
|
|
16
|
+
### React Native CLI
|
|
26
17
|
|
|
27
18
|
```js
|
|
28
19
|
// babel.config.js
|
|
@@ -32,74 +23,104 @@ module.exports = {
|
|
|
32
23
|
};
|
|
33
24
|
```
|
|
34
25
|
|
|
35
|
-
|
|
36
|
-
you're re-running one that's already built) so Gradle picks up the new
|
|
37
|
-
native module. See `apps/native-sandbox` in the
|
|
38
|
-
[repo](https://github.com/semsakadanupol/kbach) for a full working
|
|
39
|
-
reference project, including the Metro config a monorepo setup like this
|
|
40
|
-
one needs (a plain single-app install doesn't need any of that — it's
|
|
41
|
-
only relevant if you're linking packages locally instead of installing
|
|
42
|
-
from npm).
|
|
43
|
-
|
|
44
|
-
## What this is
|
|
45
|
-
|
|
46
|
-
- A JSX runtime (`@kbach/react-native/jsx-runtime`) that intercepts
|
|
47
|
-
`className`/`kb` props on every element and calls into the native bridge
|
|
48
|
-
to resolve them to a style object, synchronously, on every render.
|
|
49
|
-
- A Babel plugin (`@kbach/react-native/babel-plugin`) that routes your
|
|
50
|
-
app's own files (never `node_modules`) through that JSX runtime via a
|
|
51
|
-
per-file `@jsxImportSource` pragma.
|
|
52
|
-
- `setTheme()`/`getTheme()` for customizing the color palette and spacing
|
|
53
|
-
scale — the same `ThemeConfig` shape `@kbach/react` uses, kept as an
|
|
54
|
-
independent type here so a native-only project isn't forced to depend on
|
|
55
|
-
a web-oriented package.
|
|
56
|
-
- `shadow-*` resolves to real native shadows — iOS's discrete
|
|
57
|
-
`shadowColor`/`shadowOffset`/`shadowOpacity`/`shadowRadius` and Android's
|
|
58
|
-
`elevation`, both derived from the same named tiers (`sm`/`DEFAULT`/`md`/
|
|
59
|
-
`lg`/`xl`/`2xl`) `@kbach/react`'s CSS `box-shadow` scale uses — one class
|
|
60
|
-
produces a real shadow on both platforms. `shadow-inner` and arbitrary
|
|
61
|
-
`shadow-[...]` values aren't supported — neither platform's native shadow
|
|
62
|
-
API can express an inset shadow, and an arbitrary value is a raw CSS
|
|
63
|
-
string with no mechanical translation into discrete native props.
|
|
26
|
+
Rebuild the Android app afterward so Gradle picks up the native module.
|
|
64
27
|
|
|
65
|
-
|
|
28
|
+
### Expo Go
|
|
29
|
+
|
|
30
|
+
Works out of the box — no prebuild, no dev client, nothing to configure.
|
|
31
|
+
Expo Go can't load third-party native code, so this falls back to a pure-JS
|
|
32
|
+
engine automatically. Covers layout, spacing, border/radius, plain colors,
|
|
33
|
+
font-weight, text-transform/decoration, line-height, letter-spacing, and
|
|
34
|
+
shadows. Doesn't cover grid, transforms, filters, gradients, or DOM-only
|
|
35
|
+
typography — same scope native itself excludes.
|
|
36
|
+
|
|
37
|
+
### Expo (dev client / prebuild)
|
|
38
|
+
|
|
39
|
+
Gets you the full native engine instead of the JS fallback:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
// babel.config.js
|
|
43
|
+
module.exports = {
|
|
44
|
+
presets: ['babel-preset-expo'],
|
|
45
|
+
plugins: ['@kbach/react-native/babel-plugin'],
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
npx expo prebuild
|
|
51
|
+
npx expo run:android
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Requires the New Architecture enabled (`"newArchEnabled": true` in
|
|
55
|
+
`app.json`, on by default in current Expo SDKs). EAS Build works the same
|
|
56
|
+
way, no extra config.
|
|
66
57
|
|
|
67
|
-
|
|
58
|
+
### Expo Web
|
|
59
|
+
|
|
60
|
+
Works out of the box — resolves through the same real-CSS engine
|
|
61
|
+
`@kbach/react` uses on the DOM, with full modifier support (`hover:`,
|
|
62
|
+
`focus:`, `group-hover:`, container queries, etc.), not just the
|
|
63
|
+
`dark:`/`active:`/responsive subset native supports.
|
|
64
|
+
|
|
65
|
+
**Static rendering (SSR) caveat:** `dark:`/responsive classes on content
|
|
66
|
+
that's part of the initial pre-rendered HTML resolve against the *server*,
|
|
67
|
+
not the visiting browser — so a user in dark mode can briefly see the light
|
|
68
|
+
version on first paint. Defer preference-dependent classes until mounted:
|
|
68
69
|
|
|
69
70
|
```tsx
|
|
70
|
-
|
|
71
|
+
const [mounted, setMounted] = useState(false);
|
|
72
|
+
useEffect(() => setMounted(true), []);
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
const isDark = useGlobalDarkMode();
|
|
74
|
-
return <Pressable onPress={toggleGlobalDarkMode}><Text>{isDark ? 'Dark' : 'Light'}</Text></Pressable>;
|
|
75
|
-
}
|
|
74
|
+
<View className={mounted ? 'bg-gray-1 dark:bg-gray-12' : 'bg-gray-1'} />;
|
|
76
75
|
```
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
the exact same global store:
|
|
77
|
+
## Dark mode
|
|
80
78
|
|
|
81
79
|
```tsx
|
|
82
|
-
import {
|
|
80
|
+
import { useTheme } from '@kbach/react-native';
|
|
83
81
|
|
|
84
|
-
function
|
|
82
|
+
function ThemeToggle() {
|
|
85
83
|
const { mode, isDark, setMode, toggle } = useTheme();
|
|
86
84
|
return <Pressable onPress={toggle}><Text>{mode}</Text></Pressable>;
|
|
87
85
|
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Works anywhere, no provider needed. `<ThemeProvider defaultMode="dark">` is
|
|
89
|
+
optional, for seeding a startup default. Outside React, use
|
|
90
|
+
`getGlobalDarkMode()`/`toggleGlobalDarkMode()` instead.
|
|
91
|
+
|
|
92
|
+
Follows the OS setting live until overridden, and isn't persisted across
|
|
93
|
+
app launches (no built-in storage dependency). To persist, read your own
|
|
94
|
+
storage at startup and call `setGlobalThemeMode()` before your first render.
|
|
95
|
+
|
|
96
|
+
## Reading colors as values
|
|
97
|
+
|
|
98
|
+
For anywhere you need a real color, not a `className` — a chart prop, a
|
|
99
|
+
native shadow color:
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
import { useColors } from '@kbach/react-native';
|
|
103
|
+
|
|
104
|
+
const colors = useColors();
|
|
105
|
+
colors.blue[6]; // '#2563eb' — static, same value in both modes
|
|
106
|
+
colors.blue['6/50']; // same, at 50% opacity
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Any color can be defined in the theme as a plain string (static) or a
|
|
110
|
+
`{ light, dark }` pair — fully manual, resolved per the current dark-mode
|
|
111
|
+
state:
|
|
88
112
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
113
|
+
```ts
|
|
114
|
+
setTheme({
|
|
115
|
+
...defaultTheme,
|
|
116
|
+
colors: { ...defaultTheme.colors, brand: { light: '#2563eb', dark: '#93c5fd' } },
|
|
117
|
+
});
|
|
92
118
|
```
|
|
93
119
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
`@react-native-async-storage/async-storage`) on every consumer, even ones
|
|
99
|
-
that don't want it. If you want persistence, read your own storage at
|
|
100
|
-
startup and call `setGlobalThemeMode()` with the result before your first
|
|
101
|
-
render — the same "seed once" shape `<ThemeProvider defaultMode>` itself
|
|
102
|
-
uses internally.
|
|
120
|
+
A shade-family lookup (`colors.blue[n]`) auto-mirrors to shade `13 - n` in
|
|
121
|
+
dark mode — this palette's own convention is 1 = lightest, 12 = darkest, so
|
|
122
|
+
that's the same visual weight relative to its own background, no manual
|
|
123
|
+
`colors.blue[isDark ? 7 : 6]` needed.
|
|
103
124
|
|
|
104
125
|
## License
|
|
105
126
|
|
|
@@ -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,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getGlobalDarkMode
|
|
3
|
+
} from "./chunk-RBJXE32L.mjs";
|
|
4
|
+
|
|
5
|
+
// src/jsxRuntimeCore.ts
|
|
6
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { Fragment } from "react";
|
|
8
|
+
import { Pressable } from "react-native";
|
|
9
|
+
function makeElement(isStaticChildren, type, props, key) {
|
|
10
|
+
return (isStaticChildren ? _jsxs : _jsx)(type, props, key);
|
|
11
|
+
}
|
|
12
|
+
function resolvedStyleFor(resolveStyle, classStrRaw, userStyle, pressed) {
|
|
13
|
+
const resolved = resolveStyle(classStrRaw, pressed);
|
|
14
|
+
if (userStyle === void 0) {
|
|
15
|
+
return resolved;
|
|
16
|
+
}
|
|
17
|
+
if (typeof userStyle === "function") {
|
|
18
|
+
return [resolved, userStyle({ pressed })];
|
|
19
|
+
}
|
|
20
|
+
return [resolved, userStyle];
|
|
21
|
+
}
|
|
22
|
+
var DARK_MODIFIER_RE = /(^|\s)dark:/;
|
|
23
|
+
function darkModeKeySuffix(classStrRaw) {
|
|
24
|
+
return DARK_MODIFIER_RE.test(classStrRaw) ? `:kb-dark-${getGlobalDarkMode()}` : "";
|
|
25
|
+
}
|
|
26
|
+
function processElement(resolveStyle, type, rawProps, key, isStaticChildren) {
|
|
27
|
+
if (type === null || typeof type === "symbol" || !rawProps) {
|
|
28
|
+
return makeElement(isStaticChildren, type, rawProps ?? {}, key);
|
|
29
|
+
}
|
|
30
|
+
const { className: classStrRaw, style: userStyle, ...rest } = rawProps;
|
|
31
|
+
if (typeof classStrRaw !== "string") {
|
|
32
|
+
return makeElement(isStaticChildren, type, rawProps, key);
|
|
33
|
+
}
|
|
34
|
+
const finalStyle = type === Pressable ? (state) => resolvedStyleFor(resolveStyle, classStrRaw, userStyle, state.pressed) : resolvedStyleFor(resolveStyle, classStrRaw, userStyle, false);
|
|
35
|
+
const suffix = darkModeKeySuffix(classStrRaw);
|
|
36
|
+
const finalKey = suffix ? `${key ?? ""}${suffix}` : key;
|
|
37
|
+
return makeElement(isStaticChildren, type, { ...rest, style: finalStyle }, finalKey);
|
|
38
|
+
}
|
|
39
|
+
function createJsxFunctions(resolveStyle) {
|
|
40
|
+
function jsx(type, props, key) {
|
|
41
|
+
return processElement(resolveStyle, type, props, key, false);
|
|
42
|
+
}
|
|
43
|
+
function jsxs(type, props, key) {
|
|
44
|
+
return processElement(resolveStyle, type, props, key, true);
|
|
45
|
+
}
|
|
46
|
+
return { jsx, jsxs };
|
|
47
|
+
}
|
|
48
|
+
function createJsxDEV(jsx, jsxs) {
|
|
49
|
+
return function jsxDEV(type, props, key, isStaticChildren, source, self) {
|
|
50
|
+
const element = (isStaticChildren ? jsxs : jsx)(type, props, key);
|
|
51
|
+
if (source && element && typeof element === "object" && Object.isExtensible(element)) {
|
|
52
|
+
element._source = source;
|
|
53
|
+
element._self = self;
|
|
54
|
+
}
|
|
55
|
+
return element;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
Fragment,
|
|
61
|
+
createJsxFunctions,
|
|
62
|
+
createJsxDEV
|
|
63
|
+
};
|