aboutsummaryrefslogtreecommitdiff
path: root/src/components/comments/AddComment.tsx
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-06-11 15:41:50 -0400
committerIvan Chen <ivan@tagg.id>2021-06-11 15:41:50 -0400
commite4dd6cf05a631197be4d192901d532e8625900bb (patch)
tree83638a5a2803c9ca2a4a491dd37180871f3cbdde /src/components/comments/AddComment.tsx
parenteb672872d85f203085c96005758314d5dba359f2 (diff)
Cleanup scrolling logic, Fix scrollTo logic
Diffstat (limited to 'src/components/comments/AddComment.tsx')
-rw-r--r--src/components/comments/AddComment.tsx85
1 files changed, 46 insertions, 39 deletions
diff --git a/src/components/comments/AddComment.tsx b/src/components/comments/AddComment.tsx
index 9d9824db..9667046c 100644
--- a/src/components/comments/AddComment.tsx
+++ b/src/components/comments/AddComment.tsx
@@ -26,6 +26,7 @@ export interface AddCommentProps {
placeholderText: string;
callback?: (message: string) => void;
onFocus?: () => void;
+ isKeyboardAvoiding?: boolean;
theme?: 'dark' | 'white';
}
@@ -34,6 +35,7 @@ const AddComment: React.FC<AddCommentProps> = ({
placeholderText,
callback = (_) => null,
onFocus = () => null,
+ isKeyboardAvoiding = true,
theme = 'white',
}) => {
const {setShouldUpdateAllComments = () => null, commentTapped} =
@@ -111,49 +113,54 @@ const AddComment: React.FC<AddCommentProps> = ({
}
}, [isReplyingToComment, isReplyingToReply, commentTapped]);
- return (
+ const mainContent = () => (
+ <View
+ style={[
+ theme === 'white' ? styles.containerWhite : styles.containerDark,
+ keyboardVisible && theme !== 'dark' ? styles.whiteBackround : {},
+ ]}>
+ <View style={styles.textContainer}>
+ <Avatar style={styles.avatar} uri={avatar} />
+ <MentionInputControlled
+ containerStyle={styles.text}
+ placeholderTextColor={theme === 'dark' ? '#828282' : undefined}
+ placeholder={placeholderText}
+ value={inReplyToMention + comment}
+ onFocus={onFocus}
+ onChange={(newText: string) => {
+ // skipping the `inReplyToMention` text
+ setComment(
+ newText.substring(inReplyToMention.length, newText.length),
+ );
+ }}
+ inputRef={ref}
+ partTypes={mentionPartTypes('blue')}
+ />
+ {(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>
+ </View>
+ );
+ return isKeyboardAvoiding ? (
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
keyboardVerticalOffset={SCREEN_HEIGHT * 0.1}>
- <View
- style={[
- theme === 'white' ? styles.containerWhite : styles.containerDark,
- keyboardVisible && theme !== 'dark' ? styles.whiteBackround : {},
- ]}>
- <View style={styles.textContainer}>
- <Avatar style={styles.avatar} uri={avatar} />
- <MentionInputControlled
- containerStyle={styles.text}
- placeholderTextColor={theme === 'dark' ? '#828282' : undefined}
- placeholder={placeholderText}
- value={inReplyToMention + comment}
- onFocus={onFocus}
- onChange={(newText: string) => {
- // skipping the `inReplyToMention` text
- setComment(
- newText.substring(inReplyToMention.length, newText.length),
- );
- }}
- inputRef={ref}
- partTypes={mentionPartTypes('blue')}
- />
- {(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>
- </View>
+ {mainContent()}
</KeyboardAvoidingView>
+ ) : (
+ mainContent()
);
};