From 5c789c3d3a91f4e4ee06e97cdeec7dcb64a5cf44 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Tue, 17 Dec 2024 06:53:47 -0800 Subject: [PATCH] Fabric: Fixes TextInput crash when textShadowOffset is set and textShadowRadius is nan (#48296) Summary: Fixes https://github.com/facebook/react-native/issues/48288 ## Changelog: [IOS] [FIXED] - Fabric: Fixes TextInput crash when textShadowOffset is set and textShadowRadius is nan Pull Request resolved: https://github.com/facebook/react-native/pull/48296 Test Plan: Repro demo in https://github.com/facebook/react-native/issues/48288 Reviewed By: cipolleschi Differential Revision: D67334179 Pulled By: NickGerleman fbshipit-source-id: a9456a152d31bef1666669cbded28d99ec8a2028 --- .../renderer/textlayoutmanager/RCTAttributedTextUtils.mm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm index 1e551e4b127..2a5185d344c 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm @@ -303,8 +303,12 @@ NSMutableDictionary *RCTNSTextAttributesFromTextAttri auto textShadowOffset = textAttributes.textShadowOffset.value(); NSShadow *shadow = [NSShadow new]; shadow.shadowOffset = CGSize{textShadowOffset.width, textShadowOffset.height}; - shadow.shadowBlurRadius = textAttributes.textShadowRadius; - shadow.shadowColor = RCTUIColorFromSharedColor(textAttributes.textShadowColor); + if (!isnan(textAttributes.textShadowRadius)) { + shadow.shadowBlurRadius = textAttributes.textShadowRadius; + } + if (textAttributes.textShadowColor) { + shadow.shadowColor = RCTUIColorFromSharedColor(textAttributes.textShadowColor); + } attributes[NSShadowAttributeName] = shadow; }