1

I want something feature in textInput like if we write hello then hello should be bold in the textinput and remaining words will be normal. Can someone help me out with it?

It's something different from Text Component, which mentioned in below link.

https://stackoverflow.com/questions/35718143/react-native-add-bold-or-italics-to-single-words-in-text-field

1 Answers1

1

You will have to make custom textInput component, something like this:

const [txt,setTxt] = useState("");
        <Pressable>
            <TextInput placeholder="Type Something..." onChangeText={(value)=>setTxt(value)}/>
                <View style={{flexDirection: 'row'}}>
                    {txt.split(" ").map((text)=><Text style={{fontWeight:text == "bold"?'bold':null}}>{text+" "}</Text>)}
                </View>
        </Pressable>

Replace text == "bold" with any value that you want to make bold.

Edit: if you want to make more than one word bold, group them in an array and update your condition like this:

const anArrayOfBoldStrings = ["bold","hello","stackoverflow"];

            <Pressable>
                <TextInput placeholder="Type Something..." onChangeText={(value)=>setTxt(value)}/>
                    <View style={{flexDirection: 'row'}}>
                        {txt.split(" ").map((text)=><Text style={{fontWeight:text == anArrayOfBoldStrings.includes(text?'bold':null}}>{text+" "}</Text>)}
                    </View>
            </Pressable>
Hassan Kandil
  • 1,612
  • 1
  • 13
  • 26