Skip to content

Commit 585b28c

Browse files
tshmieldevmeta-codesync[bot]
authored andcommitted
fix(android): skip null gradient color stop positions instead of warning (#58636)
Summary: `processBackgroundImage` emits `position: null` for every color stop that has no explicit position, which is the common case (`linear-gradient(red, blue)`). On Android, `LinearGradient` and `RadialGradient` pass that value straight to `LengthPercentage.setFromDynamic`, which logs ``` W ReactNative: Unsupported type for radius property: Null ``` once per such stop on every props update. A static view logs it on each render; an animated `backgroundImage` (e.g. Reanimated CSS animations) floods logcat at frame rate. The value itself is handled correctly (`null` position → evenly spaced), so this is purely log noise, but it drowns out real warnings. `BackgroundPosition` already guards against `ReadableType.Null` before calling `setFromDynamic`; this change does the same for gradient color stops in both gradient parsers. ## Changelog: [ANDROID] [FIXED] - Stop logging "Unsupported type for radius property: Null" for gradient color stops without an explicit position Pull Request resolved: #58636 Test Plan: Built React Native from source (`includeBuild('../node_modules/react-native')`) in an app that animates `backgroundImage` on Android (Pixel 9 Pro emulator, API 37) and counted the warning in `adb logcat` over an identical ~90 s run: - before: 1386 occurrences of `Unsupported type for radius property: Null` - after: 0 occurrences Gradients with and without stop positions render the same as before. `yarn format-check-kotlin` (ktfmt) passes on the changed files. Reviewed By: Abbondanzo Differential Revision: D121621185 Pulled By: javache fbshipit-source-id: 7baeea9e373dd03db9b911c6a57d9cb90e33a866
1 parent ab37398 commit 585b28c

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/LinearGradient.kt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ internal class LinearGradient(val direction: Direction, val colorStops: List<Col
7272
else -> colorStop.getInt("color")
7373
}
7474
val colorStopPosition =
75-
LengthPercentage.setFromDynamic(colorStop.getDynamic("position"))
75+
if (colorStop.hasKey("position") && !colorStop.isNull("position")) {
76+
LengthPercentage.setFromDynamic(colorStop.getDynamic("position"))
77+
} else {
78+
null
79+
}
7680
stops.add(ColorStop(color, colorStopPosition))
7781
}
7882
stops

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/RadialGradient.kt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ internal class RadialGradient(
128128
else -> colorStop.getInt("color")
129129
}
130130
val colorStopPosition =
131-
LengthPercentage.setFromDynamic(colorStop.getDynamic("position"))
131+
if (colorStop.hasKey("position") && !colorStop.isNull("position")) {
132+
LengthPercentage.setFromDynamic(colorStop.getDynamic("position"))
133+
} else {
134+
null
135+
}
132136
stops.add(ColorStop(color, colorStopPosition))
133137
}
134138
stops

0 commit comments

Comments
 (0)