From f2f6ac7f517cd7dadcf5e634dc46f6c617acbb9c Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 19 Jul 2021 16:53:54 -0400 Subject: Cleanup code, Separate components into parts, Cleanup styles, Use pinchable view --- src/components/moments/MomentPost.tsx | 299 ++++++++++++++++------------------ 1 file changed, 141 insertions(+), 158 deletions(-) (limited to 'src') diff --git a/src/components/moments/MomentPost.tsx b/src/components/moments/MomentPost.tsx index 5dba5e69..843e049f 100644 --- a/src/components/moments/MomentPost.tsx +++ b/src/components/moments/MomentPost.tsx @@ -12,7 +12,10 @@ import { TouchableWithoutFeedback, View, } from 'react-native'; +// @ts-ignore +import Pinchable from 'react-native-pinchable'; import Animated, {EasingNode} from 'react-native-reanimated'; +import {SafeAreaView} from 'react-native-safe-area-context'; import Video from 'react-native-video'; import {useDispatch, useSelector, useStore} from 'react-redux'; import {TaggedUsersDrawer} from '.'; @@ -24,8 +27,6 @@ import {RootState} from '../../store/rootReducer'; import {MomentPostType, MomentTagType, ScreenType, UserType} from '../../types'; import { getTimePosted, - HeaderHeight, - isIPhoneX, navigateToProfile, normalize, SCREEN_HEIGHT, @@ -60,7 +61,7 @@ const MomentPost: React.FC = ({ const isOwnProfile = user.username === loggedInUsername; const [tags, setTags] = useState([]); - const [visible, setVisible] = useState(false); + const [tagsVisible, setTagsVisible] = useState(false); const [drawerVisible, setDrawerVisible] = useState(false); const [taggedUsersVisible, setTaggedUsersVisible] = useState(false); const [hideText, setHideText] = useState(false); @@ -198,6 +199,35 @@ const MomentPost: React.FC = ({ [user.username], ); + const momentMedia = isVideo ? ( + + + ) : ( + + ); + return ( <> @@ -206,157 +236,114 @@ const MomentPost: React.FC = ({ isOpen={taggedUsersVisible} setIsOpen={setTaggedUsersVisible} /> - - - {isVideo ? ( - - - ) : ( - - )} - - {visible && ( - - null} - imageRef={imageRef} - /> - - )} + + { + dispatch(loadUserMoments(loggedInUserId)); + navigation.goBack(); + }} + screenType={screenType} + moment={moment} + tags={tags} + /> + + { - setVisible(!visible); - setFadeValue(new Animated.Value(0)); - Keyboard.dismiss(); + if (keyboardVisible) { + Keyboard.dismiss(); + } else { + setTagsVisible(!tagsVisible); + setFadeValue(new Animated.Value(0)); + } }}> - - - { - dispatch(loadUserMoments(loggedInUserId)); - navigation.goBack(); - }} + + {momentMedia} + {tagsVisible && !isVideo && ( + + null} + imageRef={imageRef} + /> + + )} + + + + + {tags.length > 0 && !keyboardVisible && ( + + setTaggedUsersVisible((prevState) => !prevState) + }> + + + )} + + - - - {tags.length > 0 && ( - - setTaggedUsersVisible((prevState) => !prevState) - }> - - - )} - - - - {momentPosterPreview} - {!hideText && ( - <> - {moment.caption !== '' && - renderTextWithMentions({ - value: moment.caption, - styles: styles.captionText, - partTypes: mentionPartTypes('white', 'caption'), - onPress: (userLocal: UserType) => - navigateToProfile( - state, - dispatch, - navigation, - screenType, - userLocal, - ), - })} - - )} - - { - setCommentCount(commentCount + 1); - }} - onFocus={() => { - setHideText(true); - }} - isKeyboardAvoiding={false} - theme={'dark'} - /> - - {getTimePosted(moment.date_created)} - - - - - - + {momentPosterPreview} + {!hideText && + moment.caption !== '' && + renderTextWithMentions({ + value: moment.caption, + styles: styles.captionText, + partTypes: mentionPartTypes('white', 'caption'), + onPress: (userLocal: UserType) => + navigateToProfile( + state, + dispatch, + navigation, + screenType, + userLocal, + ), + })} + { + setCommentCount(commentCount + 1); + }} + onFocus={() => { + setHideText(true); + }} + isKeyboardAvoiding={false} + theme={'dark'} + /> + + {getTimePosted(moment.date_created)} + + + ); }; const styles = StyleSheet.create({ - media: { - zIndex: 0, - }, - imageContainer: { + mediaContainer: { height: SCREEN_HEIGHT, width: SCREEN_WIDTH, - flexDirection: 'column', justifyContent: 'center', - overflow: 'hidden', }, text: { marginHorizontal: '5%', @@ -376,12 +363,16 @@ const styles = StyleSheet.create({ marginBottom: normalize(5), width: SCREEN_WIDTH * 0.79, }, - tagIcon: { + tagIconContainer: { width: normalize(30), height: normalize(30), bottom: normalize(20), left: '5%', }, + tagIcon: { + width: '100%', + height: '100%', + }, avatar: { width: 48, aspectRatio: 1, @@ -411,37 +402,29 @@ const styles = StyleSheet.create({ right: '2%', bottom: SCREEN_HEIGHT * 0.12, }, - bottomContainer: { - flexDirection: 'column', - justifyContent: 'flex-end', - }, - topContainer: { - paddingTop: isIPhoneX() ? HeaderHeight : '6%', - alignSelf: 'flex-end', - paddingRight: '8%', + moreInfoButton: { + position: 'absolute', + zIndex: 999, + top: 5, + right: 25, }, - contentContainer: { + bottomContainer: { position: 'absolute', width: SCREEN_WIDTH, height: SCREEN_HEIGHT, flexDirection: 'column', - justifyContent: 'space-between', + justifyContent: 'flex-end', paddingBottom: '24%', }, tagsContainer: { position: 'absolute', - top: 0, - bottom: 0, - left: 0, - right: 0, - marginBottom: '3%', + width: SCREEN_WIDTH, + height: SCREEN_HEIGHT, }, - mainContainer: { + background: { backgroundColor: 'black', width: SCREEN_WIDTH, height: SCREEN_HEIGHT, - flexDirection: 'column', - justifyContent: 'center', }, }); -- cgit v1.2.3-70-g09d2