Skip to content

Commit f23bbcd

Browse files
committed
chore: cleanup
1 parent 80f4df9 commit f23bbcd

File tree

10 files changed

+58
-119
lines changed

10 files changed

+58
-119
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -783,11 +783,5 @@ function parseLengthPercentage(value: number | string): ?(number | string) {
783783
return 0;
784784
}
785785

786-
// Try to parse as number (for backward compatibility)
787-
const num = parseFloat(trimmed);
788-
if (!Number.isNaN(num) && trimmed === String(num)) {
789-
return num;
790-
}
791-
792786
return null;
793787
}

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

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import com.facebook.react.uimanager.style.ClipPathUtils
5252
import com.facebook.react.uimanager.style.LogicalEdge
5353
import com.facebook.react.uimanager.style.OutlineStyle
5454
import com.facebook.react.views.view.GeometryBoxUtil
55+
import com.facebook.react.views.view.GeometryBoxUtil.getGeometryBoxBounds
5556

5657
/**
5758
* Utility object responsible for applying backgrounds, borders, and related visual effects to
@@ -480,46 +481,42 @@ public object BackgroundStyleApplicator {
480481
}
481482

482483
@JvmStatic
483-
public fun applyClipPath(view: View, canvas: Canvas, bounds: RectF) {
484+
public fun applyClipPathIfPresent(view: View, canvas: Canvas) {
484485
val clipPath = view.getTag(R.id.clip_path) as? ClipPath ?: return
485-
486+
val bounds = getGeometryBoxBounds(view, clipPath.geometryBox, getComputedBorderInsets(view))
486487
val drawingRect = Rect()
487488
view.getDrawingRect(drawingRect)
488489

489-
// Create path from the shape
490490
val path: Path? = if (clipPath.shape != null) {
491-
ClipPathUtils.createPathFromBasicShape(clipPath.shape, bounds)
492-
} else if (clipPath.geometryBox != null) {
493-
// For geometry box only (no shape), create a rounded rectangle using border radius
494-
val composite = getCompositeBackgroundDrawable(view)
495-
val borderRadius = composite?.borderRadius
496-
val computedBorderInsets = composite?.borderInsets?.resolve(composite.layoutDirection, view.context)
497-
498-
if (borderRadius != null) {
499-
// Adjust border radius based on geometry box type
491+
ClipPathUtils.createPathFromBasicShape(clipPath.shape, bounds)
492+
} else if (clipPath.geometryBox != null) {
493+
val composite = getCompositeBackgroundDrawable(view)
494+
val borderRadius = composite?.borderRadius
495+
val computedBorderInsets =
496+
composite?.borderInsets?.resolve(composite.layoutDirection, view.context)
497+
498+
if (borderRadius != null) {
500499
val adjustedBorderRadius = GeometryBoxUtil.adjustBorderRadiusForGeometryBox(
501-
clipPath.geometryBox,
502-
borderRadius.resolve(
503-
composite.layoutDirection,
504-
view.context,
505-
PixelUtil.toDIPFromPixel(drawingRect.width().toFloat()),
506-
PixelUtil.toDIPFromPixel(drawingRect.height().toFloat())
507-
),
508-
computedBorderInsets,
509-
view
500+
clipPath.geometryBox,
501+
borderRadius.resolve(
502+
composite.layoutDirection,
503+
view.context,
504+
PixelUtil.toDIPFromPixel(drawingRect.width().toFloat()),
505+
PixelUtil.toDIPFromPixel(drawingRect.height().toFloat())
506+
), computedBorderInsets, view
510507
)
511508

512-
if (adjustedBorderRadius != null) {
513-
ClipPathUtils.createRoundedRectPath(bounds, adjustedBorderRadius)
514-
} else {
515-
null
516-
}
517-
} else {
518-
null
519-
}
509+
if (adjustedBorderRadius != null) {
510+
ClipPathUtils.createRoundedRectPath(bounds, adjustedBorderRadius)
520511
} else {
521512
null
522513
}
514+
} else {
515+
null
516+
}
517+
} else {
518+
null
519+
}
523520

524521
if (path != null) {
525522
canvas.clipPath(path)
@@ -528,12 +525,6 @@ public object BackgroundStyleApplicator {
528525
}
529526
}
530527

531-
/**
532-
* Sets a feedback underlay drawable for the view.
533-
*
534-
* @param view The view to apply the feedback underlay to
535-
* @param drawable The drawable to use as feedback underlay, or null to remove
536-
*/
537528
@JvmStatic
538529
public fun getComputedBorderInsets(view: View): RectF? {
539530
val composite = getCompositeBackgroundDrawable(view)
@@ -543,6 +534,12 @@ public object BackgroundStyleApplicator {
543534
return composite.borderInsets?.resolve(composite.layoutDirection, view.context)
544535
}
545536

537+
/**
538+
* Sets a feedback underlay drawable for the view.
539+
*
540+
* @param view The view to apply the feedback underlay to
541+
* @param drawable The drawable to use as feedback underlay, or null to remove
542+
*/
546543
@JvmStatic
547544
public fun setFeedbackUnderlay(view: View, drawable: Drawable?) {
548545
view.background = ensureCompositeBackgroundDrawable(view).withNewFeedbackUnderlay(drawable)
@@ -616,9 +613,9 @@ public object BackgroundStyleApplicator {
616613
// Android versions, use the standard clipPath.
617614
if (
618615
ReactNativeFeatureFlags.enableAndroidAntialiasedBorderRadiusClipping() &&
619-
Build.VERSION.SDK_INT <= Build.VERSION_CODES.P &&
620-
view.width > 0 &&
621-
view.height > 0 &&
616+
Build.VERSION.SDK_INT <= Build.VERSION_CODES.P &&
617+
view.width > 0 &&
618+
view.height > 0 &&
622619
drawContent != null
623620
) {
624621
clipWithAntiAliasing(
@@ -802,15 +799,12 @@ public object BackgroundStyleApplicator {
802799
paddingBoxRect: RectF,
803800
computedBorderInsets: RectF?,
804801
): Path {
805-
val drawingRect = Rect()
806-
view.getDrawingRect(drawingRect)
807-
808802
val computedBorderRadius =
809803
composite.borderRadius?.resolve(
810804
composite.layoutDirection,
811805
view.context,
812-
PixelUtil.toDIPFromPixel(drawingRect.width().toFloat()),
813-
PixelUtil.toDIPFromPixel(drawingRect.height().toFloat()),
806+
PixelUtil.toDIPFromPixel(composite.bounds.width().toFloat()),
807+
PixelUtil.toDIPFromPixel(composite.bounds.height().toFloat()),
814808
)
815809

816810
val paddingBoxPath = Path()

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.kt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import android.graphics.Shader.TileMode
2222
import android.graphics.drawable.Animatable
2323
import android.graphics.drawable.Drawable
2424
import android.net.Uri
25+
import androidx.core.graphics.withSave
2526
import com.facebook.common.references.CloseableReference
2627
import com.facebook.common.util.UriUtil
2728
import com.facebook.drawee.backends.pipeline.Fresco
@@ -44,7 +45,6 @@ import com.facebook.imagepipeline.request.ImageRequest
4445
import com.facebook.imagepipeline.request.ImageRequest.RequestLevel
4546
import com.facebook.imagepipeline.request.ImageRequestBuilder
4647
import com.facebook.imagepipeline.request.Postprocessor
47-
import com.facebook.react.R
4848
import com.facebook.react.bridge.ReactContext
4949
import com.facebook.react.bridge.ReadableArray
5050
import com.facebook.react.bridge.ReadableMap
@@ -55,14 +55,12 @@ import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatur
5555
import com.facebook.react.modules.fresco.ImageCacheControl
5656
import com.facebook.react.modules.fresco.ReactNetworkImageRequest
5757
import com.facebook.react.uimanager.BackgroundStyleApplicator
58-
import com.facebook.react.uimanager.BackgroundStyleApplicator.getComputedBorderInsets
5958
import com.facebook.react.uimanager.LengthPercentage
6059
import com.facebook.react.uimanager.LengthPercentageType
6160
import com.facebook.react.uimanager.PixelUtil.dpToPx
6261
import com.facebook.react.uimanager.PixelUtil.pxToDp
6362
import com.facebook.react.uimanager.UIManagerHelper
6463
import com.facebook.react.uimanager.style.BorderRadiusProp
65-
import com.facebook.react.uimanager.style.ClipPath
6664
import com.facebook.react.uimanager.style.LogicalEdge
6765
import com.facebook.react.util.RNLog
6866
import com.facebook.react.views.image.ImageLoadEvent.Companion.createErrorEvent
@@ -77,7 +75,6 @@ import com.facebook.react.views.imagehelper.ImageSource
7775
import com.facebook.react.views.imagehelper.ImageSource.Companion.getTransparentBitmapImageSource
7876
import com.facebook.react.views.imagehelper.MultiSourceHelper.getBestSourceForSize
7977
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper
80-
import com.facebook.react.views.view.GeometryBoxUtil.getGeometryBoxBounds
8178
import kotlin.math.abs
8279

8380
/**
@@ -376,15 +373,9 @@ public class ReactImageView(
376373
public override fun hasOverlappingRendering(): Boolean = false
377374

378375
public override fun draw(canvas: Canvas) {
379-
val clipPath = getTag(R.id.clip_path) as? ClipPath
380-
if (clipPath != null) {
381-
val bounds = getGeometryBoxBounds(this, clipPath.geometryBox, getComputedBorderInsets(this))
382-
canvas.save()
383-
BackgroundStyleApplicator.applyClipPath(this, canvas, bounds)
384-
super.draw(canvas)
385-
canvas.restore()
386-
} else {
387-
super.draw(canvas)
376+
canvas.withSave {
377+
BackgroundStyleApplicator.applyClipPathIfPresent(this@ReactImageView, this)
378+
super.draw(this)
388379
}
389380
}
390381

@@ -664,4 +655,4 @@ public class ReactImageView(
664655
)
665656
.build()
666657
}
667-
}
658+
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/PreparedLayoutTextView.kt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@ import android.view.ViewGroup
2222
import androidx.annotation.ColorInt
2323
import androidx.annotation.DoNotInline
2424
import androidx.annotation.RequiresApi
25+
import androidx.core.graphics.withSave
2526
import androidx.core.view.ViewCompat
2627
import com.facebook.proguard.annotations.DoNotStrip
27-
import com.facebook.react.R
2828
import com.facebook.react.uimanager.BackgroundStyleApplicator
29-
import com.facebook.react.uimanager.BackgroundStyleApplicator.getComputedBorderInsets
3029
import com.facebook.react.uimanager.ReactCompoundView
31-
import com.facebook.react.uimanager.style.ClipPath
3230
import com.facebook.react.uimanager.style.Overflow
3331
import com.facebook.react.views.text.internal.span.ReactFragmentIndexSpan
34-
import com.facebook.react.views.view.GeometryBoxUtil.getGeometryBoxBounds
3532
import kotlin.collections.ArrayList
3633
import kotlin.math.roundToInt
3734

@@ -109,16 +106,9 @@ internal class PreparedLayoutTextView(context: Context) : ViewGroup(context), Re
109106
if (overflow != Overflow.VISIBLE) {
110107
BackgroundStyleApplicator.clipToPaddingBox(this, canvas)
111108
}
112-
val clipPath = getTag(R.id.clip_path) as? ClipPath
113-
if (clipPath != null) {
114-
val bounds = getGeometryBoxBounds(this, clipPath.geometryBox, getComputedBorderInsets(this))
115-
canvas.save()
116-
BackgroundStyleApplicator.applyClipPath(this, canvas, bounds)
117-
}
118-
119-
super.onDraw(canvas)
120-
if (clipPath != null) {
121-
canvas.restore()
109+
canvas.withSave {
110+
BackgroundStyleApplicator.applyClipPathIfPresent(this@PreparedLayoutTextView, this)
111+
super.onDraw(canvas)
122112
}
123113
canvas.translate(
124114
paddingLeft.toFloat(),

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.content.Context;
1111
import android.graphics.Canvas;
1212
import android.graphics.Rect;
13-
import android.graphics.RectF;
1413
import android.graphics.drawable.Drawable;
1514
import android.os.Build;
1615
import android.text.Layout;
@@ -58,7 +57,6 @@
5857
import com.facebook.react.views.text.internal.span.ReactTagSpan;
5958
import com.facebook.react.views.text.internal.span.TextInlineImageSpan;
6059
import com.facebook.react.views.text.internal.span.TextInlineViewPlaceholderSpan;
61-
import com.facebook.react.views.view.GeometryBoxUtil;
6260
import com.facebook.yoga.YogaMeasureMode;
6361

6462
@Nullsafe(Nullsafe.Mode.LOCAL)
@@ -369,14 +367,9 @@ protected void onDraw(Canvas canvas) {
369367
}
370368

371369
ClipPath clipPath = (ClipPath) getTag(R.id.clip_path);
372-
RectF bounds =
373-
GeometryBoxUtil.getGeometryBoxBounds(
374-
this,
375-
clipPath != null ? clipPath.getGeometryBox() : null,
376-
BackgroundStyleApplicator.getComputedBorderInsets(this));
377370
if (clipPath != null) {
378371
canvas.save();
379-
BackgroundStyleApplicator.applyClipPath(this, canvas, bounds);
372+
BackgroundStyleApplicator.applyClipPathIfPresent(this, canvas);
380373
}
381374
super.onDraw(canvas);
382375
if (clipPath != null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.kt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import androidx.appcompat.widget.AppCompatEditText
4444
import androidx.core.util.Predicate
4545
import androidx.core.view.ViewCompat
4646
import com.facebook.common.logging.FLog
47-
import com.facebook.react.R
4847
import com.facebook.react.bridge.ReactSoftExceptionLogger.logSoftException
4948
import com.facebook.react.common.ReactConstants
5049
import com.facebook.react.common.build.ReactBuildConfig
@@ -54,7 +53,6 @@ import com.facebook.react.uimanager.BackgroundStyleApplicator
5453
import com.facebook.react.uimanager.BackgroundStyleApplicator.clipToPaddingBox
5554
import com.facebook.react.uimanager.BackgroundStyleApplicator.getBackgroundColor
5655
import com.facebook.react.uimanager.BackgroundStyleApplicator.getBorderColor
57-
import com.facebook.react.uimanager.BackgroundStyleApplicator.getComputedBorderInsets
5856
import com.facebook.react.uimanager.BackgroundStyleApplicator.setBackgroundColor
5957
import com.facebook.react.uimanager.BackgroundStyleApplicator.setBorderColor
6058
import com.facebook.react.uimanager.BackgroundStyleApplicator.setBorderRadius
@@ -71,7 +69,6 @@ import com.facebook.react.uimanager.common.ViewUtil.getUIManagerType
7169
import com.facebook.react.uimanager.events.EventDispatcher
7270
import com.facebook.react.uimanager.style.BorderRadiusProp
7371
import com.facebook.react.uimanager.style.BorderStyle
74-
import com.facebook.react.uimanager.style.ClipPath
7572
import com.facebook.react.uimanager.style.LogicalEdge
7673
import com.facebook.react.uimanager.style.Overflow
7774
import com.facebook.react.views.text.ReactTextUpdate
@@ -91,10 +88,10 @@ import com.facebook.react.views.text.internal.span.ReactStrikethroughSpan
9188
import com.facebook.react.views.text.internal.span.ReactTextPaintHolderSpan
9289
import com.facebook.react.views.text.internal.span.ReactUnderlineSpan
9390
import com.facebook.react.views.text.internal.span.TextInlineImageSpan
94-
import com.facebook.react.views.view.GeometryBoxUtil.getGeometryBoxBounds
9591
import java.util.concurrent.CopyOnWriteArrayList
9692
import kotlin.math.max
9793
import kotlin.math.min
94+
import androidx.core.graphics.withSave
9895

9996
/**
10097
* A wrapper around the EditText that lets us better control what happens when an EditText gets
@@ -1209,15 +1206,9 @@ public open class ReactEditText public constructor(context: Context) : AppCompat
12091206
}
12101207

12111208
public override fun draw(canvas: Canvas) {
1212-
val clipPath = getTag(R.id.clip_path) as? ClipPath
1213-
if (clipPath != null) {
1214-
val bounds = getGeometryBoxBounds(this, clipPath.geometryBox, getComputedBorderInsets(this))
1215-
canvas.save()
1216-
BackgroundStyleApplicator.applyClipPath(this, canvas, bounds)
1217-
super.draw(canvas)
1218-
canvas.restore()
1219-
} else {
1220-
super.draw(canvas)
1209+
canvas.withSave {
1210+
BackgroundStyleApplicator.applyClipPathIfPresent(this@ReactEditText, this)
1211+
super.draw(this)
12211212
}
12221213
}
12231214

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ internal object GeometryBoxUtil {
134134
@JvmStatic
135135
fun getGeometryBoxBounds(view: View, geometryBox: GeometryBox?, computedBorderInsets: RectF?): RectF {
136136
val bounds = RectF(0f, 0f, view.width.toFloat(), view.height.toFloat())
137-
val params = view.layoutParams as? ViewGroup.MarginLayoutParams
137+
val params = view.layoutParams as? MarginLayoutParams
138138
val box = when (geometryBox) {
139139
GeometryBox.ContentBox -> {
140140
// ContentBox = BorderBox + padding

0 commit comments

Comments
 (0)