fix: guard against null ScreenCornerRadius native module on simulator - #16
Open
blazejkustra wants to merge 1 commit into
Open
fix: guard against null ScreenCornerRadius native module on simulator#16blazejkustra wants to merge 1 commit into
blazejkustra wants to merge 1 commit into
Conversation
On the iOS simulator (and any setup where the native module isn't registered) NativeModules.ScreenCornerRadius is null. Reading .cornerRadius on it throws "Cannot read property 'cornerRadius' of null" at import time, before the ?? 0 fallback can apply. Optional-chain the module access so it falls back to 0 (and IsScreenRounded to false) as the docs promise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On the iOS simulator (and any setup where the native module isn't registered),
NativeModules.ScreenCornerRadiusisnull. The current code reads.cornerRadiusoff it directly:The
?? 0only guards.cornerRadiusbeingnull/undefined— it does not guardNativeModules.ScreenCornerRadiusitself beingnull. So on the simulator this throws:at import time, which surfaces as an error in Metro. The doc comment promises "May also be
0if the corner radius couldn't be detected", but it throws instead of falling back to0.Fix
Optional-chain the module access so it falls back to
0(andIsScreenRoundedtofalse) as documented:One-line change in
src/index.ts.Test plan
ScreenCornerRadiuson an iOS simulator → no longer throws;ScreenCornerRadiusis0andIsScreenRoundedisfalse.