diff options
| author | Ivan Chen <ivan@tagg.id> | 2021-01-22 19:05:36 -0500 |
|---|---|---|
| committer | Ivan Chen <ivan@tagg.id> | 2021-01-22 19:05:36 -0500 |
| commit | e5915b02008dfcebe08de063f0440974c8415d4b (patch) | |
| tree | 308517c416605f13163bf6847e5c322ee23ab2e8 /src/screens/profile/MomentCommentsScreen.tsx | |
| parent | cf420db54deb32be1e6bc4092eef105cc23d93e4 (diff) | |
| parent | 9921e80e60cb24d0fc7b99123a8b146c6e7d14ff (diff) | |
Merge branch 'master' into tma552-adjust-styles-and-sizes
# Conflicts:
# src/components/profile/Content.tsx
# src/screens/profile/MomentCommentsScreen.tsx
Diffstat (limited to 'src/screens/profile/MomentCommentsScreen.tsx')
| -rw-r--r-- | src/screens/profile/MomentCommentsScreen.tsx | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/screens/profile/MomentCommentsScreen.tsx b/src/screens/profile/MomentCommentsScreen.tsx index fa35a33b..2bceafc9 100644 --- a/src/screens/profile/MomentCommentsScreen.tsx +++ b/src/screens/profile/MomentCommentsScreen.tsx @@ -1,9 +1,12 @@ -import AsyncStorage from '@react-native-community/async-storage'; import {RouteProp, useNavigation} from '@react-navigation/native'; -import * as React from 'react'; -import {useEffect} from 'react'; -import {StyleSheet, Text, TouchableOpacity, View} from 'react-native'; -import Animated from 'react-native-reanimated'; +import React, {useEffect, useRef} from 'react'; +import { + ScrollView, + StyleSheet, + Text, + TouchableOpacity, + View, +} from 'react-native'; import {SafeAreaView} from 'react-native-safe-area-context'; import {useDispatch} from 'react-redux'; import {getMomentComments} from '../..//services'; @@ -11,9 +14,8 @@ import BackIcon from '../../assets/icons/back-arrow.svg'; import {CommentTile, TabsGradient} from '../../components'; import {AddComment} from '../../components/'; import {ProfileStackParams} from '../../routes/main'; -import {logout} from '../../store/actions'; import {CommentType} from '../../types'; -import {SCREEN_WIDTH, SCREEN_HEIGHT} from '../../utils'; +import {SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; /** * Comments Screen for an image uploaded @@ -36,19 +38,20 @@ const MomentCommentsScreen: React.FC<MomentCommentsScreenProps> = ({route}) => { const [commentsList, setCommentsList] = React.useState([]); const [newCommentsAvailable, setNewCommentsAvailable] = React.useState(true); const dispatch = useDispatch(); + const ref = useRef<ScrollView>(null); useEffect(() => { const loadComments = async () => { - const token = await AsyncStorage.getItem('token'); - if (!token) { - dispatch(logout()); - return; - } - getMomentComments(moment_id, setCommentsList, token); + getMomentComments(moment_id, setCommentsList); setNewCommentsAvailable(false); }; if (newCommentsAvailable) { loadComments(); + setTimeout(() => { + ref.current?.scrollToEnd({ + animated: true, + }); + }, 500); } }, [dispatch, moment_id, newCommentsAvailable]); @@ -68,7 +71,8 @@ const MomentCommentsScreen: React.FC<MomentCommentsScreenProps> = ({route}) => { </Text> </View> <View style={styles.body}> - <Animated.ScrollView + <ScrollView + ref={ref} style={styles.scrollView} contentContainerStyle={styles.scrollViewContent}> {commentsList && @@ -79,7 +83,7 @@ const MomentCommentsScreen: React.FC<MomentCommentsScreenProps> = ({route}) => { screenType={screenType} /> ))} - </Animated.ScrollView> + </ScrollView> <AddComment setNewCommentsAvailable={setNewCommentsAvailable} moment_id={moment_id} @@ -117,7 +121,7 @@ const styles = StyleSheet.create({ }, body: { width: SCREEN_WIDTH, - height: (4.9 / 6) * SCREEN_HEIGHT, + height: SCREEN_HEIGHT * 0.8, paddingTop: '3%', }, scrollView: { |
