Skip to content

Commit f28f7d8

Browse files
authored
fix: resolve native SafeAreaProvider via exports map (#279)
The ./components/* wildcard in the exports map resolved env(safe-area-inset-*) to the web passthrough file (.tsx) instead of the native wrapper (.native.tsx) that injects CSS variables via SafeAreaEnv. Metro treats exports-resolved paths as final and does not apply platform-suffix resolution. Add an explicit exports entry for ./components/react-native-safe-area-context that maps the react-native condition to .native.tsx, and add a SafeAreaProvider convenience re-export consistent with the component naming pattern used by View, Text, etc. Enable the previously skipped env(safe-area-inset-*) test.
1 parent 499711c commit f28f7d8

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@
4747
"types": "./dist/typescript/commonjs/src/components/index.d.ts"
4848
}
4949
},
50+
"./components/react-native-safe-area-context": {
51+
"source": "./src/components/react-native-safe-area-context.native.tsx",
52+
"react-native": "./src/components/react-native-safe-area-context.native.tsx",
53+
"import": {
54+
"types": "./dist/typescript/module/src/components/react-native-safe-area-context.d.ts",
55+
"default": "./dist/module/components/react-native-safe-area-context.js"
56+
},
57+
"require": {
58+
"types": "./dist/typescript/commonjs/src/components/react-native-safe-area-context.d.ts",
59+
"default": "./dist/commonjs/components/react-native-safe-area-context.js"
60+
}
61+
},
5062
"./components/*": {
5163
"source": "./src/components/*.tsx",
5264
"react-native": "./src/components/*.tsx",

src/__tests__/native/env.test.ios.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
// import { SafeAreaProvider } from "react-native-css/components/SafeAreaProvider";
21
import { render, screen } from "@testing-library/react-native";
2+
import { SafeAreaProvider } from "react-native-css/components/SafeAreaProvider";
33
import { View } from "react-native-css/components/View";
44
import { registerCSS, testID } from "react-native-css/jest";
55

6-
test.skip("safe-area-inset-*", () => {
6+
test("safe-area-inset-*", () => {
77
registerCSS(`.my-class {
88
margin-top: env(safe-area-inset-top);
99
margin-bottom: env(safe-area-inset-bottom);
1010
margin-left: env(safe-area-inset-left);
1111
margin-right: env(safe-area-inset-right);
1212
}`);
1313

14-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
15-
const SafeAreaProvider = View as any;
16-
1714
render(
1815
<SafeAreaProvider
1916
initialMetrics={{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { SafeAreaProvider } from "react-native-css/components/react-native-safe-area-context";

0 commit comments

Comments
 (0)