Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Fix switch ripple color #30685

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
package com.facebook.react.views.switchview;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
rnike marked this conversation as resolved.
Show resolved Hide resolved
import android.os.Build;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;

Expand Down Expand Up @@ -59,6 +62,16 @@ public void setTrackColor(@Nullable Integer color) {

public void setThumbColor(@Nullable Integer color) {
setColor(super.getThumbDrawable(), color);

// Set the ripple color with thumb color if >= LOLLIPOP
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
RippleDrawable ripple = (RippleDrawable) super.getBackground();
rnike marked this conversation as resolved.
Show resolved Hide resolved
ColorStateList customColorState =
new ColorStateList(
new int[][] {new int[] {android.R.attr.state_pressed}}, new int[] {color});

ripple.setColor(customColorState);
}
}

/*package*/ void setOn(boolean on) {
Expand Down