mrousavy / mrousavy/react-native-screen-corner-radius
ScreenCornerRadius crashes at import on iOS simulator: "Cannot read property 'cornerRadius' of null"
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
- Add
react-native-screen-corner-radiusto an app. import { ScreenCornerRadius } from 'react-native-screen-corner-radius'.- Run on an iOS simulator.
- 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.3react-native: 0.83.2- Platform: iOS simulator
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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