I would like to highlight a multiline text in a expo app by changing the text's background color. there i can like the image highlight color.
my code:

import HighlightText from "@sanar/react-native-highlight-text"; <HighlightText highlightStyle={{ backgroundColor: isSelectedVerse || isCurrentlySpeaking ? highlightColorValue : highlightColorValue, color: "black", }} searchWords={ highlightColorValue !== "transparent" || isSelectedVerse || isCurrentlySpeaking ? [verse.text] : [] } textToHighlight={verse.text} style={[ { fontSize, color: textColor, lineHeight: fontSize * 1.5, textAlign: "justify", borderRadius: 4, position: "relative", flex: 1, fontFamily: activeRead && bookData.book === bookName && chapter.chapter === chapterNumber && verse.verse === verseIndex + 1 && verse.text === verseText ? "RobotoExtraBold" : isCurrentlySpeaking ? "RobotoSemiBold" : isVerseRead ? "RobotoMidium" : "RobotoRegular", }, activeVerseForButtons === `${bookData.book}-${chapter.chapter}-${verse.verse}` && { textDecorationLine: "underline", textDecorationStyle: "dashed", textDecorationColor: textColor, borderBottomWidth: 1, borderStyle: "dashed", paddingBottom: 2, }, ]} className="font-Roboto" />

enter image description here

but i want to like that:
enter image description here

Rasel Babu's user avatar

New contributor

Rasel Babu is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

import { View, Text } from "react-native"; const isHighlighted = isSelectedVerse || isCurrentlySpeaking; <View style={{ backgroundColor: isHighlighted ? highlightColorValue : "transparent", borderRadius: 6, paddingHorizontal: 8, paddingVertical: 6, marginVertical: 2, }} > <Text style={{ fontSize, color: textColor, lineHeight: fontSize * 1.5, textAlign: "justify", fontFamily: activeRead && bookData.book === bookName && chapter.chapter === chapterNumber && verse.verse === verseIndex + 1 && verse.text === verseText ? "RobotoExtraBold" : isCurrentlySpeaking ? "RobotoSemiBold" : isVerseRead ? "RobotoMidium" : "RobotoRegular", ...(activeVerseForButtons === `${bookData.book}-${chapter.chapter}-${verse.verse}` && { textDecorationLine: "underline", textDecorationStyle: "dashed", textDecorationColor: textColor, }), }} > {verse.text} </Text> </View>

Instead of highlighting individual words HighlightText, I wrapped the whole verse inside a View and applied the background color to that container.

Lucifer's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.