facebookarchive / shimmer-android

An easy, flexible way to add a shimmering effect to any view in an Android app.
http://facebook.github.io/shimmer-android/
Other
5.32k stars 695 forks source link

When using inside cardView with rounded corners, corners are CLEARED #116

Open qoswa opened 3 years ago

qoswa commented 3 years ago

Environment: Android emulator, Nexus 5 Api 25

Layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_margin="20dp">

    <androidx.cardview.widget.CardView
        android:id="@+id/image_card"
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:elevation="6dp"
        app:cardCornerRadius="14dp">

        <ImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            tools:ignore="ContentDescription" />

    </androidx.cardview.widget.CardView>

</FrameLayout>

Activity:

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val imageView = findViewById<ImageView>(R.id.image)
        val shimmer = Shimmer.ColorHighlightBuilder()
            .setBaseColor(ContextCompat.getColor(this, R.color.skeleton_mask))
            .setBaseAlpha(1f)
            .setHighlightAlpha(1f)
            .setHighlightColor(ContextCompat.getColor(this, R.color.skeleton_shimmer))
            .setDuration(2000)
            .setDirection(Shimmer.Direction.LEFT_TO_RIGHT)
            .setAutoStart(true)
            .build()
        val shimmerDrawable = ShimmerDrawable()
        shimmerDrawable.setShimmer(shimmer)
        imageView.setImageDrawable(shimmerDrawable)
    }

}

Results in: newimage

As i can see the reason is that CardView uses RoundedCornerDrawable underneath and when we place our ShimmerDrawable over it, PorterDuff.Mode.SRC_IN clears corner pixels (and because of it they are black)

shreelakshmijoshi commented 3 years ago

Hi @qoswa ! I am a new open source contributor and would like to solve this issue, could you help me understand the issue better by providing some extra references ? Is this is issue open to contribute ?