Skip to content

Commit

Permalink
Library: Clip child views in card view temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
fornewid committed Jun 2, 2020
1 parent 8ca68db commit 90a79d8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions neumorphism/src/main/java/soup/neumorphism/NeumorphCardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package soup.neumorphism

import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.widget.FrameLayout
import androidx.annotation.ColorInt
import soup.neumorphism.internal.util.NeumorphResources
Expand Down Expand Up @@ -64,6 +66,17 @@ class NeumorphCardView @JvmOverloads constructor(
isInitialized = true
}

override fun drawChild(canvas: Canvas, child: View, drawingTime: Long): Boolean {
//TODO: clip using Outline smoothly
val checkpoint = canvas.save()
canvas.clipPath(shapeDrawable.getOutlinePath())
try {
return super.drawChild(canvas, child, drawingTime)
} finally {
canvas.restoreToCount(checkpoint)
}
}

override fun setPadding(left: Int, top: Int, right: Int, bottom: Int) {
super.setPadding(left, top, right, bottom)
shapeDrawable.setPadding(left, top, right, bottom)
Expand Down

0 comments on commit 90a79d8

Please sign in to comment.