pmusolino / Wormholy

iOS network debugging, like a wizard 🧙‍♂️
MIT License
2.35k stars 189 forks source link

fix: Search Result on Response Body and Request Body screen not visible on darkmode #129

Closed rickirby closed 1 year ago

rickirby commented 1 year ago

Summary

On darkmode enabled, when searching a keyword inside Request Body or Response Body, the screen shows matched (highlighted) text only. The remaining text appear black, blend with its background color, so it can't be read. The issue was raised on https://github.com/pmusolino/Wormholy/issues/128

Steps to reproduce

What is the current bug behavior?

The screen shows highlighted matched text only. The remaining are black, blends with its background color.

What is the expected correct behavior?

The screen should show remaining non-matched text also.

Root Cause

On WHTextView inside highlight(text:with:font:highlightedFont:) -> [NSTextCheckingResult] method, it adds attributes only to the highlighted text. But for the default text (non-matched) attribute wasn't set yet. That's why its text color was black as same as its background color.

How to solve ?

Set attributes .foregroundColor to UIColor.label as default attribute to the text. Please note that UIColor.label is only available for iOS 13 or above, since dark mode feature was first introduced in that iOS version.

Relevant logs and/or screenshots

Before After
Simulator Screen Shot - iPhone 14 Pro - 2022-12-08 at 10 32 39 Simulator Screen Shot - iPhone 14 Pro - 2022-12-08 at 10 33 17
rickirby commented 1 year ago

I have checked also in light mode it works fine 👍 Simulator Screen Shot - iPhone 14 Pro - 2022-12-08 at 11 17 46

pmusolino commented 1 year ago

Looks good to me! Thanks for your contribution :shipit: