question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong ripple color in Switch component

See original GitHub issue

Environment

React Native Environment Info:
  System:
    OS: Windows 10
    CPU: (4) x64 Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
    Memory: 8.03 GB / 15.91 GB
  Binaries:
    npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
  IDEs:
    Android Studio: Version  3.1.0.0 AI-173.4907809

Description

I configure a different color for my Switch component with the props trackColor and thumbColor. When I press the switch to change it’s value, the color on the ripple is completely different from the one configured with the props. The bug only occurs on Android platform with the ripple and with the background color when the state is changing, After the animation ends, the background color assume the custom color I configured.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
rnikecommented, Jan 3, 2021

Follow the hint gave by @kelset, adding codes below in ReactSwitch.java fixes this issue

   public void setThumbColor(@Nullable Integer color) {
     setColor(super.getThumbDrawable(), color);
+
+    // Set the ripple color with thumb color
+    RippleDrawable ripple = (RippleDrawable) super.getBackground();
+    ColorStateList customColorState = new ColorStateList(
+      new int[][]{ new int[]{ android.R.attr.state_pressed } },
+      new int[]{color});
+
+    ripple.setColor(customColorState);
   }

Screenshot ripple_fixed

But I’m not sure if this is a good practice.

1reaction
rnikecommented, Jan 4, 2021

@kelset Sure, here’s the PR

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I override the style of the Material-UI switch ...
I want to control the color of the switch component, both when it is checked and when is is unchecked. By default it...
Read more >
How to Enable ripple for Switch label in Angular ... - Syncfusion
You can achieve this by using rippleMouseHandler method. The following example illustrates how to enable ripple effect for labels in Switch component. Source....
Read more >
Switch API - Material UI - MUI
Use when the component is not controlled. If true , the component is disabled. If true , the ripple effect is disabled.
Read more >
Switches - Material Design
A travel app that uses Material Design components and Material Theming to create a personalized on-brand experience. Related link arrow_downward. Color. Crane's ...
Read more >
How to Recreate the Ripple Effect of Material Design Buttons
Learn to make the ripple effect of Material Design's button component. We'll start with ES6+ JavaScript, before looking at other solutions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found