aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-04-29 16:32:30 -0400
committerIvan Chen <ivan@tagg.id>2021-05-04 20:48:05 -0400
commitf0c5a226d4ae02cd92d92372708056f63d3cd976 (patch)
tree42d001e7a98edf27428399756c0a300d9aa25e0d /src
parent0ae6415c3f8fec65bfb6996b773be6fe67a02d58 (diff)
added ParsedText, initial work for typeahead
Diffstat (limited to 'src')
-rw-r--r--src/components/comments/AddComment.tsx48
-rw-r--r--src/components/common/TaggTypeahead.tsx25
-rw-r--r--src/components/common/index.ts1
-rw-r--r--src/screens/profile/MomentCommentsScreen.tsx34
4 files changed, 67 insertions, 41 deletions
diff --git a/src/components/comments/AddComment.tsx b/src/components/comments/AddComment.tsx
index 2a8c773e..79d4d970 100644
--- a/src/components/comments/AddComment.tsx
+++ b/src/components/comments/AddComment.tsx
@@ -1,12 +1,14 @@
-import React, {useEffect, useRef} from 'react';
+import React, {useEffect, useRef, useState} from 'react';
import {
Keyboard,
KeyboardAvoidingView,
Platform,
StyleSheet,
+ TextInput,
View,
} from 'react-native';
-import {TextInput, TouchableOpacity} from 'react-native-gesture-handler';
+import {TouchableOpacity} from 'react-native-gesture-handler';
+import ParsedText from 'react-native-parsed-text';
import {useDispatch, useSelector} from 'react-redux';
import UpArrowIcon from '../../assets/icons/up_arrow.svg';
import {TAGG_LIGHT_BLUE} from '../../constants';
@@ -14,7 +16,7 @@ import {postComment} from '../../services';
import {updateReplyPosted} from '../../store/actions';
import {RootState} from '../../store/rootreducer';
import {SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils';
-import {Avatar} from '../common';
+import {Avatar, TaggTypeahead} from '../common';
/**
* This file provides the add comment view for a user.
@@ -36,7 +38,9 @@ const AddComment: React.FC<AddCommentProps> = ({
isCommentInFocus,
}) => {
const [comment, setComment] = React.useState('');
- const [keyboardVisible, setKeyboardVisible] = React.useState(false);
+ const [keyboardVisible, setKeyboardVisible] = useState(false);
+ const [isMentioning, setIsMentioning] = useState(false);
+ const [mentionSearch, setMentionSearch] = useState('');
const {avatar} = useSelector((state: RootState) => state.user);
const dispatch = useDispatch();
@@ -95,6 +99,7 @@ const AddComment: React.FC<AddCommentProps> = ({
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
keyboardVerticalOffset={SCREEN_HEIGHT * 0.1}>
+ {isMentioning && <TaggTypeahead search={mentionSearch} />}
<View
style={[
styles.container,
@@ -106,11 +111,37 @@ const AddComment: React.FC<AddCommentProps> = ({
style={styles.text}
placeholder={placeholderText}
placeholderTextColor="grey"
- onChangeText={setComment}
- value={comment}
+ onChangeText={(newText: string) => {
+ const newestChar = newText[newText.length - 1];
+ if (newestChar === ' ') {
+ setIsMentioning(false);
+ setMentionSearch('');
+ }
+ if (newestChar === '@') {
+ setIsMentioning(true);
+ }
+ if (isMentioning) {
+ const match = newText.match(/@(.*)$/);
+ if (match) {
+ setMentionSearch(match[1]);
+ }
+ }
+ setComment(newText);
+ }}
multiline={true}
- ref={ref}
- />
+ ref={ref}>
+ <ParsedText
+ style={styles.text}
+ parse={[
+ {
+ pattern: /@\{.*\}/,
+ style: {color: 'red'},
+ renderText: (text: string) => '@fooo',
+ },
+ ]}>
+ {comment}
+ </ParsedText>
+ </TextInput>
<View style={styles.submitButton}>
<TouchableOpacity style={styles.submitButton} onPress={addComment}>
<UpArrowIcon width={35} height={35} color={'white'} />
@@ -141,6 +172,7 @@ const styles = StyleSheet.create({
flex: 1,
padding: '1%',
marginHorizontal: '1%',
+ maxHeight: 100,
},
avatar: {
height: 35,
diff --git a/src/components/common/TaggTypeahead.tsx b/src/components/common/TaggTypeahead.tsx
new file mode 100644
index 00000000..8a68c9a5
--- /dev/null
+++ b/src/components/common/TaggTypeahead.tsx
@@ -0,0 +1,25 @@
+import React from 'react';
+import {StyleSheet, Text, View} from 'react-native';
+import {SCREEN_WIDTH} from '../../utils';
+
+type TaggTypeaheadProps = {
+ search: string;
+};
+
+const TaggTypeahead: React.FC<TaggTypeaheadProps> = ({search}) => {
+ return (
+ <View style={styles.container}>
+ <Text>searching for {search}</Text>
+ </View>
+ );
+};
+
+const styles = StyleSheet.create({
+ container: {
+ width: SCREEN_WIDTH * 0.9,
+ height: 100,
+ borderWidth: 1,
+ },
+});
+
+export default TaggTypeahead;
diff --git a/src/components/common/index.ts b/src/components/common/index.ts
index 802cf505..4a49339b 100644
--- a/src/components/common/index.ts
+++ b/src/components/common/index.ts
@@ -24,3 +24,4 @@ export {default as TaggSquareButton} from './TaggSquareButton';
export {default as GradientBorderButton} from './GradientBorderButton';
export {default as BasicButton} from './BasicButton';
export {default as Avatar} from './Avatar';
+export {default as TaggTypeahead} from './TaggTypeahead';
diff --git a/src/screens/profile/MomentCommentsScreen.tsx b/src/screens/profile/MomentCommentsScreen.tsx
index b0208f6f..effbbb63 100644
--- a/src/screens/profile/MomentCommentsScreen.tsx
+++ b/src/screens/profile/MomentCommentsScreen.tsx
@@ -8,12 +8,7 @@ import CommentsContainer from '../../components/comments/CommentsContainer';
import {ADD_COMMENT_TEXT} from '../../constants/strings';
import {headerBarOptions, MainStackParams} from '../../routes/main';
import {CommentType} from '../../types';
-import {
- HeaderHeight,
- normalize,
- SCREEN_HEIGHT,
- SCREEN_WIDTH,
-} from '../../utils';
+import {HeaderHeight, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils';
/**
* Comments Screen for an image uploaded
@@ -88,39 +83,12 @@ const styles = StyleSheet.create({
backgroundColor: 'white',
height: '100%',
},
- header: {justifyContent: 'center', padding: '3%'},
- headerText: {
- position: 'absolute',
- alignSelf: 'center',
- fontSize: normalize(18),
- fontWeight: '700',
- lineHeight: normalize(21.48),
- letterSpacing: normalize(1.3),
- },
- headerButton: {
- width: '5%',
- aspectRatio: 1,
- padding: 0,
- marginLeft: '5%',
- alignSelf: 'flex-start',
- },
- headerButtonText: {
- color: 'black',
- fontSize: 18,
- fontWeight: '400',
- },
body: {
marginTop: HeaderHeight,
width: SCREEN_WIDTH * 0.9,
height: SCREEN_HEIGHT * 0.8,
paddingTop: '3%',
},
- scrollView: {
- paddingHorizontal: 20,
- },
- scrollViewContent: {
- justifyContent: 'center',
- },
});
export default MomentCommentsScreen;