Skip to content

Commit 46404ad

Browse files
committed
feat: add drawAsOverlay flag to control stroke drawing order
Allows rendering the stroke before or after content. Useful for overlay effects or drawing boundaries on top of views.
1 parent e1005da commit 46404ad

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

library/src/main/java/com/sonsation/library/ShadowLayout.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class ShadowLayout : FrameLayout {
122122
)
123123
} ?: BlurMaskFilter.Blur.NORMAL
124124
this.blur = a.getDimension(R.styleable.ShadowLayout_stroke_blur, 0f)
125+
this.drawAsOverlay = a.getBoolean(R.styleable.ShadowLayout_stroke_draw_as_overlay, false)
125126
}
126127

127128
val allRadius = a.getDimension(R.styleable.ShadowLayout_background_radius, 0f)
@@ -274,7 +275,20 @@ class ShadowLayout : FrameLayout {
274275
canvas.drawPath(backgroundPath, backgroundPaint)
275276

276277
if (stroke?.isEnable == true) {
277-
canvas.drawPath(outlinePath, outlinePaint)
278+
279+
if (stroke?.drawAsOverlay == true) {
280+
281+
if (clipOutLine) {
282+
canvas.clipPath(outlinePath)
283+
}
284+
285+
super.dispatchDraw(canvas)
286+
287+
canvas.drawPath(outlinePath, outlinePaint)
288+
return
289+
} else {
290+
canvas.drawPath(outlinePath, outlinePaint)
291+
}
278292
}
279293

280294
if (clipOutLine) {
@@ -603,6 +617,11 @@ class ShadowLayout : FrameLayout {
603617
invalidate()
604618
}
605619

620+
fun updateStrokeDrawAsOverlay(drawAsOverlay: Boolean) {
621+
this.stroke?.drawAsOverlay = drawAsOverlay
622+
invalidate()
623+
}
624+
606625
fun updateStrokeType(strokeType: StrokeType) {
607626
this.stroke?.strokeType = strokeType
608627
if (autoAdjustPadding) {

library/src/main/java/com/sonsation/library/effet/Stroke.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Stroke(var strokeWidth: Float = 0f,
1010
var strokeType: StrokeType = StrokeType.INSIDE
1111
) {
1212

13+
var drawAsOverlay = false
1314
var blur: Float = 0f
1415
var blurType = BlurMaskFilter.Blur.NORMAL
1516
val isEnable: Boolean

library/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<enum name="CENTER" value="1"/>
4545
<enum name="OUTSIDE" value="2"/>
4646
</attr>
47+
<attr name="stroke_draw_as_overlay" format="boolean"/>
4748

4849
<attr name="shadow_color" format="color" />
4950
<attr name="shadow_offset_x" format="dimension" />

0 commit comments

Comments
 (0)