Skip to content

fix/ Add lazy getters for initialWindowMetrics#907

Open
s-brankovic wants to merge 2 commits intodevelopfrom
fix/home-indicator-padding-load-race-condition
Open

fix/ Add lazy getters for initialWindowMetrics#907
s-brankovic wants to merge 2 commits intodevelopfrom
fix/home-indicator-padding-load-race-condition

Conversation

@s-brankovic
Copy link
Contributor

Fix: SafeArea inset constants crash when initialWindowMetrics is null

In react-native-safe-area-context v5, initialWindowMetrics can be null when the JS bundle evaluates before the native module initializes — a race condition common in large apps with many native modules. This caused HOME_INDICATOR_PADDING, NOTCH_AREA_HEIGHT, and NAVIGATION_BAR_HEIGHT to evaluate to undefined or NaN, leading to layout crashes.

Changes:

1. Added hardcoded fallbacks to the existing static constants via nullish coalescing:

  • Top inset defaults to 59 (Dynamic Island devices, iPhone 14 Pro+)
  • Bottom inset defaults to 34 (home indicator, consistent across all notched iPhones since iPhone X)
  • These prevent NaN/undefined for consumers that import the constants at module load time (e.g., theme variable files).

2. Added lazy getter functions that resolve initialWindowMetrics on first call (render time) instead of import time:

  • getNavigationBarHeight()
  • getHomeIndicatorPadding()
  • getNotchAreaHeight()
  • Values are cached after the first read. By render time, the native module is initialized, so these return accurate device-specific values rather than fallbacks.
  • Exported the getter functions through the existing export chain.

Backward compatible — existing static constant exports are preserved. Consumers can migrate to the getter functions if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant