Skip to content

Commit 920bf2d

Browse files
authored
fix: consistent API exports (#174)
1 parent 16edec1 commit 920bf2d

8 files changed

Lines changed: 43 additions & 17 deletions

File tree

example/src/App.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
import { Text, View } from "react-native";
1+
import { View as RNView } from "react-native";
2+
3+
import { styled, VariableContextProvider } from "react-native-css";
4+
import { View } from "react-native-css/components";
25

36
import "../global.css";
47

8+
const CustomView = styled(RNView, { className: "style" });
9+
510
export default function App() {
611
return (
7-
<>
8-
<View className="justify-center items-center h-full">
9-
<Text className="text-red-500">Test Component</Text>
10-
</View>
11-
</>
12+
<View className="flex-1 items-center justify-center">
13+
<VariableContextProvider
14+
value={{
15+
"--custom": "pink",
16+
}}
17+
>
18+
<View className="bg-[var(--custom,purple)] w-10 h-10" />
19+
20+
<CustomView className="bg-[var(--custom,purple)] w-10 h-10" />
21+
</VariableContextProvider>
22+
</View>
1223
);
1324
}

src/__tests__/native/units.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { View } from "react-native";
33
import { act, renderHook } from "@testing-library/react-native";
44
import { registerCSS } from "react-native-css/jest";
55
import { useNativeCss } from "react-native-css/runtime/native";
6+
import { VariableContext } from "react-native-css/style-collection";
67

78
import {
89
dimensions,
910
VAR_SYMBOL,
10-
VariableContext,
1111
vh,
1212
vw,
1313
} from "../../runtime/native/reactivity";

src/__tests__/native/variables.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { memo, useEffect } from "react";
22
import type { ViewProps } from "react-native";
33

44
import { render, screen } from "@testing-library/react-native";
5+
import { styled, VariableContextProvider } from "react-native-css";
56
import { View } from "react-native-css/components/View";
67
import { registerCSS, testID } from "react-native-css/jest";
7-
import { styled, VariableContextProvider } from "react-native-css/runtime";
88

99
test("inline variable", () => {
1010
registerCSS(`.my-class { width: var(--my-var); --my-var: 10px; }`);

src/components/react-native-safe-area-context.native.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { useContext, useMemo, type PropsWithChildren } from "react";
22

3+
import { VariableContext } from "react-native-css/style-collection";
34
import {
45
SafeAreaProvider as OriginalSafeAreaProvider,
56
useSafeAreaInsets,
67
type SafeAreaProviderProps,
78
} from "react-native-safe-area-context";
89

9-
import { VariableContext } from "../runtime/native/reactivity";
10-
1110
export * from "react-native-safe-area-context";
1211

1312
export function SafeAreaProvider({

src/runtime/native/api.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import { useContext, useMemo, useState, type PropsWithChildren } from "react";
33
import { Appearance } from "react-native";
44

5+
import { VariableContext } from "react-native-css/style-collection";
6+
57
import type { StyleDescriptor } from "../../compiler";
68
import type {
79
ColorScheme,
@@ -15,14 +17,16 @@ import { usePassthrough } from "./react/usePassthrough";
1517
import {
1618
colorScheme as colorSchemeObs,
1719
VAR_SYMBOL,
18-
VariableContext,
1920
type Effect,
2021
type Getter,
2122
type VariableContextValue,
2223
} from "./reactivity";
2324
import { resolveValue } from "./styles/resolve";
2425

25-
export { StyleCollection } from "react-native-css/style-collection";
26+
export {
27+
StyleCollection,
28+
VariableContext,
29+
} from "react-native-css/style-collection";
2630

2731
export { useNativeCss };
2832

src/runtime/native/react/useNativeCss.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import {
99
} from "react";
1010
import { Pressable, View } from "react-native";
1111

12+
import { VariableContext } from "react-native-css/style-collection";
13+
1214
import type { StyledConfiguration } from "../../runtime.types";
1315
import { testGuards, type RenderGuard } from "../conditions/guards";
1416
import {
1517
cleanupEffect,
1618
ContainerContext,
17-
VariableContext,
1819
type ContainerContextValue,
1920
type Effect,
2021
type Getter,

src/runtime/native/reactivity.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,10 @@ export function weakFamily<Key extends WeakKey, Args = undefined, Result = Key>(
181181

182182
/********************************* Variables **********************************/
183183

184-
export const VAR_SYMBOL = Symbol("react-native-css.var");
184+
export const VAR_SYMBOL = Symbol.for("react-native-css.var");
185185
export type VariableContextValue = Record<string, StyleDescriptor> & {
186186
[VAR_SYMBOL]: true;
187187
};
188-
export const VariableContext = createContext<VariableContextValue>({
189-
[VAR_SYMBOL]: true,
190-
});
191188

192189
/** Pseudo Classes ************************************************************/
193190

src/style-collection/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { createContext, type Context } from "react";
2+
13
import type {
24
Animation,
35
ReactNativeCssStyleSheet,
@@ -9,7 +11,9 @@ import {
911
family,
1012
observable,
1113
observableBatch,
14+
VAR_SYMBOL,
1215
type Observable,
16+
type VariableContextValue,
1317
} from "../runtime/native/reactivity";
1418
import { rootVariables, universalVariables } from "./root";
1519

@@ -23,6 +27,9 @@ interface StyleCollectionType {
2327

2428
declare global {
2529
var __react_native_css_style_collection: StyleCollectionType | undefined;
30+
var __react_native_css_variable_context:
31+
| Context<VariableContextValue>
32+
| undefined;
2633
}
2734

2835
globalThis.__react_native_css_style_collection ??= {
@@ -140,3 +147,10 @@ function isDeepEqual(a: unknown, b: unknown): boolean {
140147

141148
return true;
142149
}
150+
151+
globalThis.__react_native_css_variable_context ??=
152+
createContext<VariableContextValue>({
153+
[VAR_SYMBOL]: true,
154+
});
155+
156+
export const VariableContext = globalThis.__react_native_css_variable_context;

0 commit comments

Comments
 (0)