@@ -45,12 +45,22 @@ import com.facebook.react.uimanager.style.LogicalEdge
4545import com.facebook.react.uimanager.style.OutlineStyle
4646
4747/* *
48- * BackgroundStyleApplicator is responsible for applying backgrounds, borders, and related effects,
49- * to an Android view
48+ * Utility object responsible for applying backgrounds, borders, and related visual effects to
49+ * Android views.
50+ *
51+ * This object provides methods to manage background colors, images, borders, outlines, and box
52+ * shadows for React Native views. It handles the complex layering and composition of these visual
53+ * properties by managing [CompositeBackgroundDrawable] instances.
5054 */
5155@OptIn(UnstableReactNativeAPI ::class )
5256public object BackgroundStyleApplicator {
5357
58+ /* *
59+ * Sets the background color of the view.
60+ *
61+ * @param view The view to apply the background color to
62+ * @param color The color to set, or null to remove the background color
63+ */
5464 @JvmStatic
5565 public fun setBackgroundColor (view : View , @ColorInt color : Int? ): Unit {
5666 // No color to set, and no color already set
@@ -64,6 +74,12 @@ public object BackgroundStyleApplicator {
6474 ensureBackgroundDrawable(view).backgroundColor = color ? : Color .TRANSPARENT
6575 }
6676
77+ /* *
78+ * Sets the background image layers for the view.
79+ *
80+ * @param view The view to apply the background images to
81+ * @param backgroundImageLayers The list of background image layers to apply, or null to remove
82+ */
6783 @JvmStatic
6884 public fun setBackgroundImage (
6985 view : View ,
@@ -90,12 +106,25 @@ public object BackgroundStyleApplicator {
90106 ensureBackgroundImageDrawable(view).backgroundRepeat = backgroundRepeats
91107 }
92108
109+ /* *
110+ * Gets the background color of the view.
111+ *
112+ * @param view The view to get the background color from
113+ * @return The background color, or null if no background color is set
114+ */
93115 @JvmStatic
94116 @ColorInt
95117 public fun getBackgroundColor (view : View ): Int? {
96118 return getBackground(view)?.backgroundColor
97119 }
98120
121+ /* *
122+ * Sets the border width for a specific edge of the view.
123+ *
124+ * @param view The view to apply the border width to
125+ * @param edge The logical edge (start, end, top, bottom, etc.) to set the width for
126+ * @param width The border width in DIPs, or null to remove
127+ */
99128 @JvmStatic
100129 public fun setBorderWidth (view : View , edge : LogicalEdge , width : Float? ): Unit {
101130 val composite = ensureCompositeBackgroundDrawable(view)
@@ -121,6 +150,13 @@ public object BackgroundStyleApplicator {
121150 }
122151 }
123152
153+ /* *
154+ * Gets the border width for a specific edge of the view.
155+ *
156+ * @param view The view to get the border width from
157+ * @param edge The logical edge to get the width for
158+ * @return The border width in DIPs, or null if not set
159+ */
124160 @JvmStatic
125161 public fun getBorderWidth (view : View , edge : LogicalEdge ): Float? {
126162 val width = getBorder(view)?.borderWidth?.getRaw(edge.toSpacingType())
@@ -131,17 +167,38 @@ public object BackgroundStyleApplicator {
131167 }
132168 }
133169
170+ /* *
171+ * Sets the border color for a specific edge of the view.
172+ *
173+ * @param view The view to apply the border color to
174+ * @param edge The logical edge to set the color for
175+ * @param color The border color, or null to remove
176+ */
134177 @JvmStatic
135178 public fun setBorderColor (view : View , edge : LogicalEdge , @ColorInt color : Int? ): Unit {
136179 ensureBorderDrawable(view).setBorderColor(edge, color)
137180 }
138181
182+ /* *
183+ * Gets the border color for a specific edge of the view.
184+ *
185+ * @param view The view to get the border color from
186+ * @param edge The logical edge to get the color for
187+ * @return The border color, or null if not set
188+ */
139189 @JvmStatic
140190 @ColorInt
141191 public fun getBorderColor (view : View , edge : LogicalEdge ): Int? {
142192 return getBorder(view)?.getBorderColor(edge)
143193 }
144194
195+ /* *
196+ * Sets the border radius for a specific corner of the view.
197+ *
198+ * @param view The view to apply the border radius to
199+ * @param corner The corner property to set the radius for
200+ * @param radius The border radius value (length or percentage), or null to remove
201+ */
145202 @JvmStatic
146203 public fun setBorderRadius (
147204 view : View ,
@@ -183,22 +240,47 @@ public object BackgroundStyleApplicator {
183240 compositeBackgroundDrawable.invalidateSelf()
184241 }
185242
243+ /* *
244+ * Gets the border radius for a specific corner of the view.
245+ *
246+ * @param view The view to get the border radius from
247+ * @param corner The corner property to get the radius for
248+ * @return The border radius value, or null if not set
249+ */
186250 @JvmStatic
187251 public fun getBorderRadius (view : View , corner : BorderRadiusProp ): LengthPercentage ? {
188252
189253 return getCompositeBackgroundDrawable(view)?.borderRadius?.get(corner)
190254 }
191255
256+ /* *
257+ * Sets the border style for the view.
258+ *
259+ * @param view The view to apply the border style to
260+ * @param borderStyle The border style (solid, dashed, dotted), or null to remove
261+ */
192262 @JvmStatic
193263 public fun setBorderStyle (view : View , borderStyle : BorderStyle ? ) {
194264 ensureBorderDrawable(view).borderStyle = borderStyle
195265 }
196266
267+ /* *
268+ * Gets the border style of the view.
269+ *
270+ * @param view The view to get the border style from
271+ * @return The border style, or null if not set
272+ */
197273 @JvmStatic
198274 public fun getBorderStyle (view : View ): BorderStyle ? {
199275 return getBorder(view)?.borderStyle
200276 }
201277
278+ /* *
279+ * Sets the outline color for the view (Fabric only).
280+ *
281+ * @param view The view to apply the outline color to
282+ * @param outlineColor The outline color, or null to remove
283+ */
202284 @JvmStatic
203285 public fun setOutlineColor (view : View , @ColorInt outlineColor : Int? ) {
204286 if (ViewUtil .getUIManagerType(view) != UIManagerType .FABRIC ) {
@@ -211,8 +293,20 @@ public object BackgroundStyleApplicator {
211293 }
212294 }
213295
296+ /* *
297+ * Gets the outline color of the view.
298+ *
299+ * @param view The view to get the outline color from
300+ * @return The outline color, or null if not set
301+ */
214302 @JvmStatic public fun getOutlineColor (view : View ): Int? = getOutlineDrawable(view)?.outlineColor
215303
304+ /* *
305+ * Sets the outline offset for the view (Fabric only).
306+ *
307+ * @param view The view to apply the outline offset to
308+ * @param outlineOffset The outline offset in DIPs
309+ */
216310 @JvmStatic
217311 public fun setOutlineOffset (view : View , outlineOffset : Float ): Unit {
218312 if (ViewUtil .getUIManagerType(view) != UIManagerType .FABRIC ) {
@@ -223,8 +317,20 @@ public object BackgroundStyleApplicator {
223317 outline.outlineOffset = outlineOffset.dpToPx()
224318 }
225319
320+ /* *
321+ * Gets the outline offset of the view.
322+ *
323+ * @param view The view to get the outline offset from
324+ * @return The outline offset in pixels, or null if not set
325+ */
226326 public fun getOutlineOffset (view : View ): Float? = getOutlineDrawable(view)?.outlineOffset
227327
328+ /* *
329+ * Sets the outline style for the view (Fabric only).
330+ *
331+ * @param view The view to apply the outline style to
332+ * @param outlineStyle The outline style (solid, dashed, dotted), or null to remove
333+ */
228334 @JvmStatic
229335 public fun setOutlineStyle (view : View , outlineStyle : OutlineStyle ? ): Unit {
230336 if (ViewUtil .getUIManagerType(view) != UIManagerType .FABRIC ) {
@@ -237,8 +343,20 @@ public object BackgroundStyleApplicator {
237343 }
238344 }
239345
346+ /* *
347+ * Gets the outline style of the view.
348+ *
349+ * @param view The view to get the outline style from
350+ * @return The outline style, or null if not set
351+ */
240352 public fun getOutlineStyle (view : View ): OutlineStyle ? = getOutlineDrawable(view)?.outlineStyle
241353
354+ /* *
355+ * Sets the outline width for the view (Fabric only).
356+ *
357+ * @param view The view to apply the outline width to
358+ * @param width The outline width in DIPs
359+ */
242360 @JvmStatic
243361 public fun setOutlineWidth (view : View , width : Float ) {
244362 if (ViewUtil .getUIManagerType(view) != UIManagerType .FABRIC ) {
@@ -249,8 +367,20 @@ public object BackgroundStyleApplicator {
249367 outline.outlineWidth = width.dpToPx()
250368 }
251369
370+ /* *
371+ * Gets the outline width of the view.
372+ *
373+ * @param view The view to get the outline width from
374+ * @return The outline width in pixels, or null if not set
375+ */
252376 public fun getOutlineWidth (view : View ): Float? = getOutlineDrawable(view)?.outlineOffset
253377
378+ /* *
379+ * Sets box shadows for the view (Fabric only).
380+ *
381+ * @param view The view to apply box shadows to
382+ * @param shadows The list of box shadow styles to apply
383+ */
254384 @JvmStatic
255385 public fun setBoxShadow (view : View , shadows : List <BoxShadow >) {
256386 if (ViewUtil .getUIManagerType(view) != UIManagerType .FABRIC ) {
@@ -309,6 +439,12 @@ public object BackgroundStyleApplicator {
309439 .withNewShadows(outerShadows = outerShadows, innerShadows = innerShadows)
310440 }
311441
442+ /* *
443+ * Sets box shadows for the view from a ReadableArray (Fabric only).
444+ *
445+ * @param view The view to apply box shadows to
446+ * @param shadows The array of box shadow definitions, or null to remove all shadows
447+ */
312448 @JvmStatic
313449 public fun setBoxShadow (view : View , shadows : ReadableArray ? ) {
314450 if (shadows == null ) {
@@ -323,11 +459,26 @@ public object BackgroundStyleApplicator {
323459 BackgroundStyleApplicator .setBoxShadow(view, shadowStyles)
324460 }
325461
462+ /* *
463+ * Sets a feedback underlay drawable for the view.
464+ *
465+ * @param view The view to apply the feedback underlay to
466+ * @param drawable The drawable to use as feedback underlay, or null to remove
467+ */
326468 @JvmStatic
327469 public fun setFeedbackUnderlay (view : View , drawable : Drawable ? ) {
328470 ensureCompositeBackgroundDrawable(view).withNewFeedbackUnderlay(drawable)
329471 }
330472
473+ /* *
474+ * Clips the canvas to the padding box of the view.
475+ *
476+ * The padding box is the area within the borders of the view, accounting for border radius if
477+ * present.
478+ *
479+ * @param view The view whose padding box defines the clipping region
480+ * @param canvas The canvas to clip
481+ */
331482 @JvmStatic
332483 public fun clipToPaddingBox (view : View , canvas : Canvas ) {
333484 val drawingRect = Rect ()
@@ -366,6 +517,13 @@ public object BackgroundStyleApplicator {
366517 }
367518 }
368519
520+ /* *
521+ * Resets the background styling of the view to its original state.
522+ *
523+ * This removes any CompositeBackgroundDrawable and restores the original background.
524+ *
525+ * @param view The view to reset
526+ */
369527 @JvmStatic
370528 public fun reset (view : View ) {
371529 if (view.background is CompositeBackgroundDrawable ) {
0 commit comments