From 67fcb0b963a9f38451a382803bcfaa5fb001cded Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Thu, 17 Jun 2021 23:04:57 -0700 Subject: Revamp Moment Post View --- src/components/moments/MomentPost.tsx | 352 ++++++++++++++++++++++-- src/components/profile/MomentMoreInfoDrawer.tsx | 7 - src/screens/profile/IndividualMoment.tsx | 55 ++-- 3 files changed, 349 insertions(+), 65 deletions(-) (limited to 'src') diff --git a/src/components/moments/MomentPost.tsx b/src/components/moments/MomentPost.tsx index 60cb16fa..8a3cfacb 100644 --- a/src/components/moments/MomentPost.tsx +++ b/src/components/moments/MomentPost.tsx @@ -1,12 +1,42 @@ -import React, {useEffect, useState} from 'react'; -import {StyleSheet} from 'react-native'; -import {useSelector} from 'react-redux'; -import {MomentPostContent, MomentPostHeader} from '.'; +import {useNavigation} from '@react-navigation/native'; +import React, {useContext, useEffect, useMemo, useRef, useState} from 'react'; +import { + Image, + KeyboardAvoidingView, + Platform, + StatusBar, + StyleSheet, + Text, + TouchableOpacity, + View, +} from 'react-native'; +import Animated, {EasingNode} from 'react-native-reanimated'; +import {useDispatch, useSelector, useStore} from 'react-redux'; +import {headerBarOptions} from '../../routes'; +import {MomentContext} from '../../screens/profile/IndividualMoment'; import {deleteMomentTag, loadMomentTags} from '../../services'; +import {loadUserMoments} from '../../store/actions'; import {RootState} from '../../store/rootReducer'; -import {MomentPostType, MomentTagType, ScreenType} from '../../types'; -import {normalize, SCREEN_HEIGHT} from '../../utils'; - +import { + MomentCommentPreviewType, + MomentPostType, + MomentTagType, + ScreenType, + UserType, +} from '../../types'; +import { + getLoggedInUserAsProfilePreview, + getTimePosted, + HeaderHeight, + navigateToProfile, + normalize, + SCREEN_HEIGHT, + SCREEN_WIDTH, +} from '../../utils'; +import {mentionPartTypes, renderTextWithMentions} from '../../utils/comments'; +import {AddComment} from '../comments'; +import CommentsCount from '../comments/CommentsCount'; +import {MomentMoreInfoDrawer, TaggAvatar} from '../profile'; interface MomentPostProps { moment: MomentPostType; userXId: string | undefined; @@ -24,15 +54,13 @@ const MomentPost: React.FC = ({ (state: RootState) => state.user.user, ); - const { - user: {username}, - } = useSelector((state: RootState) => + const {user} = useSelector((state: RootState) => userXId ? state.userX[screenType][userXId] : state.user, ); const [tags, setTags] = useState([]); const [momentTagId, setMomentTagId] = useState(''); - const isOwnProfile = username === loggedInUsername; + const isOwnProfile = user.username === loggedInUsername; /* * Load tags on initial render to pass tags data to moment header and content @@ -71,18 +99,201 @@ const MomentPost: React.FC = ({ } }; - return ( - <> - (momentTags); + const state: RootState = useStore().getState(); + const navigation = useNavigation(); + const dispatch = useDispatch(); + const imageRef = useRef(null); + const [visible, setVisible] = useState(false); + const [fadeValue, setFadeValue] = useState>( + new Animated.Value(0), + ); + const [commentCount, setCommentCount] = useState( + moment.comments_count, + ); + const [commentPreview, setCommentPreview] = + useState(moment.comment_preview); + const {keyboardVisible, scrollTo} = useContext(MomentContext); + const [hideText, setHideText] = useState(false); + + const [isFullScreen, setIsFullScreen] = useState(false); + const [aspectRatio, setAspectRatio] = useState(1); + + const [drawerVisible, setDrawerVisible] = useState(false); + + useEffect( + () => + navigation.setOptions({ + ...headerBarOptions('white', ''), + headerTitle: () => ( + + + 18 + ? normalize(14) + : normalize(16), + }, + ]}> + {moment.moment_category} + + + + ), + }), + [moment.moment_id], + ); + + useEffect(() => { + Image.getSize( + moment.moment_url, + (w, h) => { + const isFS = Math.abs(w / h - 9 / 16) < 0.01; + setAspectRatio(w / h); + setIsFullScreen(isFS); + }, + (err) => console.log(err), + ); + }, []); + + useEffect(() => { + const fade = async () => { + Animated.timing(fadeValue, { + toValue: 1, + duration: 250, + easing: EasingNode.linear, + }).start(); + }; + fade(); + }, [fadeValue]); + + useEffect(() => { + if (!keyboardVisible && hideText) { + setHideText(false); + } + }, [keyboardVisible, hideText]); + + const tagsIcon = useMemo(() => { + tags.length > 0 && ( + + ); + }, [tags]); + + const MomentUserPreview = () => ( + + navigateToProfile(state, dispatch, navigation, screenType, user) + } + style={styles.header}> + + {user.username} + + ); + + const TagsIcon = () => { + return tags.length === 0 ? ( + + ) : ( + + ); + }; + + const [verticalOffset, setVerticalOffset] = useState(0); + return ( + <> + + + + + + { + dispatch(loadUserMoments(loggedInUserId)); + navigation.goBack(); + }} + screenType={screenType} + moment={moment} + tags={tags} + /> + + + + = ({ }}> + + {!hideText && ( + <> + {moment.caption !== '' && + renderTextWithMentions({ + value: moment.caption, + styles: styles.captionText, + partTypes: mentionPartTypes('white'), + onPress: (user: UserType) => + navigateToProfile( + state, + dispatch, + navigation, + screenType, + user, + ), + })} + + )} + + { + setCommentPreview({ + commenter: getLoggedInUserAsProfilePreview(state), + comment: message, + }); + setCommentCount(commentCount + 1); + }} + onFocus={() => { + setHideText(true); + setVerticalOffset(SCREEN_HEIGHT * 0.05); + }} + isKeyboardAvoiding={false} + theme={'dark'} + /> + + {getTimePosted(moment.date_created)} + + + + + + ); }; @@ -98,9 +354,63 @@ const MomentPost: React.FC = ({ const styles = StyleSheet.create({ postHeader: {}, postContent: { - minHeight: SCREEN_HEIGHT * 0.8, + // minHeight: SCREEN_HEIGHT * 0.8, paddingBottom: normalize(20), }, + image: { + width: SCREEN_WIDTH, + marginBottom: '3%', + zIndex: 0, + position: 'absolute', + }, + text: { + marginHorizontal: '5%', + color: 'white', + fontWeight: '500', + textAlign: 'right', + marginTop: 5, + }, + captionText: { + position: 'relative', + marginHorizontal: '5%', + color: '#ffffff', + fontWeight: '500', + fontSize: normalize(13), + lineHeight: normalize(15.51), + letterSpacing: normalize(0.6), + marginBottom: normalize(5), + width: SCREEN_WIDTH * 0.79, + }, + tapTag: { + position: 'absolute', + backgroundColor: 'red', + width: 100, + height: 100, + }, + tagIcon: { + width: normalize(30), + height: normalize(30), + bottom: normalize(20), + left: '5%', + }, + avatar: { + width: 48, + aspectRatio: 1, + borderRadius: 100, + marginLeft: '3%', + }, + headerText: { + fontSize: 15, + fontWeight: 'bold', + color: 'white', + paddingHorizontal: '3%', + flex: 1, + }, + header: { + alignItems: 'center', + flexDirection: 'row', + marginBottom: normalize(15), + }, }); export default MomentPost; diff --git a/src/components/profile/MomentMoreInfoDrawer.tsx b/src/components/profile/MomentMoreInfoDrawer.tsx index a796ffd8..a8adcfda 100644 --- a/src/components/profile/MomentMoreInfoDrawer.tsx +++ b/src/components/profile/MomentMoreInfoDrawer.tsx @@ -169,7 +169,6 @@ const MomentMoreInfoDrawer: React.FC = (props) => { return ( <> { setIsOpen(true); }}> @@ -184,10 +183,4 @@ const MomentMoreInfoDrawer: React.FC = (props) => { ); }; -const styles = StyleSheet.create({ - icon: { - marginRight: '3%', - }, -}); - export default MomentMoreInfoDrawer; diff --git a/src/screens/profile/IndividualMoment.tsx b/src/screens/profile/IndividualMoment.tsx index f8113aba..4088895a 100644 --- a/src/screens/profile/IndividualMoment.tsx +++ b/src/screens/profile/IndividualMoment.tsx @@ -1,10 +1,9 @@ -import {BlurView} from '@react-native-community/blur'; import {RouteProp} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; import React, {useEffect, useRef, useState} from 'react'; import {FlatList, Keyboard, StyleSheet} from 'react-native'; import {useSelector} from 'react-redux'; -import {IndividualMomentTitleBar, MomentPost} from '../../components'; +import {MomentPost, TabsGradient} from '../../components'; import {AVATAR_DIM} from '../../constants'; import {MainStackParams} from '../../routes'; import {RootState} from '../../store/rootreducer'; @@ -84,41 +83,23 @@ const IndividualMoment: React.FC = ({ keyboardVisible, scrollTo, }}> - - navigation.goBack()} - title={moment_category} - /> - ( - - )} - keyExtractor={(item, _) => item.moment_id} - showsVerticalScrollIndicator={false} - initialScrollIndex={initialIndex} - onScrollToIndexFailed={() => { - // TODO: code below does not work, index resets to 0 - // const wait = new Promise((resolve) => setTimeout(resolve, 500)); - // wait.then(() => { - // console.log('scrolling to ', initialIndex); - // scrollRef.current?.scrollToIndex({index: initialIndex}); - // }); - }} - /> - + ( + + )} + keyExtractor={(item, _) => item.moment_id} + showsVerticalScrollIndicator={false} + initialScrollIndex={initialIndex} + pagingEnabled + /> + ); }; -- cgit v1.2.3-70-g09d2