Skip to content

fix: resolve native SafeAreaProvider via exports map#279

Merged
danstepanov merged 1 commit intomainfrom
fix/safe-area-env-exports
Feb 22, 2026
Merged

fix: resolve native SafeAreaProvider via exports map#279
danstepanov merged 1 commit intomainfrom
fix/safe-area-env-exports

Conversation

@danstepanov
Copy link
Member

@danstepanov danstepanov commented Feb 22, 2026

Summary

  • Bug: env(safe-area-inset-*) values resolve to 0 on native when applied via className (e.g. mb-safe, p-safe). The SafeAreaEnv component that injects CSS variables into the VariableContext is never loaded.
  • Root cause: The ./components/* wildcard in the exports map resolves to react-native-safe-area-context.tsx (the web passthrough) instead of react-native-safe-area-context.native.tsx (the native wrapper with SafeAreaEnv). Metro treats exports-resolved paths as final and does not apply platform-suffix resolution.
  • Fix: Add an explicit, higher-specificity exports entry for ./components/react-native-safe-area-context that maps the react-native condition directly to .native.tsx.

Additionally:

  • Add SafeAreaProvider.tsx as a convenience re-export, consistent with the component naming pattern used by View, Text, etc.
  • Enable the previously skipped env(safe-area-inset-*) test.

Closes #234

Test plan

  • env.test.ios.tsx passes (previously skipped)
  • All native tests pass (npx jest src/__tests__/native/)
  • Verified via Metro bundle that SafeAreaEnv and react-native-css-safe-area-inset-* variables are present in the iOS bundle
  • Verified on iPhone 16 simulator (iOS 18.4) that mb-safe produces visible bottom margin

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.
@danstepanov danstepanov merged commit f28f7d8 into main Feb 22, 2026
6 checks passed
@danstepanov danstepanov deleted the fix/safe-area-env-exports branch February 22, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Safe-area insets utility classes not working

1 participant