Giter VIP home page Giter VIP logo

Comments (3)

MohiniGupta04 avatar MohiniGupta04 commented on September 14, 2024

For this you may save the searchKey into state using setState and pass this searchkey to the searchWords props of Highlighter like this example below:

This is your text input to enter the search keyword:
<TextInput placeholder='Search for initials' onChangeText={(text)=>{this.setState({searchKey: text})}} />

And your Highlighter component would look like this
<Highlighter
highlightStyle={{backgroundColor:'yellow'}}
searchWords={[this.state.searchKey]}
textToHighlight='Your text goes here.....'
/>

from react-native-highlight-words.

tushgup avatar tushgup commented on September 14, 2024

@MohiniGupta04 I'm still not clear how your comment resolves the issue @ramisalem described. I just found this package but I only want to try and highlight an exact match, not partial matches within a longer word... Any solutions?

from react-native-highlight-words.

JoeyFenny avatar JoeyFenny commented on September 14, 2024

I just figured out how accomplish using the code below. (I'm using lodash)

<TextInput
  ref={_input}
  onChangeText={onChangeValue}
  multiline
  placeholderTextColor={Colors.darkGrey}
  autoCapitalize="none"
  style={styles.textInput}
  placeholder={
    state.editComment
      ? 'Update comment...'
      : 'Write a comment...'
  }>
  {_.flatMap(
    value.split(' ').map((word: string) => {
      if (state[articleID].blacklistedWords[word]) {
        return (
          <Text style={styles.highlightStyle}>{word}</Text>
        );
      } else {
        return <Text>{word}</Text>;
      }
    }),
    (word, index, array) =>
      array.length - 1 !== index // .join(" ") throws [Object, object] so manually add spaces between array elements
        ? [word, <Text> </Text>]
        : word,
  )}
</TextInput>

from react-native-highlight-words.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.