Skip to content

ScreenCornerRadius crashes at import on iOS simulator: "Cannot read property 'cornerRadius' of null" #15

Description

@blazejkustra

Summary

Importing ScreenCornerRadius crashes the app on the iOS simulator with:

TypeError: Cannot read property 'cornerRadius' of null

The crash happens at module-load time, so it takes down the whole app rather than degrading gracefully.

Root cause

In src/index.tsx:

export const ScreenCornerRadius =
  NativeModules.ScreenCornerRadius.cornerRadius ?? 0;

The ?? 0 only guards .cornerRadius being null/undefined — it does not guard NativeModules.ScreenCornerRadius itself being null. When the native module isn't available (iOS simulator, or module not registered), NativeModules.ScreenCornerRadius is null, so accessing .cornerRadius throws before the ?? 0 fallback can apply.

Steps to reproduce

  1. Add react-native-screen-corner-radius to an app.
  2. import { ScreenCornerRadius } from 'react-native-screen-corner-radius'.
  3. Run on an iOS simulator.
  4. App crashes on load.

Expected behavior

When the native module is unavailable, ScreenCornerRadius should fall back to 0 (and IsScreenRounded to false) rather than throwing.

Suggested fix

Optional-chain the module access too:

export const ScreenCornerRadius =
  NativeModules.ScreenCornerRadius?.cornerRadius ?? 0;

Environment

  • react-native-screen-corner-radius: 0.2.3
  • react-native: 0.83.2
  • Platform: iOS simulator

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions