From 12a7f43885abf132d5ca2d8e2b1235354b85aaee Mon Sep 17 00:00:00 2001 From: Peter Abbondanzo Date: Sun, 25 Oct 2026 14:09:45 -0700 Subject: [PATCH] Fix getOutlineWidth returning the outline offset Summary: `BackgroundStyleApplicator.getOutlineWidth` returned `outlineOffset` instead of `outlineWidth`, so readers got the offset value (or null when only a width was set). Return the width. Changelog: [Android][Fixed] - Fix `getOutlineWidth` returning the outline offset Differential Revision: D127479548 --- .../uimanager/BackgroundStyleApplicator.kt | 2 +- .../BackgroundStyleApplicatorTest.kt | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BackgroundStyleApplicatorTest.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BackgroundStyleApplicator.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BackgroundStyleApplicator.kt index c7d94a770c39..c3af3626ae6e 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BackgroundStyleApplicator.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BackgroundStyleApplicator.kt @@ -358,7 +358,7 @@ public object BackgroundStyleApplicator { * @param view The view to get the outline width from * @return The outline width in pixels, or null if not set */ - public fun getOutlineWidth(view: View): Float? = getOutlineDrawable(view)?.outlineOffset + public fun getOutlineWidth(view: View): Float? = getOutlineDrawable(view)?.outlineWidth /** * Sets box shadows for the view. diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BackgroundStyleApplicatorTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BackgroundStyleApplicatorTest.kt new file mode 100644 index 000000000000..b836e4cfcf74 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BackgroundStyleApplicatorTest.kt @@ -0,0 +1,45 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.uimanager + +import android.util.DisplayMetrics +import android.view.View +import org.assertj.core.api.Assertions.assertThat +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment + +/** Tests for [BackgroundStyleApplicator] outline getters. */ +@RunWith(RobolectricTestRunner::class) +class BackgroundStyleApplicatorTest { + + private lateinit var view: View + + @Before + fun setUp() { + DisplayMetricsHolder.setScreenDisplayMetrics(DisplayMetrics().apply { density = 2f }) + view = View(RuntimeEnvironment.getApplication()) + } + + @After + fun tearDown() { + DisplayMetricsHolder.setScreenDisplayMetrics(null) + } + + @Test + fun getOutlineWidthReturnsWidthNotOffset() { + BackgroundStyleApplicator.setOutlineWidth(view, 3f) + BackgroundStyleApplicator.setOutlineOffset(view, 8f) + + assertThat(BackgroundStyleApplicator.getOutlineWidth(view)).isEqualTo(6f) + assertThat(BackgroundStyleApplicator.getOutlineOffset(view)).isEqualTo(16f) + } +}