diff options
author | Ivan Chen <ivan@tagg.id> | 2021-06-24 17:41:45 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-06-24 17:41:45 -0400 |
commit | b184179a8bff25ad018d02abc31acadc7b3f6a62 (patch) | |
tree | efd94448ee76860156d7622a61e6eb8785c10f10 /src/components/comments/CommentTextField.tsx | |
parent | 981051448fee6197544383e535fea7a72827d41d (diff) | |
parent | 53bdc94cf0491e348b7d4ad61e51ce1844423773 (diff) |
Merge branch 'master' into tma948-video-playback
# Conflicts:
# ios/Podfile.lock
# package.json
# src/components/moments/Moment.tsx
# src/routes/main/MainStackNavigator.tsx
# src/screens/moments/TagFriendsScreen.tsx
# src/screens/profile/CaptionScreen.tsx
# yarn.lock
Diffstat (limited to 'src/components/comments/CommentTextField.tsx')
-rw-r--r-- | src/components/comments/CommentTextField.tsx | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/src/components/comments/CommentTextField.tsx b/src/components/comments/CommentTextField.tsx new file mode 100644 index 00000000..6e92329c --- /dev/null +++ b/src/components/comments/CommentTextField.tsx @@ -0,0 +1,164 @@ +import React, {FC, ReactFragment} from 'react'; +import { + NativeSyntheticEvent, + StyleSheet, + StyleProp, + Text, + TextInput, + TextInputSelectionChangeEventData, + TouchableOpacity, + View, + ViewStyle, +} from 'react-native'; +import {useSelector} from 'react-redux'; +import {TAGG_LIGHT_BLUE} from '../../constants'; +import {RootState} from '../../store/rootReducer'; +import { + Part, + PartType, + MentionPartType, +} from 'react-native-controlled-mentions/dist/types'; +import { + defaultMentionTextStyle, + isMentionPartType, +} from 'react-native-controlled-mentions/dist/utils'; +import {Avatar} from '../common'; +import {normalize} from '../../utils'; + +import UpArrowIcon from '../../assets/icons/up_arrow.svg'; + +type CommentTextFieldProps = { + containerStyle: StyleProp<ViewStyle>; + validateInput: any; + keyboardText: string; + partTypes: PartType[]; + renderMentionSuggestions: (mentionType: MentionPartType) => ReactFragment; + handleTextInputRef: (ref: TextInput) => null; + onChangeInput: (changedText: string) => null; + handleSelectionChange: ( + event: NativeSyntheticEvent<TextInputSelectionChangeEventData>, + ) => null; + parts: Part[]; + addComment: () => any; + theme?: 'dark' | 'white'; + keyboardVisible?: boolean; + comment?: string; +}; + +const CommentTextField: FC<CommentTextFieldProps> = ({ + containerStyle, + validateInput, + keyboardText, + partTypes, + renderMentionSuggestions, + handleTextInputRef, + onChangeInput, + handleSelectionChange, + parts, + addComment, + theme = 'white', + keyboardVisible = true, + comment = '', + ...textInputProps +}) => { + const {avatar} = useSelector((state: RootState) => state.user); + + return ( + <View style={containerStyle}> + {validateInput(keyboardText) + ? ( + partTypes.filter( + (one) => + isMentionPartType(one) && + one.renderSuggestions != null && + !one.isBottomMentionSuggestionsRender, + ) as MentionPartType[] + ).map(renderMentionSuggestions) + : null} + + <View style={styles.containerStyle}> + <Avatar style={styles.avatar} uri={avatar} /> + <TextInput + multiline + {...textInputProps} + ref={handleTextInputRef} + onChangeText={onChangeInput} + onSelectionChange={handleSelectionChange} + style={styles.text}> + <Text> + {parts.map(({text, partType, data}, index) => + partType ? ( + <Text + key={`${index}-${data?.trigger ?? 'pattern'}`} + style={partType.textStyle ?? defaultMentionTextStyle}> + {text} + </Text> + ) : ( + <Text key={index}>{text}</Text> + ), + )} + </Text> + </TextInput> + {(theme === 'white' || (theme === 'dark' && keyboardVisible)) && ( + <View style={styles.submitButton}> + <TouchableOpacity + style={ + comment === '' + ? [styles.submitButton, styles.greyButton] + : styles.submitButton + } + disabled={comment === ''} + onPress={addComment}> + <UpArrowIcon width={35} height={35} color={'white'} /> + </TouchableOpacity> + </View> + )} + </View> + + {validateInput(keyboardText) && + ( + partTypes.filter( + (one) => + isMentionPartType(one) && + one.renderSuggestions != null && + one.isBottomMentionSuggestionsRender, + ) as MentionPartType[] + ).map(renderMentionSuggestions)} + </View> + ); +}; + +const styles = StyleSheet.create({ + avatar: { + height: 35, + width: 35, + borderRadius: 30, + marginRight: 10, + marginLeft: '3%', + marginVertical: '2%', + }, + containerStyle: { + flexDirection: 'row', + alignSelf: 'center', + alignItems: 'center', + justifyContent: 'center', + height: normalize(45), + }, + greyButton: { + backgroundColor: 'grey', + }, + submitButton: { + height: 35, + width: 35, + backgroundColor: TAGG_LIGHT_BLUE, + borderRadius: 999, + justifyContent: 'center', + alignItems: 'center', + marginRight: '3%', + marginVertical: '2%', + alignSelf: 'flex-end', + }, + text: {flex: 1}, +}); + +export {CommentTextField}; |