npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-mention-editor

v1.0.7

Published

Based on the code in https://github.com/mrazadar/react-native-mentions-editor. Still a work in progress.

Downloads

2,464

Readme

react-native-mention-editor

Based on the code in https://github.com/mrazadar/react-native-mentions-editor. Still a work in progress.

Improvements:

  • Removed backward typing bug
  • Fixed cursor not showing on Android
  • Can edit existing text with @ mentions
  • Can customize user objects as needed
  • Can show custom secondary text in mention items
  • Can change the key with which to extract display name of user (@Full Name instead of @username, for instance)
  • Can show mention list above or below editor as needed

Getting started

$ npm install react-native-mention-editor --save

Usage

import Editor from 'react-native-mention-editor';

<Editor
  list={this.state.userList} //send the list of user objects
  editorStyles={{
    mainContainer: style.textInputStyle,
    inputMaskText: { fontFamily: font.regular }, //important to make sure input and
    input: { fontFamily: font.regular }, //inputMaskText styles match exactly
  }}
  displayKey="name" //specify which key in the user object to display
  extractionKey="username" //specify which key is to be treated as the unique ID of user objects
  secondaryKey="speciality" //specify what to show in the second line. Omit this prop if you don't need a second line
  showEditor
  onHideMentions={() => this.setState({ showMentions: false })}
  clearInput={this.state.clearInput}
  placeholder={strings.common.say_something}
  onChange={({ text, displayText }) => {
    this.setState({ text, displayText });
  }}
/>;

Whatever displayKey and extractionKey are specified, those strings are mandatory as keys in the user objects in the list passed to the Editor. For example, here, displayKey="name" and extractionKey="username" so a user object must mandatorily be of the form {"name": "Full Name", "username": "some_one", ...any other keys and values you want}.

The onChange() method will always receive two params:

  • text in the form Hey @[username](id:1) this is good work
  • displayText in the form Hey @Full Name this is good work (if you have specified displayKey to be "name").

To format the text according to your api's needs, you can use the following code snippet:

import { EU } from 'react-native-mention-editor';

export const formatMentionTextToApiFormat = inputText => {
  const retLines = inputText.split('\n');
  const formattedText = [];
  retLines.forEach((retLine, rowIndex) => {
    const mentions = EU.findMentions(retLine);
    if (mentions.length) {
      let lastIndex = 0;
      mentions.forEach((men, index) => {
        const initialStr = retLine.substring(lastIndex, men.start);
        lastIndex = men.end + 1;
        formattedText.push(initialStr);
        const formattedMention = `@{{${men.id}||${men.username}}}`; //You can format the mention text any way you want here. Remember that inputText will always have the value of the extractionKey you specified as the value of the id key in this object.
        formattedText.push(formattedMention);
        if (mentions.length - 1 === index) {
          const lastStr = retLine.substr(lastIndex); //remaining string
          formattedText.push(lastStr);
        }
      });
    } else {
      formattedText.push(retLine);
    }
  });
  return formattedText.join('');
};

Other Properties:

list: array This should be the list of objects to be used as options for the mentions list. Note This must contain id and username properties to uniqely identify object in the list.

initialValue: string Use this to initialize TextInput with the initial value. Usage. initalValue: "Hey @mrazadar this is good work"

clearInput: bool When true input will be cleared automatically.

onChange: function This function will be called on input change event.

showEditor: bool Programmatically show/hide editor by using this property.

toggleEditor: function Use this to handle blur event on input.

showMentions: bool Use this property to programmatically trigger the mentionsList this will add @ character in the value.

shouldShowMentionsBelow: bool When true, the list of mentions will be shown below the editor instead of above.

onHideMentions: function This callback will be called when user stop tracking of mention.

placeholder: string placeholder for empty input.

editorStyles: object This object will contain the overriding styles for different nodes. Check the object below to see how you can override styles.

editorStyles: {
    mainContainer: {},
    editorContainer: {...},
    inputMaskTextWrapper: {},
    inputMaskText: {},
    input: {},
    mentionsListWrapper:{},
    mentionListItemWrapper: {}
    mentionListItemTextWrapper: {},
    mentionListItemTitle: {}
    mentionListItemUsername: {}
}