Skip to content

Commit 5e6b108

Browse files
Abbondanzometa-codesync[bot]
authored andcommitted
Clear null length percentages without a warning (#58753)
Summary: Pull Request resolved: #58753 Treat a null dynamic length-percentage value as the expected property-reset case instead of reporting it as an unsupported type. Preserve the existing null result while avoiding a warning whenever a percentage border radius is cleared. Add focused coverage for point, percentage, negative, opt-in negative, and null parsing behavior. Changelog: [Android][Fixed] - Avoid warning when clearing percentage border radii Differential Revision: D122278946 fbshipit-source-id: ce29b398cd3f35a798bb89bc44cf44f5e0ad7b7f
1 parent 8f58866 commit 5e6b108

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public data class LengthPercentage(
5151
null
5252
}
5353
}
54+
ReadableType.Null -> null
5455
else -> {
5556
FLog.w(ReactConstants.TAG, "Unsupported type for radius property: ${dynamic.type}")
5657
null
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.uimanager
9+
10+
import com.facebook.common.logging.FLog
11+
import com.facebook.react.bridge.DynamicFromObject
12+
import org.assertj.core.api.Assertions.assertThat
13+
import org.junit.Test
14+
import org.mockito.Mockito.mockStatic
15+
16+
class LengthPercentageTest {
17+
18+
@Test
19+
fun parsesPointAndPercentageValues() {
20+
assertThat(LengthPercentage.setFromDynamic(DynamicFromObject(12.0)))
21+
.isEqualTo(LengthPercentage(12f, LengthPercentageType.POINT))
22+
assertThat(LengthPercentage.setFromDynamic(DynamicFromObject("25%")))
23+
.isEqualTo(LengthPercentage(25f, LengthPercentageType.PERCENT))
24+
}
25+
26+
@Test
27+
fun rejectsNegativeValuesByDefault() {
28+
assertThat(LengthPercentage.setFromDynamic(DynamicFromObject(-1.0))).isNull()
29+
assertThat(LengthPercentage.setFromDynamic(DynamicFromObject("-1%"))).isNull()
30+
}
31+
32+
@Test
33+
fun acceptsNegativeValuesWhenAllowed() {
34+
assertThat(LengthPercentage.setFromDynamic(DynamicFromObject(-1.0), allowNegative = true))
35+
.isEqualTo(LengthPercentage(-1f, LengthPercentageType.POINT))
36+
assertThat(LengthPercentage.setFromDynamic(DynamicFromObject("-1%"), allowNegative = true))
37+
.isEqualTo(LengthPercentage(-1f, LengthPercentageType.PERCENT))
38+
}
39+
40+
@Test
41+
fun clearsNullWithoutWarning() {
42+
mockStatic(FLog::class.java).use { flog ->
43+
assertThat(LengthPercentage.setFromDynamic(DynamicFromObject(null))).isNull()
44+
flog.verifyNoInteractions()
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)