-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support background colors on <Text> components #4155
Comments
This is a good topic to discuss during an upcoming checkpoint review, I will queue it up. The most elegant way to solve this may be to improve the XAML TextBlock to be able to take a background which will likely take a while (needs WinUI3+). |
Per @kmelmon, TextBlock.TextHighlighters property in XAML might be the right native property that helps address this scenario. I looked out of curiosity - Android has an analogous TextView.textColorHighlight property and the scenario appears to be possible to accomplish in iOS as well by applying a background color to an NSAttributedString combined with UITextView's attributedText props. This may be a good candidate to surface as a cross-platform prop for react-native. |
FYI @KAnder425 I've just submitted a PR implementing what you requested - backgroundColor for arbitrarily nested <Text> elements. I hope to have it merged soon. |
Proposal: Support background colors on <Text> components
Summary
Both iOS and Android RN support the ability to set the background color of a <Text> element. Without this support in RNW, we have to resort to wrapping Text in Views in order to get the same effect. This approach quickly runs into complex Yoga/Flexbox layout issues that prevent its use in all but the most basic scenarios.
This is not a new issue. See #698 and #1949 for background.
Motivation
I'm implementing a search highlighting feature in our app. I need to apply a highlight background on specific runs of text in several elements of the app. If I use nested <Text> elements to apply styling like 'underline' to the various runs of text, everything looks stellar. When I switch to nested <View> elements to apply a background color I run into seemingly insurmountable issues with Flexbox/Yoga layout and all those nested Views.
I'm (somewhat) sure I'll surmount those issues at some point using the View/Text workaround, but it would be so much better if I could just do what iOS and Android already support.
Basic example
Here's an example of what I'd like to do....
Open Questions
I realize that this issue is due to a lack of support for background color in XAML's TextBlock but perhaps we can find a creative way to workaround that in RNW native code?
The text was updated successfully, but these errors were encountered: