ryer.io

Debugging Dark Mode Contrast in React Native Date Picker

TL;DR

  • Upgraded React Native Date Picker to version 5.13 and discovered a contrast issue in iOS dark mode.
  • The issue was due to the text color not adjusting to the color scheme, unlike on Android.
  • Implemented a conditional fix to dynamically set text color based on iOS theme.

While testing the upgraded React Native Date Picker library from version 5.02 to 5.13, I stumbled upon a contrast problem in the monthly report section’s month selector, specifically on iOS when in dark mode. The text color was barely visible against the background, while Android seemed unaffected due to better adherence to system theme colors.

Upon digging deeper, I found that the month selector was a custom component not responding to theme changes. The text color on Android was appropriately adapting, as the app leveraged the Android system’s text color state. However, iOS required an explicit assignment that wasn’t defined, leading to undesirable results.

To tackle this, I focused on creating logic to dynamically set the text color based on the device’s current theme. Here’s the approach I took:

  1. Identifying the Problem: I figured out that the text color issue was rooted in how the iOS implementation didn’t automatically adapt to theme changes like Android.
  2. Developing a Conditional Solution: By implementing a stateful approach, I created an iosTextColor state to be updated based on the focus and theme change.
  3. Testing: After conditionally setting the text color using system theme detection on iOS, I verified the fix by switching between light and dark modes, ensuring that the typography color aligned with the intended design.

This fix not only resolved the iOS text color issue but also improved overall design conformance, ensuring functionality across both light and dark modes. Moving forward, having a conditional check for text colors based on system settings will become a part of my standard processes, ensuring cross-platform robustness and a seamless user experience.