-
Notifications
You must be signed in to change notification settings - Fork 1
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
[request] use custom patterns for mentions and hashtags #1
Comments
this is how text is stored on database: These are the pattern props: {
onPress: (text: string) => props.handleMentionPress(extractMentionUserId(text)),
pattern: /((.)\[([^[]*)]\(([^(^)]*)\))/i,
renderText: (matchingString: string) => renderMentionText(matchingString),
style: { color: props.theme.green },
suppressHighlighting: true
},
export const extractMentionUserId = (text: string) => {
const pattern = /((.)\[([^[]*)]\(([^(^)]*)\))/i;
const match = text.match(pattern);
return `${match ? match[4] : [1]}`;
};
export const renderMentionText = (matchingString: string) => {
const pattern = /((.)\[([^[]*)]\(([^(^)]*)\))/i;
const match = matchingString.match(pattern);
return `${match ? match[2] + "" + match[3] : [1]}`;
}; using this approach everytime someone taps the mention I get the user id on the |
Hey! I added You can catch all mentions before sending to Hyperlinks somehow like this: const myText = "@[johnonesix](qkkA1mR6A9PHkLjEEUcpOZtjSXI2) hey there!";
function getCustomHyperlinkMentions() {
const mentions: { start: number; end: number; data: { userId: string } }[] =
[];
const regex = /((.)\[([^[]*)]\(([^(^)]*)\))+/gi;
let match;
while ((match = regex.exec(myText)) != null) {
// mentions.push...
}
return mentions;
} Then you'll just need to normalize the text before rendering the component, removing the users' id. In order not to have a conflict, you'll need to disable |
Hi Andres, thanks again for the lib. It would be nice if we could use our own regex patterns for hashtags and mentions like react-native-parsed-text is doing it.
use case:
By adding custom patterns we can include the user id on the text string eg
{id:1, mention:”andres”}
but the user will only see @andres. This can came in handy when the user taps on the mention -> navigate to that user’s public profile.I’ll post an example on how I’m achieving this with react-native-parsed-text.
The text was updated successfully, but these errors were encountered: