Skip to content

Commit 58688bf

Browse files
feat(style): remove experimental_ prefix from backgroundImage (#57165)
Summary: Promote `backgroundImage` from `experimental_backgroundImage` to a stable style prop. It has been available in experimental mode for some time and is already used in popular open-source projects such as NativeWind, Unstyles, Tamagui, React Strict DOM, and others, with no reported issues so far. `backgroundImage` currently supports `linear-gradient` and `radial-gradient`. `url()` support already has a PR up ([PRs](#54995)), it should not be a blocker imo though as gradient is also a big unlock. ## Changelog: [GENERAL][CHANGED] - Remove `experimental_` prefix from `backgroundImage` <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Pull Request resolved: #57165 Test Plan: Tested background image screen on RNTester. Reviewed By: javache Differential Revision: D108301578 Pulled By: jorge-cab fbshipit-source-id: 558d1d8943b3cd56557584eaf5e4bda112154298
1 parent aa429cf commit 58688bf

14 files changed

Lines changed: 191 additions & 143 deletions

File tree

packages/react-native/Libraries/Components/View/ReactNativeStyleAttributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ const ReactNativeStyleAttributes: {[string]: AnyAttributeType, ...} = {
194194
/**
195195
* BackgroundImage
196196
*/
197+
backgroundImage: backgroundImageAttribute,
197198
experimental_backgroundImage: backgroundImageAttribute,
198199

199200
/**

packages/react-native/Libraries/Components/View/__tests__/View-itest.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,12 @@ describe('<View>', () => {
335335
<>
336336
<View
337337
style={{
338-
experimental_backgroundImage:
339-
'radial-gradient(#e66465, #9198e5)',
338+
backgroundImage: 'radial-gradient(#e66465, #9198e5)',
340339
}}
341340
/>
342341
<View
343342
style={{
344-
experimental_backgroundImage: [
343+
backgroundImage: [
345344
{
346345
type: 'radial-gradient',
347346
shape: 'ellipse',

packages/react-native/Libraries/NativeComponent/BaseViewConfig.android.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ const validAttributesForNonEventProps = {
211211
backgroundColor: colorAttribute,
212212
transform: true,
213213
transformOrigin: true,
214+
backgroundImage: backgroundImageAttribute,
214215
experimental_backgroundImage: backgroundImageAttribute,
215216
experimental_backgroundSize: backgroundSizeAttribute,
216217
experimental_backgroundPosition: backgroundPositionAttribute,

packages/react-native/Libraries/StyleSheet/StyleSheetTypes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ export interface ViewStyle extends FlexStyle, ShadowStyleIOS, TransformsStyle {
517517
filter?: ReadonlyArray<FilterFunction> | string | undefined;
518518

519519
mixBlendMode?: BlendMode | undefined;
520+
backgroundImage?: ReadonlyArray<BackgroundImageValue> | string | undefined;
520521
experimental_backgroundImage?:
521522
| ReadonlyArray<BackgroundImageValue>
522523
| string

packages/react-native/Libraries/StyleSheet/StyleSheetTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ export type ____ViewStyle_InternalBase = Readonly<{
887887
boxShadow?: ReadonlyArray<BoxShadowValue> | string,
888888
filter?: ReadonlyArray<FilterFunction> | string,
889889
mixBlendMode?: ____BlendMode_Internal,
890+
backgroundImage?: ReadonlyArray<BackgroundImageValue> | string,
890891
experimental_backgroundImage?: ReadonlyArray<BackgroundImageValue> | string,
891892
experimental_backgroundSize?: ReadonlyArray<BackgroundSizeValue> | string,
892893
experimental_backgroundPosition?:

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4509,6 +4509,7 @@ public final class com/facebook/react/uimanager/ViewProps {
45094509
public static final field ELLIPSIZE_MODE Ljava/lang/String;
45104510
public static final field ENABLED Ljava/lang/String;
45114511
public static final field END Ljava/lang/String;
4512+
public static final field EXPERIMENTAL_BACKGROUND_IMAGE Ljava/lang/String;
45124513
public static final field FILTER Ljava/lang/String;
45134514
public static final field FLEX Ljava/lang/String;
45144515
public static final field FLEX_BASIS Ljava/lang/String;
@@ -6486,6 +6487,7 @@ public class com/facebook/react/views/view/ReactViewManager : com/facebook/react
64866487
public fun setBorderWidth (Lcom/facebook/react/views/view/ReactViewGroup;IF)V
64876488
public fun setCollapsable (Lcom/facebook/react/views/view/ReactViewGroup;Z)V
64886489
public fun setCollapsableChildren (Lcom/facebook/react/views/view/ReactViewGroup;Z)V
6490+
public fun setExperimentalBackgroundImage (Lcom/facebook/react/views/view/ReactViewGroup;Lcom/facebook/react/bridge/ReadableArray;)V
64896491
public fun setFocusable (Lcom/facebook/react/views/view/ReactViewGroup;Z)V
64906492
public fun setHitSlop (Lcom/facebook/react/views/view/ReactViewGroup;Lcom/facebook/react/bridge/Dynamic;)V
64916493
public fun setNativeBackground (Lcom/facebook/react/views/view/ReactViewGroup;Lcom/facebook/react/bridge/ReadableMap;)V

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public object ViewProps {
7272
// Props that affect more than just layout
7373
public const val ENABLED: String = "enabled"
7474
public const val BACKGROUND_COLOR: String = "backgroundColor"
75-
public const val BACKGROUND_IMAGE: String = "experimental_backgroundImage"
75+
public const val BACKGROUND_IMAGE: String = "backgroundImage"
76+
// Backwards-compatible alias for the original experimental_ prefixed prop name.
77+
public const val EXPERIMENTAL_BACKGROUND_IMAGE: String = "experimental_backgroundImage"
7678
public const val BACKGROUND_SIZE: String = "experimental_backgroundSize"
7779
public const val BACKGROUND_POSITION: String = "experimental_backgroundPosition"
7880
public const val BACKGROUND_REPEAT: String = "experimental_backgroundRepeat"

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ public open class ReactViewManager : ReactClippingViewManager<ReactViewGroup>()
150150
}
151151
}
152152

153+
@ReactProp(name = ViewProps.EXPERIMENTAL_BACKGROUND_IMAGE, customType = "BackgroundImage")
154+
public open fun setExperimentalBackgroundImage(
155+
view: ReactViewGroup,
156+
backgroundImage: ReadableArray?,
157+
) {
158+
setBackgroundImage(view, backgroundImage)
159+
}
160+
153161
@ReactProp(name = ViewProps.BACKGROUND_SIZE, customType = "BackgroundSize")
154162
public open fun setBackgroundSize(view: ReactViewGroup, backgroundSize: ReadableArray?) {
155163
if (backgroundSize != null && backgroundSize.size() > 0) {

packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,13 @@ BaseViewProps::BaseViewProps(
223223
: convertRawProp(
224224
context,
225225
rawProps,
226-
"experimental_backgroundImage",
227-
sourceProps.backgroundImage,
226+
"backgroundImage",
227+
convertRawProp(
228+
context,
229+
rawProps,
230+
"experimental_backgroundImage",
231+
sourceProps.backgroundImage,
232+
{}),
228233
{})),
229234
backgroundSize(
230235
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
@@ -403,6 +408,7 @@ void BaseViewProps::setProp(
403408
switch (hash) {
404409
RAW_SET_PROP_SWITCH_CASE_BASIC(opacity);
405410
RAW_SET_PROP_SWITCH_CASE_BASIC(backgroundColor);
411+
RAW_SET_PROP_SWITCH_CASE_BASIC(backgroundImage);
406412
RAW_SET_PROP_SWITCH_CASE(backgroundImage, "experimental_backgroundImage");
407413
RAW_SET_PROP_SWITCH_CASE(backgroundSize, "experimental_backgroundSize");
408414
RAW_SET_PROP_SWITCH_CASE(

packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ folly::dynamic HostPlatformViewProps::getDiffProps(
625625
}
626626

627627
if (backgroundImage != oldProps->backgroundImage) {
628-
result["experimental_backgroundImage"] = toDynamic(backgroundImage);
628+
result["backgroundImage"] = toDynamic(backgroundImage);
629629
}
630630

631631
if (mixBlendMode != oldProps->mixBlendMode) {

0 commit comments

Comments
 (0)