From 9322aede82815ba5a6bddf5b289692955d6e1d96 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 30 Apr 2021 18:05:28 -0400 Subject: added display text parsing --- src/utils/comments.tsx | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/utils/comments.tsx (limited to 'src/utils') diff --git a/src/utils/comments.tsx b/src/utils/comments.tsx new file mode 100644 index 00000000..a1f353d6 --- /dev/null +++ b/src/utils/comments.tsx @@ -0,0 +1,67 @@ +import React from 'react'; +import {Text} from 'react-native'; +import { + isMentionPartType, + parseValue, + Part, + PartType, +} from 'react-native-controlled-mentions'; +import TaggTypeahead from '../components/common/TaggTypeahead'; +import {TAGG_LIGHT_BLUE} from '../constants'; + +/** + * Part renderer + * + * https://github.com/dabakovich/react-native-controlled-mentions#rendering-mentioninputs-value + * + * @param part + * @param index + */ +const renderPart = (part: Part, index: number) => { + // Just plain text + if (!part.partType) { + return {part.text}; + } + + // Mention type part + if (isMentionPartType(part.partType)) { + return ( + console.log('Pressed', part.data)}> + {part.text} + + ); + } + + // Other styled part types + return ( + + {part.text} + + ); +}; + +/** + * Value renderer. Parsing value to parts array and then mapping the array using 'renderPart' + * + * https://github.com/dabakovich/react-native-controlled-mentions#rendering-mentioninputs-value + * + * @param value - value from MentionInput + * @param partTypes - the part types array that you providing to MentionInput + */ +export const renderValue: React.FC = (value: string, partTypes: PartType[]) => { + const {parts} = parseValue(value, partTypes); + return {parts.map(renderPart)}; +}; + +export const mentionPartTypes: PartType[] = [ + { + trigger: '@', + renderSuggestions: (props) => , + allowedSpacesCount: 0, + isInsertSpaceAfterMention: true, + textStyle: {color: TAGG_LIGHT_BLUE}, + }, +]; -- cgit v1.2.3-70-g09d2