mrousavy / mrousavy/react-native-screen-corner-radius

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

Open Beginner friendly
#15 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
121
Forks
11
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/index.tsx at the ScreenCornerRadius export and inspect the related IsScreenRounded value. Reproduce the import on an iOS simulator where NativeModules.ScreenCornerRadius is unavailable, then verify that both exports use their documented fallback values without a module-load crash.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, react-native, typescript
Domain
mobile
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.